Added some more header checks.

committer: mfx <mfx> 978531825 +0000
This commit is contained in:
Markus F.X.J. Oberhumer 2001-01-03 14:23:45 +00:00
parent 572082ac2b
commit 597143df7f
2 changed files with 25 additions and 8 deletions

View File

@ -156,9 +156,6 @@ bool PackLinuxI386elf::canPack()
exetype = 0;
// FIXME: add special checks for uncompresed "vmlinux" kernel
// FIXME: add checks for FreeBSD/... ELF executables
fi->readx(buf, sizeof(buf));
fi->seek(0, SEEK_SET);
Elf_LE32_Ehdr const *const ehdr = (Elf_LE32_Ehdr const *)buf;
@ -183,11 +180,21 @@ bool PackLinuxI386elf::canPack()
if (j >= 14)
return false;
if (phdr->PT_LOAD == phdr->p_type) {
if (phdr->p_offset != 0)
{
if (phdr->p_offset != 0) {
throwCantPack("invalid Phdr p_offset; try `--force-execve'");
return false;
}
#if 1
// FIXME: what about these checks ?
if (phdr->p_vaddr != 0x08048000) {
throwCantPack("invalid Phdr p_vaddr; try `--force-execve'");
return false;
}
if (phdr->p_paddr != 0x08048000) {
throwCantPack("invalid Phdr p_paddr; try `--force-execve'");
return false;
}
#endif
exetype = 1;
break;
}

View File

@ -100,7 +100,6 @@ int PackLinuxI386::checkEhdr(const Elf_LE32_Ehdr *ehdr) const
{
const unsigned char * const buf = ehdr->e_ident;
// info: ELF executables are now handled by p_lx_elf.cpp
if (memcmp(buf, "\x7f\x45\x4c\x46\x01\x01\x01", 7)) // ELF 32-bit LSB
return -1;
@ -109,14 +108,25 @@ int PackLinuxI386::checkEhdr(const Elf_LE32_Ehdr *ehdr) const
return 1;
if (ehdr->e_type != 2) // executable
return 2;
if (ehdr->e_machine != 3 && ehdr->e_machine != 6) // Intel 80[34]86
if (ehdr->e_machine != 3) // Intel 80386
return 3;
if (ehdr->e_version != 1) // version
return 4;
if (ehdr->e_phnum < 1)
return 5;
if (ehdr->e_phentsize != sizeof(Elf_LE32_Phdr))
return 6;
// check for Linux kernels
if (ehdr->e_entry == 0xC0100000) // uncompressed vmlinux
return 1000;
if (ehdr->e_entry == 0x00001000) // compressed vmlinux
return 1001;
if (ehdr->e_entry == 0x00100000) // compressed bvmlinux
return 1002;
// FIXME: add more checks for kernels
// FIXME: add special checks for uncompresed "vmlinux" kernel
// FIXME: add special checks for other ELF i386 formats, like
// NetBSD, OpenBSD, Solaris, ....