diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2018-01-13 22:37:31 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2018-01-13 22:37:31 (GMT) |
commit | 23b9c6e68bbe5f0531f9a9408c2deb9f897701dc (patch) | |
tree | 3804d6c21c9cd5e291cb8c7853607cdda992d125 /src/analysis/disass/output.c | |
parent | a6975c1d754a1ba5bfb9e23f0b26692c746e6f9c (diff) |
Created a real iterator for symbols.
Diffstat (limited to 'src/analysis/disass/output.c')
-rw-r--r-- | src/analysis/disass/output.c | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/src/analysis/disass/output.c b/src/analysis/disass/output.c index 3cc282a..19c7de9 100644 --- a/src/analysis/disass/output.c +++ b/src/analysis/disass/output.c @@ -32,6 +32,7 @@ #include "../../core/logs.h" #include "../../format/format.h" +#include "../../format/symiter.h" #include "../../glibext/generators/rborder.h" @@ -60,9 +61,8 @@ void print_disassembled_instructions(GBufferCache *cache, GCodingLanguage *lang, GBinPortion **portions; /* Morceaux d'encadrement */ size_t portions_count; /* Taille de cette liste */ size_t portion_index; /* Prochaine portion à traiter */ - GBinSymbol **symbols; /* Symboles à représenter */ - size_t sym_count; /* Qté de symboles présents */ - size_t sym_index; /* Prochain symbole non traité */ + sym_iter_t *siter; /* Parcours des symboles */ + GBinSymbol *symbol; /* Symbole manipulé */ MemoryDataSize msize; /* Taille du bus d'adresses */ const GBinContent *content; /* Contenu binaire global */ size_t count; /* Nombre total d'instructions */ @@ -127,8 +127,9 @@ void print_disassembled_instructions(GBufferCache *cache, GCodingLanguage *lang, g_object_unref(G_OBJECT(root)); - symbols = g_binary_format_get_symbols(G_BIN_FORMAT(format), &sym_count); - sym_index = 0; + siter = create_symbol_iterator(G_BIN_FORMAT(format), 0); + + symbol = get_symbol_iterator_current(siter); msize = g_arch_processor_get_memory_size(proc); @@ -205,21 +206,24 @@ void print_disassembled_instructions(GBufferCache *cache, GCodingLanguage *lang, /* Début d'un nouveau symbole ? */ - if (sym_index == sym_count) + if (symbol == NULL) compared = -1; else { iaddr = get_mrange_addr(g_arch_instruction_get_range(instr)); - for ( ; sym_index < sym_count; sym_index++) + for ( ; symbol != NULL; symbol = get_symbol_iterator_next(siter)) { - sym_status = g_binary_symbol_get_status(symbols[sym_index]); + sym_status = g_binary_symbol_get_status(symbol); if (sym_status == SSS_IMPORTED) + { + g_object_unref(G_OBJECT(symbol)); continue; + } - saddr = get_mrange_addr(g_binary_symbol_get_range(symbols[sym_index])); + saddr = get_mrange_addr(g_binary_symbol_get_range(symbol)); compared = cmp_vmpa(iaddr, saddr); @@ -228,10 +232,10 @@ void print_disassembled_instructions(GBufferCache *cache, GCodingLanguage *lang, log_variadic_message(LMT_BAD_BINARY, _("Unable to find a proper location for symbol '%s' @ 0x%08x"), - g_binary_symbol_get_label(symbols[sym_index]), get_phy_addr(saddr)); + g_binary_symbol_get_label(symbol), get_phy_addr(saddr)); asprintf(&errmsg, _("Unable to find a proper location for symbol '%s'"), - g_binary_symbol_get_label(symbols[sym_index])); + g_binary_symbol_get_label(symbol)); g_arch_processor_add_error(proc, APE_LABEL, saddr, errmsg); @@ -239,22 +243,24 @@ void print_disassembled_instructions(GBufferCache *cache, GCodingLanguage *lang, _missing++; + g_object_unref(G_OBJECT(symbol)); + } - if (sym_index == sym_count) + if (symbol == NULL) goto no_more_symbol_finally; if (compared == 0) { /* Coupure pour une nouvelle routine */ - stype = g_binary_symbol_get_target_type(symbols[sym_index]); + stype = g_binary_symbol_get_target_type(symbol); if (stype == STP_ROUTINE || stype == STP_ENTRY_POINT) { /* Impression de la marque de début */ - copy_vmpa(&intro_addr, get_mrange_addr(g_binary_symbol_get_range(symbols[sym_index]))); + copy_vmpa(&intro_addr, get_mrange_addr(g_binary_symbol_get_range(symbol))); border = g_border_generator_new(lang, &intro_addr, true, msize); g_buffer_cache_append(cache, G_LINE_GENERATOR(border), BLF_NONE); @@ -273,7 +279,7 @@ void print_disassembled_instructions(GBufferCache *cache, GCodingLanguage *lang, * est nécessaire pour imprimer cette marque de clôture. */ - compute_mrange_end_addr(g_binary_symbol_get_range(symbols[sym_index]), &outro_addr); + compute_mrange_end_addr(g_binary_symbol_get_range(symbol), &outro_addr); expect_outro = true; @@ -281,7 +287,7 @@ void print_disassembled_instructions(GBufferCache *cache, GCodingLanguage *lang, /* Etiquette ? */ - generator = g_binary_symbol_produce_label(symbols[sym_index]); + generator = g_binary_symbol_produce_label(symbol); if (generator != NULL) g_buffer_cache_append(cache, generator, BLF_NONE); @@ -298,7 +304,7 @@ void print_disassembled_instructions(GBufferCache *cache, GCodingLanguage *lang, { /* Point d'entrée ? */ - if (g_binary_symbol_get_target_type(symbols[sym_index]) == STP_ENTRY_POINT) + if (g_binary_symbol_get_target_type(symbol) == STP_ENTRY_POINT) flags |= BLF_ENTRYPOINT; /** @@ -311,7 +317,8 @@ void print_disassembled_instructions(GBufferCache *cache, GCodingLanguage *lang, flags |= BLF_WIDTH_MANAGER; - sym_index++; + g_object_unref(G_OBJECT(symbol)); + symbol = get_symbol_iterator_next(siter); } @@ -369,6 +376,11 @@ void print_disassembled_instructions(GBufferCache *cache, GCodingLanguage *lang, g_object_unref(G_OBJECT(content)); + if (symbol != NULL) + g_object_unref(G_OBJECT(symbol)); + + delete_symbol_iterator(siter); + if (portions != NULL) free(portions); |