From c9449c389834c580196527c4e1cb010a701e7a32 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Wed, 14 Oct 2015 19:33:06 +0000 Subject: Discarded code symbols as symbols already containing instructions when disassembling. git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@595 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a --- ChangeLog | 12 ++++++++++ src/analysis/disass/area.c | 56 +++++++++++++++++++++++++--------------------- src/analysis/project.c | 4 +++- src/format/symbol.c | 4 ++++ 4 files changed, 49 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7eabc65..7964745 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 15-10-14 Cyrille Bagard + * src/analysis/disass/area.c: + Discard code symbols as symbols already containing instructions when + disassembling. + + * src/analysis/project.c: + Search for more main entry points to display. + + * src/format/symbol.c: + Extend the TODO list. + +15-10-14 Cyrille Bagard + * src/analysis/disass/links.c: Reorganize the code. diff --git a/src/analysis/disass/area.c b/src/analysis/disass/area.c index 3338b03..b45e7fc 100644 --- a/src/analysis/disass/area.c +++ b/src/analysis/disass/area.c @@ -994,6 +994,7 @@ mem_area *compute_memory_areas(GExeFormat *format, phys_t bin_length, size_t *co const vmpa2t *portion_start; /* Point de départ de portion */ size_t j; /* Boucle de parcours #2 */ + SymbolType type; /* Nature d'un symbole */ const mrange_t *range; /* Couverture d'un symbole */ const vmpa2t *start; /* Point de départ du symbole */ phys_t length; /* Taille de ce même symbole */ @@ -1175,32 +1176,45 @@ mem_area *compute_memory_areas(GExeFormat *format, phys_t bin_length, size_t *co } - //exit(0); - /* Troisième étape : on insère les symboles existants */ j = 0; -#define SKIP_EMPTY_SYMBOLS \ - for (; j < sym_count; j++) \ - { \ - range = g_binary_symbol_get_range(symbols[j]); \ - \ - length = get_mrange_length(range); \ - if (length > 0) break; \ - \ - } \ + for (i = 0; i < *count; i++) + { + /* Sélection et écartement des symboles */ - SKIP_EMPTY_SYMBOLS + for (; j < sym_count; j++) + { + type = g_binary_symbol_get_target_type(symbols[j]); - for (i = 0; i < *count && j < sym_count; i++) - { - range = g_binary_symbol_get_range(symbols[j]); + /** + * On ne garde que les symboles renvoyant directement une ou + * plusieurs instructions, c'est à dire les symboles valides + * pour un appel à g_binary_symbol_get_instruction(). + * + * Les instructions des autres symboles sont obtenues et mises + * en place durant la procédure de désassemblage. + */ + + if (type == STP_ROUTINE || type == STP_ENTRY_POINT || type == STP_CODE_LABEL) + continue; + + range = g_binary_symbol_get_range(symbols[j]); + + length = get_mrange_length(range); + + if (length > 0) + break; + + } + + if (j == sym_count) + break; start = get_mrange_addr(range); - length = get_mrange_length(range); /* Si un découpage s'impose... */ @@ -1286,25 +1300,15 @@ mem_area *compute_memory_areas(GExeFormat *format, phys_t bin_length, size_t *co } - - - - j++; - SKIP_EMPTY_SYMBOLS - } } - - if (exe_ranges != NULL) free(exe_ranges); - //exit(0); - return result; } diff --git a/src/analysis/project.c b/src/analysis/project.c index 902b5a8..8fef602 100644 --- a/src/analysis/project.c +++ b/src/analysis/project.c @@ -566,7 +566,9 @@ void g_study_project_add_loaded_binary(GLoadedBinary *binary, GStudyProject *pro format = G_BIN_FORMAT(g_loaded_binary_get_format(binary)); - if (g_binary_format_find_symbol_by_label(format, "entry_point", &symbol)) + if (g_binary_format_find_symbol_by_label(format, "main", &symbol) + || g_binary_format_find_symbol_by_label(format, "_start", &symbol) + || g_binary_format_find_symbol_by_label(format, "entry_point", &symbol)) { range = g_binary_symbol_get_range(symbol); diff --git a/src/format/symbol.c b/src/format/symbol.c index 2346c63..58fdfb3 100644 --- a/src/format/symbol.c +++ b/src/format/symbol.c @@ -494,6 +494,8 @@ void g_binary_symbol_attach_instruction(GBinSymbol *symbol, GArchInstruction *in GBinRoutine *g_binary_symbol_get_routine(const GBinSymbol *symbol) { + /* TODO : rajouter des assert() sur le type de symbole */ + return symbol->extra.routine; } @@ -513,6 +515,8 @@ GBinRoutine *g_binary_symbol_get_routine(const GBinSymbol *symbol) GArchInstruction *g_binary_symbol_get_instruction(const GBinSymbol *symbol) { + /* TODO : rajouter des assert() sur le type de symbole */ + return symbol->extra.instr; } -- cgit v0.11.2-87-g4458