mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:38:11 +00:00
LibElf+readelf: Parse ELFs with no program headers correctly
This simply fixes a check which assumed the program header count was always non zero.
This commit is contained in:
parent
ba0df27653
commit
eab151c994
2 changed files with 21 additions and 17 deletions
|
@ -95,7 +95,7 @@ bool validate_elf_header(const Elf32_Ehdr& elf_header, size_t file_size, bool ve
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (elf_header.e_phoff < elf_header.e_ehsize || (elf_header.e_shnum != SHN_UNDEF && elf_header.e_shoff < elf_header.e_ehsize)) {
|
if ((elf_header.e_phnum != 0 && elf_header.e_phoff < elf_header.e_ehsize) || (elf_header.e_shnum != SHN_UNDEF && elf_header.e_shoff < elf_header.e_ehsize)) {
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
dbgln("SHENANIGANS! program header offset ({}) or section header offset ({}) overlap with ELF header!",
|
dbgln("SHENANIGANS! program header offset ({}) or section header offset ({}) overlap with ELF header!",
|
||||||
elf_header.e_phoff, elf_header.e_shoff);
|
elf_header.e_phoff, elf_header.e_shoff);
|
||||||
|
|
|
@ -552,25 +552,29 @@ int main(int argc, char** argv)
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Program Headers:\n");
|
if (!elf_image.program_header_count()) {
|
||||||
printf(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n");
|
printf("There are no program headers in this file.\n");
|
||||||
|
} else {
|
||||||
|
printf("Program Headers:\n");
|
||||||
|
printf(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n");
|
||||||
|
|
||||||
elf_image.for_each_program_header([](const ELF::Image::ProgramHeader& program_header) {
|
elf_image.for_each_program_header([](const ELF::Image::ProgramHeader& program_header) {
|
||||||
printf(" %-14s ", object_program_header_type_to_string(program_header.type()));
|
printf(" %-14s ", object_program_header_type_to_string(program_header.type()));
|
||||||
printf("0x%08x ", program_header.offset());
|
printf("0x%08x ", program_header.offset());
|
||||||
printf("%p ", program_header.vaddr().as_ptr());
|
printf("%p ", program_header.vaddr().as_ptr());
|
||||||
printf("%p ", program_header.vaddr().as_ptr()); // FIXME: assumes PhysAddr = VirtAddr
|
printf("%p ", program_header.vaddr().as_ptr()); // FIXME: assumes PhysAddr = VirtAddr
|
||||||
printf("0x%08x ", program_header.size_in_image());
|
printf("0x%08x ", program_header.size_in_image());
|
||||||
printf("0x%08x ", program_header.size_in_memory());
|
printf("0x%08x ", program_header.size_in_memory());
|
||||||
printf("%04x ", program_header.flags());
|
printf("%04x ", program_header.flags());
|
||||||
printf("0x%08x", program_header.alignment());
|
printf("0x%08x", program_header.alignment());
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
if (program_header.type() == PT_INTERP)
|
if (program_header.type() == PT_INTERP)
|
||||||
printf(" [Interpreter: %s]\n", program_header.raw_data());
|
printf(" [Interpreter: %s]\n", program_header.raw_data());
|
||||||
|
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Display section to segment mapping
|
// TODO: Display section to segment mapping
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue