diff options
Diffstat (limited to 'src/format/elf')
-rw-r--r-- | src/format/elf/strings.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/format/elf/strings.c b/src/format/elf/strings.c index 049f6d4..3178d69 100644 --- a/src/format/elf/strings.c +++ b/src/format/elf/strings.c @@ -59,6 +59,8 @@ bool find_all_elf_strings(elf_format *format) Elf_Shdr *sections; /* Groupe de sections trouvées */ size_t count; /* Quantité de données */ size_t i; /* Boucle de parcours */ + off_t offset; /* Position physique */ + Elf_Phdr phdr; /* En-tête de programme ELF */ /* Données en lecture seule */ @@ -89,6 +91,23 @@ bool find_all_elf_strings(elf_format *format) parse_elf_string_data(format, str_start, str_size, str_vaddr); } + /* En désespoir de cause, on se rabbat sur les parties de programme directement */ + + if (format->str_count == 0 && format->header.e_shnum == 0 /* FIXME : cond. à garder ? */) + for (i = 0; i < format->header.e_phnum; i++) + { + offset = format->header.e_phoff + format->header.e_phentsize * i; + if ((offset + format->header.e_phentsize) >= EXE_FORMAT(format)->length) continue; + + memcpy(&phdr, &EXE_FORMAT(format)->content[offset], format->header.e_phentsize); + + if (ELF_PHDR(format, &phdr, p_flags) & PF_R && !(ELF_PHDR(format, &phdr, p_flags) & PF_X)) + parse_elf_string_data(format, ELF_PHDR(format, &phdr, p_offset), + ELF_PHDR(format, &phdr, p_filesz), + ELF_PHDR(format, &phdr, p_vaddr)); + + } + return true; } @@ -121,11 +140,11 @@ bool parse_elf_string_data(elf_format *format, const off_t start, const off_t si { for (end = i + 1; end < (start + size); end++) if (!isprint(EXE_FORMAT(format)->content[end])) break; - + format->strings = (elf_string *)realloc(format->strings, ++format->str_count * sizeof(elf_string)); - format->strings[format->str_count - 1].value = (const char *)&EXE_FORMAT(format)->content[i]; - format->strings[format->str_count - 1].len = end - start; + format->strings[format->str_count - 1].value = strndup((const char *)&EXE_FORMAT(format)->content[i], end - i); + format->strings[format->str_count - 1].len = end - i; format->strings[format->str_count - 1].vaddress = vaddress + i - start; i = end; |