From f990b078a8fa3406f159f036bf7a47285ba71240 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Wed, 5 Nov 2014 16:32:47 +0100 Subject: [PATCH] Make the elf parser use the phdrs and the DT_DYNAMIC contents --- libr/bin/format/elf/elf.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/libr/bin/format/elf/elf.c b/libr/bin/format/elf/elf.c index c92b450bd9..818fa35430 100644 --- a/libr/bin/format/elf/elf.c +++ b/libr/bin/format/elf/elf.c @@ -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;