diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index 1fcbea23..d47bcea3 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -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; } diff --git a/src/p_lx_exc.cpp b/src/p_lx_exc.cpp index ed4962b7..6d5a63e7 100644 --- a/src/p_lx_exc.cpp +++ b/src/p_lx_exc.cpp @@ -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, ....