Make the elf parser use the phdrs and the DT_DYNAMIC contents

This commit is contained in:
LemonBoy 2014-11-05 16:32:47 +01:00 committed by pancake
parent 5bdbfd240a
commit f990b078a8

View File

@ -308,11 +308,22 @@ static int Elf_(r_bin_elf_init_strtab)(struct Elf_(r_bin_elf_obj_t) *bin) {
} else {
Elf_(Shdr) *sh = Elf_(r_bin_elf_get_section_by_name) (bin, ".strtab");
if (!sh) {
eprintf ("Warning: strtab section not found\n");
return R_FALSE;
// Try using the DYNAMIC headers to get the strtab section
// but only if the binary has no section headers
dyn_strtab = Elf_(r_bin_elf_seek_dyn_tag) (bin, DT_STRTAB);
dyn_strsz = Elf_(r_bin_elf_seek_dyn_tag) (bin, DT_STRSZ);
if (dyn_strtab && dyn_strsz) {
off = dyn_strtab->d_un.d_val - bin->baddr;
size = dyn_strsz->d_un.d_val;
} else {
eprintf ("Could not find a suitable strtab section\n");
return R_FALSE;
}
} else {
off = sh->sh_offset;
size = sh->sh_size;
}
off = sh->sh_offset;
size = sh->sh_size;
}
bin->strtab_size = size;