diff options
Diffstat (limited to 'src/analysis/decomp')
-rw-r--r-- | src/analysis/decomp/decompiler.c | 2 | ||||
-rw-r--r-- | src/analysis/decomp/il.c | 86 |
2 files changed, 60 insertions, 28 deletions
diff --git a/src/analysis/decomp/decompiler.c b/src/analysis/decomp/decompiler.c index 71a9286..a61e7c7 100644 --- a/src/analysis/decomp/decompiler.c +++ b/src/analysis/decomp/decompiler.c @@ -169,7 +169,7 @@ static void prepare_all_routines_for_decomp(const GLoadedBinary *binary, const c max = g_binary_routine_get_address(routines[i]) + g_binary_routine_get_size(routines[i]); */ - printf("##### DECOMPILE '%s' #####\n", g_binary_routine_to_string(routines[i])); + //printf("\n##### DECOMPILE '%s' #####\n", g_binary_routine_to_string(routines[i])); dinstrs = decompiled_routine_instructions(routines[i], format, proc); diff --git a/src/analysis/decomp/il.c b/src/analysis/decomp/il.c index 642c921..64f6398 100644 --- a/src/analysis/decomp/il.c +++ b/src/analysis/decomp/il.c @@ -40,8 +40,11 @@ static bool track_used_registers(GFlowBlock *, BlockFollowPosition, GRAccessList /* Etablit le relévé des allocations de registre. */ static void setup_awaited_regs_allocation(const GInstrBlock *, vmpa_t); +/* Etablit la liste de tous les allocations attendues. */ +static bool merge_all_awaited_regs(GInstrBlock *, BlockVisitOrder, GRAccessList *); + /* Met en place un contexte adapté aux sous-blocs d'un bloc. */ -static GDecContext *create_new_context_for_sub_block(GDecContext *, GInstrBlock *); +static GDecContext *create_new_context_for_sub_block(GDecContext *, GInstrBlock *, GHashTable *); @@ -147,7 +150,7 @@ static bool track_used_registers(GFlowBlock *block, BlockFollowPosition pos, GRA } - + /* do { vmpa_t start, end; @@ -160,7 +163,7 @@ static bool track_used_registers(GFlowBlock *block, BlockFollowPosition pos, GRA } while (0); - + */ break; @@ -203,8 +206,38 @@ static void setup_awaited_regs_allocation(const GInstrBlock *list, vmpa_t start) /****************************************************************************** * * -* Paramètres : ctx = contexte de décompilation courant. * -* block = block regroupant les branches de division. * +* Paramètres : block = bloc d'instructions concerné par la visite. * +* order = position dans la visite. * +* list = liste à compléter. * +* * +* Description : Etablit la liste de tous les allocations attendues. * +* * +* Retour : true pour parcourir tous les blocs. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool merge_all_awaited_regs(GInstrBlock *block, BlockVisitOrder order, GRAccessList *list) +{ + const GRAccessList *awaited; /* Registres conséquents */ + + if (G_IS_FLOW_BLOCK(block)) + { + awaited = g_flow_block_list_regs_accesses(G_FLOW_BLOCK(block)); + g_raccess_list_merge(list, awaited); + } + + return true; + +} + + +/****************************************************************************** +* * +* Paramètres : ctx = contexte de décompilation courant. * +* block = block regroupant les branches de division. * +* shared = liste des allocations passées de registres attendus.* * * * Description : Met en place un contexte adapté aux sous-blocs d'un bloc. * * * @@ -214,17 +247,26 @@ static void setup_awaited_regs_allocation(const GInstrBlock *list, vmpa_t start) * * ******************************************************************************/ -static GDecContext *create_new_context_for_sub_block(GDecContext *ctx, GInstrBlock *block) +static GDecContext *create_new_context_for_sub_block(GDecContext *ctx, GInstrBlock *block, GHashTable *shared) { + GDecContext *result; /* Contexte à retourner */ + GRAccessList *list; /* Allocations attendues */ + result = g_dec_context_dup(ctx); - return g_dec_context_dup(ctx); + list = g_raccess_list_new(); + g_instr_block_visit(block, (instr_block_visitor_cb)merge_all_awaited_regs, list); + g_dec_context_set_awaited(result, list); + g_object_unref(G_OBJECT(list)); + g_dec_context_set_shared_allocs(result, shared); + return result; } + /* ---------------------------------------------------------------------------------- */ /* ENCADREMENT DES INSTRUCTIONS */ /* ---------------------------------------------------------------------------------- */ @@ -282,8 +324,6 @@ static GDecInstruction *merge_decompiled_instructions(GDecInstruction *group, GD static GDecInstruction *decompiled_instructions_block(GFlowBlock *block, GDecContext *ctx) { - GDecInstruction *res; - GArchInstruction *instrs; /* Liste d'instructions natives*/ GArchInstruction *first; /* Première instruction du lot */ GArchInstruction *last; /* Dernière instruction du lot */ @@ -291,12 +331,12 @@ static GDecInstruction *decompiled_instructions_block(GFlowBlock *block, GDecCon GArchInstruction *iter; /* Boucle de parcours */ GDecInstruction *decomp; /* Dernier résultat de décomp. */ GInstrBlock *sub_parent; /* Groupe des sous-branches */ + GHashTable *sub_shared; /* Allocations communes */ GDecContext *sub_ctx; /* Sous-contexte pour branche */ GDecInstruction *true_dinstr; /* Décompilation 'cond vraie' */ GDecInstruction *false_dinstr; /* Décompilation 'cond fausse' */ GArchInstruction *next; /* Instruction de branchement */ vmpa_t next_addr; /* Adresse de cette instruct° */ - //GInstrBlock *next_parent; /* Bloc basique correspondant */ GInstrBlock *next_block; /* Sous-bloc basique direct */ instrs = g_flow_block_get_all_instructions_list(block); @@ -316,14 +356,13 @@ static GDecInstruction *decompiled_instructions_block(GFlowBlock *block, GDecCon /* Post-traitement selon les types de lien */ - - //res = g_dec_context_get_decomp_instrs(ctx); - - /* if ... then ... else ... */ if (G_IS_ITE_INSTRUCTION(decomp)) { sub_parent = g_instr_block_get_links_block(G_INSTR_BLOCK(block)); + sub_shared = g_hash_table_new_full((GHashFunc)g_arch_register_hash, + (GEqualFunc)g_arch_register_equal, + g_object_unref, g_object_unref); true_dinstr = NULL; @@ -335,9 +374,9 @@ static GDecInstruction *decompiled_instructions_block(GFlowBlock *block, GDecCon if (next_block != NULL) { - sub_ctx = create_new_context_for_sub_block(ctx, sub_parent); + sub_ctx = create_new_context_for_sub_block(ctx, next_block, sub_shared); true_dinstr = decompiled_basic_block(next_block, sub_ctx); - /* TODO : merge awaited */ + g_dec_context_spread_allocated_shared_regs(ctx, sub_ctx); g_object_unref(G_OBJECT(sub_ctx)); } @@ -353,29 +392,22 @@ static GDecInstruction *decompiled_instructions_block(GFlowBlock *block, GDecCon if (next_block != NULL) { - sub_ctx = create_new_context_for_sub_block(ctx, sub_parent); + sub_ctx = create_new_context_for_sub_block(ctx, next_block, sub_shared); false_dinstr = decompiled_basic_block(next_block, sub_ctx); - /* TODO : merge awaited */ + g_dec_context_spread_allocated_shared_regs(ctx, sub_ctx); g_object_unref(G_OBJECT(sub_ctx)); } } - printf(" -> ite : %p + %p\n", true_dinstr, false_dinstr); - - printf(" -> ite : %s + %s\n", - true_dinstr ? g_type_name(G_TYPE_FROM_INSTANCE(true_dinstr)) : "none", - false_dinstr ? g_type_name(G_TYPE_FROM_INSTANCE(false_dinstr)) : "none"); - - g_ite_instruction_set_branches(G_ITE_INSTRUCTION(decomp), true_dinstr, false_dinstr); + g_hash_table_unref(sub_shared); + } /* Renvoi des instructions mises en place */ - //return res; - return g_dec_context_get_decomp_instrs(ctx); } |