diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2009-04-12 19:15:35 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2009-04-12 19:15:35 (GMT) |
commit | 216a3d0121fabd678e50ea6b4fa2447ae9b921f0 (patch) | |
tree | 395fcd91b674ff5652e34b46207ba08cc9e7af68 /src/format/elf | |
parent | edac614a164d9cac345d914f4320d71bdb16ab79 (diff) |
Created a debugging layout and introduced a heavier use of GLib.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@58 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
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; |