diff options
Diffstat (limited to 'src/analysis/binary.c')
-rw-r--r-- | src/analysis/binary.c | 98 |
1 files changed, 97 insertions, 1 deletions
diff --git a/src/analysis/binary.c b/src/analysis/binary.c index 61d344e..6b5697a 100644 --- a/src/analysis/binary.c +++ b/src/analysis/binary.c @@ -87,6 +87,9 @@ GRenderingLine *build_binary_prologue(const char *, const uint8_t *, off_t); /* Procède au désassemblage basique d'un contenu binaire. */ void disassemble_openida_binary(openida_binary *); +/* Etablit les liens entres les différentes lignes de code. */ +void establish_links_in_openida_binary(const openida_binary *); + /****************************************************************************** @@ -665,7 +668,7 @@ void disassemble_openida_binary(openida_binary *binary) } - + establish_links_in_openida_binary(binary); line = g_rendering_line_find_by_address(binary->lines, NULL, get_exe_entry_point(binary->format)); if (line != NULL) g_rendering_line_add_flag(line, RLF_ENTRY_POINT); @@ -674,3 +677,96 @@ void disassemble_openida_binary(openida_binary *binary) } + + +/****************************************************************************** +* * +* Paramètres : binary = binaire dont le contenu est à lier. * +* * +* Description : Etablit les liens entres les différentes lignes de code. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void establish_links_in_openida_binary(const openida_binary *binary) +{ + GBinRoutine **routines; /* Liste des routines trouvées */ + size_t routines_count; /* Nombre de ces routines */ + size_t i; /* Boucle de parcours */ + vmpa_t start; /* Adresse de départ */ + vmpa_t end; /* Adresse de fin */ + GRenderingLine *iter; /* Boucle de parcours */ + GArchInstruction *instr; /* Instruction à ausculter */ + vmpa_t addr; /* Adresse référencée */ + InstructionLinkType type; /* Type de référence */ + GRenderingLine *target; /* Ligne visée par la référence*/ + + routines = get_all_exe_routines(binary->format, &routines_count); + + for (i = 0; i < routines_count; i++) + { + start = g_binary_routine_get_address(routines[i]); + end = start + g_binary_routine_get_size(routines[i]); + + for (iter = g_rendering_line_find_by_address(binary->lines, NULL, start); + iter != NULL; + iter = g_rendering_line_get_next_iter(binary->lines, iter, NULL)) + { + /* Si on sort de la zone... */ + if (get_rendering_line_address(iter) >= end) break; + + /* On ne traite que du code ici ! */ + if (!G_IS_CODE_LINE(iter)) continue; + + instr = g_code_line_get_instruction(G_CODE_LINE(iter)); + type = g_arch_instruction_get_link(instr, &addr); + + switch (type) + { + case ILT_NONE: + break; + + case ILT_JUMP: + + target = g_rendering_line_find_by_address(binary->lines, NULL, addr); + + if (target != NULL) + g_rendering_line_link_with(iter, target, type); + + break; + + case ILT_JUMP_IF_TRUE: + + target = g_rendering_line_find_by_address(binary->lines, NULL, addr); + + if (target != NULL) + { + g_rendering_line_link_with(iter, target, type); + + target = g_rendering_line_get_next_iter(binary->lines, iter, NULL); + if (target != NULL) + g_rendering_line_link_with(iter, target, ILT_JUMP_IF_FALSE); + + } + + break; + + case ILT_CALL: + + target = g_rendering_line_find_by_address(binary->lines, NULL, addr); + + if (target != NULL) + g_rendering_line_link_with(iter, target, type); + + break; + + } + + } + + } + +} |