Added some more header checks.
committer: mfx <mfx> 978531825 +0000
This commit is contained in:
+12
-5
@@ -156,9 +156,6 @@ bool PackLinuxI386elf::canPack()
|
|||||||
|
|
||||||
exetype = 0;
|
exetype = 0;
|
||||||
|
|
||||||
// FIXME: add special checks for uncompresed "vmlinux" kernel
|
|
||||||
// FIXME: add checks for FreeBSD/... ELF executables
|
|
||||||
|
|
||||||
fi->readx(buf, sizeof(buf));
|
fi->readx(buf, sizeof(buf));
|
||||||
fi->seek(0, SEEK_SET);
|
fi->seek(0, SEEK_SET);
|
||||||
Elf_LE32_Ehdr const *const ehdr = (Elf_LE32_Ehdr const *)buf;
|
Elf_LE32_Ehdr const *const ehdr = (Elf_LE32_Ehdr const *)buf;
|
||||||
@@ -183,11 +180,21 @@ bool PackLinuxI386elf::canPack()
|
|||||||
if (j >= 14)
|
if (j >= 14)
|
||||||
return false;
|
return false;
|
||||||
if (phdr->PT_LOAD == phdr->p_type) {
|
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'");
|
throwCantPack("invalid Phdr p_offset; try `--force-execve'");
|
||||||
return false;
|
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;
|
exetype = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-3
@@ -100,7 +100,6 @@ int PackLinuxI386::checkEhdr(const Elf_LE32_Ehdr *ehdr) const
|
|||||||
{
|
{
|
||||||
const unsigned char * const buf = ehdr->e_ident;
|
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
|
if (memcmp(buf, "\x7f\x45\x4c\x46\x01\x01\x01", 7)) // ELF 32-bit LSB
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@@ -109,14 +108,25 @@ int PackLinuxI386::checkEhdr(const Elf_LE32_Ehdr *ehdr) const
|
|||||||
return 1;
|
return 1;
|
||||||
if (ehdr->e_type != 2) // executable
|
if (ehdr->e_type != 2) // executable
|
||||||
return 2;
|
return 2;
|
||||||
if (ehdr->e_machine != 3 && ehdr->e_machine != 6) // Intel 80[34]86
|
if (ehdr->e_machine != 3) // Intel 80386
|
||||||
return 3;
|
return 3;
|
||||||
if (ehdr->e_version != 1) // version
|
if (ehdr->e_version != 1) // version
|
||||||
return 4;
|
return 4;
|
||||||
if (ehdr->e_phnum < 1)
|
if (ehdr->e_phnum < 1)
|
||||||
return 5;
|
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
|
// FIXME: add special checks for other ELF i386 formats, like
|
||||||
// NetBSD, OpenBSD, Solaris, ....
|
// NetBSD, OpenBSD, Solaris, ....
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user