diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2014-12-14 23:32:23 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2014-12-14 23:32:23 (GMT) |
commit | a1c2bc0c3b6f4b4fda9c50beeb09a1f699419e2a (patch) | |
tree | 7856d9bc8fd702d0499f8a09156a555406eaaea9 /src/format/elf/symbols.c | |
parent | 16d37d997b84c75c1f9b877fe446b3b3e5ce2495 (diff) |
Shown label of loaded symbols when possible.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@441 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/format/elf/symbols.c')
-rw-r--r-- | src/format/elf/symbols.c | 128 |
1 files changed, 111 insertions, 17 deletions
diff --git a/src/format/elf/symbols.c b/src/format/elf/symbols.c index 15c3a6b..30bdcca 100644 --- a/src/format/elf/symbols.c +++ b/src/format/elf/symbols.c @@ -32,6 +32,7 @@ #include "elf-int.h" +#include "helper_arm.h" #include "helper_x86.h" #include "section.h" #include "../mangling/demangler.h" @@ -46,6 +47,10 @@ + +/* Récupère la définition complète d'un symbole donné. */ +bool get_elf_symbol_by_index(GElfFormat *, const elf_shdr *, off_t, elf_sym *); + /* Récupère la désignation d'un symbole donné. */ const char *get_elf_symbol_name(GElfFormat *, const elf_shdr *, const elf_shdr *, off_t); @@ -92,7 +97,7 @@ static bool load_elf_external_symbols(GElfFormat *, const elf_shdr *); - +#include <stdlib.h> /****************************************************************************** * * @@ -109,29 +114,57 @@ static bool load_elf_external_symbols(GElfFormat *, const elf_shdr *); bool load_elf_symbols(GElfFormat *format) { bool result; /* Bilan à retourner */ + + virt_t entry_point; + vmpa2t addr; /* Localisation d'une routine */ + mrange_t range; /* Couverture mémoire associée */ + GBinRoutine *routine; /* Nouvelle routine trouvée */ + GBinSymbol *symbol; /* Nouveau symbole construit */ + elf_shdr *sections; /* Groupe de sections trouvées */ size_t count; /* Quantité de données */ result = true; - +#if 1 annotate_elf_header(format); annotate_elf_program_header_table(format); annotate_elf_section_header_table(format); - +#endif /* Symboles internes */ +#if 0 result = load_elf_internal_symbols(format); +#endif + entry_point = ELF_HDR(format, format->header, e_entry); + printf("E_ENTRY : 0x%08lx\n", (unsigned long)entry_point); - /* Symboles externes */ + if (ELF_HDR(format, format->header, e_machine) == EM_ARM) + entry_point &= ~0x1; + + + init_vmpa(&addr, VMPA_NO_PHYSICAL, entry_point); + + init_mrange(&range, &addr, 0); + + routine = try_to_demangle_routine("entry_point"); + + g_binary_routine_set_range(routine, &range); + + symbol = g_binary_symbol_new(STP_ROUTINE, "entry_point", ~0); + g_binary_symbol_attach_routine(symbol, routine); + g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol); + + /* Symboles externes */ +#if 1 if (find_elf_sections_by_type(format, SHT_DYNAMIC, §ions, &count)) { log_variadic_message(LMT_INFO, _("Binary is dynamically linked")); @@ -142,10 +175,41 @@ bool load_elf_symbols(GElfFormat *format) } else log_variadic_message(LMT_INFO, _("Binary is statically linked")); - +#endif /* Symboles internes */ //result &= load_elf_internal_symbols(format); + + + qsort(G_BIN_FORMAT(format)->symbols, G_BIN_FORMAT(format)->symbols_count, + sizeof(GBinSymbol *), (__compar_fn_t)g_binary_symbol_cmp); + +#if 0 + + const vmpa2t *saddr; /* Adresse de symbole */ + size_t i; /* Boucle de parcours #2 */ + GBinSymbol **symbols; /* Symboles à représenter */ + + symbols = G_BIN_FORMAT(format)->symbols; + + for (i = 0; i < G_BIN_FORMAT(format)->symbols_count; i++) + { + saddr = get_mrange_addr(g_binary_symbol_get_range(symbols[i])); + if (saddr == NULL) continue; + + //if (g_binary_symbol_to_string(symbols[i]) == NULL) continue; + + printf(" <symbol % 2zu> '% 22s'-> 0x%08lx 0x%08lx\n", + i, + g_binary_symbol_to_string(symbols[i]), + saddr->physical, + saddr->virtual); + + } + + //exit(0); +#endif + return result; } @@ -155,36 +219,56 @@ bool load_elf_symbols(GElfFormat *format) * * * Paramètres : format = description de l'exécutable à consulter. * * sym = section comprenant les symboles à venir lire. * -* str = section de chaînes de caractères pour les noms. * * index = indice de l'entrée à venir lire. * +* symbol = ensemble d'informations lues. [OUT] * * * -* Description : Récupère la désignation d'un symbole donné. * +* Description : Récupère la définition complète d'un symbole donné. * * * -* Retour : Nom du symbole trouvé, ou NULL si erreur ou non adapté. * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -const char *get_elf_symbol_name(GElfFormat *format, const elf_shdr *sym, const elf_shdr *str, off_t index) +bool get_elf_symbol_by_index(GElfFormat *format, const elf_shdr *sym, off_t index, elf_sym *symbol) { - const char *result; /* Résultat à retourner */ off_t sym_start; /* Début de section */ off_t sym_size; /* Taille de section */ - off_t str_start; /* Début de section */ - off_t str_size; /* Taille de section */ off_t offset; /* Emplacement à venir lire */ - elf_sym symbol; /* Symbole aux infos visées */ - - result = NULL; get_elf_section_content(format, sym, &sym_start, &sym_size, NULL); - get_elf_section_content(format, str, &str_start, &str_size, NULL); offset = sym_start + index * ELF_SIZEOF_SYM(format); if ((offset + ELF_SIZEOF_SYM(format)) > (sym_start + sym_size)) return NULL; - if (read_elf_symbol(format, &offset, &symbol)) + return read_elf_symbol(format, &offset, symbol); + +} + + +/****************************************************************************** +* * +* Paramètres : format = description de l'exécutable à consulter. * +* sym = section comprenant les symboles à venir lire. * +* str = section de chaînes de caractères pour les noms. * +* index = indice de l'entrée à venir lire. * +* * +* Description : Récupère la désignation d'un symbole donné. * +* * +* Retour : Nom du symbole trouvé, ou NULL si erreur ou non adapté. * +* * +* Remarques : - * +* * +******************************************************************************/ + +const char *get_elf_symbol_name(GElfFormat *format, const elf_shdr *sym, const elf_shdr *str, off_t index) +{ + const char *result; /* Résultat à retourner */ + elf_sym symbol; /* Symbole aux infos visées */ + + result = NULL; + + if (get_elf_symbol_by_index(format, sym, index, &symbol)) result = extract_name_from_elf_string_section(format, str, ELF_SYM(format, symbol, st_name)); return result; @@ -1374,6 +1458,8 @@ static bool load_elf_internal_symbols(GElfFormat *format) /* Routine */ + printf("ADDING>> '%s'\n", name); + routine = try_to_demangle_routine(name); g_binary_routine_set_range(routine, &range); @@ -1537,6 +1623,10 @@ static bool load_elf_external_symbols(GElfFormat *format, const elf_shdr *sectio if (result) switch (g_exe_format_get_target_machine(G_EXE_FORMAT(format))) { + case FTM_ARM: + result = load_elf_arm_relocated_symbols(format, &relxxx, &dynsym, &dynstr); + break; + case FTM_386: result = load_elf_x86_relocated_symbols(format, &relxxx, &dynsym, &dynstr); break; @@ -1548,6 +1638,8 @@ static bool load_elf_external_symbols(GElfFormat *format, const elf_shdr *sectio } +#if 0 + /* Entrées équivalentes dans le binaire */ if (find_elf_dynamic_item(format, section, DT_SYMTAB, &item)) { @@ -1591,6 +1683,8 @@ static bool load_elf_external_symbols(GElfFormat *format, const elf_shdr *sectio } +#endif + return result; } |