summaryrefslogtreecommitdiff
path: root/src/analysis
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis')
-rw-r--r--src/analysis/blocks/raccess.c2
-rw-r--r--src/analysis/blocks/raccess.h2
-rw-r--r--src/analysis/decomp/decompiler.c2
-rw-r--r--src/analysis/decomp/il.c86
-rw-r--r--src/analysis/disass/macro.c4
5 files changed, 64 insertions, 32 deletions
diff --git a/src/analysis/blocks/raccess.c b/src/analysis/blocks/raccess.c
index 7fe084c..4c76e22 100644
--- a/src/analysis/blocks/raccess.c
+++ b/src/analysis/blocks/raccess.c
@@ -190,7 +190,7 @@ GRAccessList *g_raccess_list_new(void)
* *
******************************************************************************/
-void g_raccess_list_merge(GRAccessList *list, GRAccessList *src)
+void g_raccess_list_merge(GRAccessList *list, const GRAccessList *src)
{
size_t count; /* Taille d'un parcours */
size_t i; /* Boucle de parcours */
diff --git a/src/analysis/blocks/raccess.h b/src/analysis/blocks/raccess.h
index cc2fd00..843933b 100644
--- a/src/analysis/blocks/raccess.h
+++ b/src/analysis/blocks/raccess.h
@@ -77,7 +77,7 @@ GType g_raccess_list_get_type(void);
GRAccessList *g_raccess_list_new(void);
/* Intègre une liste d'accès à des registres dans une autre. */
-void g_raccess_list_merge(GRAccessList *, GRAccessList *);
+void g_raccess_list_merge(GRAccessList *, const GRAccessList *);
/* Compare un accès registre avec un autre. */
int compare_reg_accesses(const reg_access *, const reg_access *);
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);
}
diff --git a/src/analysis/disass/macro.c b/src/analysis/disass/macro.c
index 8652b27..60d99da 100644
--- a/src/analysis/disass/macro.c
+++ b/src/analysis/disass/macro.c
@@ -655,14 +655,14 @@ void group_routines_instructions(GArchInstruction *list, GBinRoutine **routines,
end = start + g_binary_routine_get_size(routines[i]);
- printf("==== %s ====\n", g_binary_routine_to_string(routines[i]));
+ //printf("==== %s ====\n", g_binary_routine_to_string(routines[i]));
block = build_instruction_block(list, start, end, VMPA_MAX);
g_binary_routine_set_basic_blocks(routines[i], block);
- g_instr_block_visit(block, (instr_block_visitor_cb)print_blocks, (int []){ 0 });
+ //g_instr_block_visit(block, (instr_block_visitor_cb)print_blocks, (int []){ 0 });
gtk_extended_status_bar_update_activity(statusbar, id, (i + 1) * 1.0 / count);