1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:04:59 +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:
Idan Horowitz 2021-03-29 15:14:41 +03:00 committed by Andreas Kling
parent ba0df27653
commit eab151c994
2 changed files with 21 additions and 17 deletions

View file

@ -552,25 +552,29 @@ int main(int argc, char** argv)
printf("\n");
}
printf("Program Headers:\n");
printf(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n");
if (!elf_image.program_header_count()) {
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) {
printf(" %-14s ", object_program_header_type_to_string(program_header.type()));
printf("0x%08x ", program_header.offset());
printf("%p ", program_header.vaddr().as_ptr());
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_memory());
printf("%04x ", program_header.flags());
printf("0x%08x", program_header.alignment());
printf("\n");
elf_image.for_each_program_header([](const ELF::Image::ProgramHeader& program_header) {
printf(" %-14s ", object_program_header_type_to_string(program_header.type()));
printf("0x%08x ", program_header.offset());
printf("%p ", program_header.vaddr().as_ptr());
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_memory());
printf("%04x ", program_header.flags());
printf("0x%08x", program_header.alignment());
printf("\n");
if (program_header.type() == PT_INTERP)
printf(" [Interpreter: %s]\n", program_header.raw_data());
if (program_header.type() == PT_INTERP)
printf(" [Interpreter: %s]\n", program_header.raw_data());
return IterationDecision::Continue;
});
return IterationDecision::Continue;
});
}
// TODO: Display section to segment mapping
printf("\n");