diff options
Diffstat (limited to 'src/arch/dalvik/decomp/invoke.c')
-rw-r--r-- | src/arch/dalvik/decomp/invoke.c | 164 |
1 files changed, 106 insertions, 58 deletions
diff --git a/src/arch/dalvik/decomp/invoke.c b/src/arch/dalvik/decomp/invoke.c index 7360659..a8772cd 100644 --- a/src/arch/dalvik/decomp/invoke.c +++ b/src/arch/dalvik/decomp/invoke.c @@ -24,8 +24,12 @@ #include "translate.h" +#include <string.h> + + #include "../instruction.h" #include "../operand.h" +#include "../../../decomp/expr/access.h" #include "../../../decomp/expr/assign.h" #include "../../../decomp/expr/call.h" #include "../../../format/dex/pool.h" @@ -38,7 +42,7 @@ * Paramètres : instr = instruction d'origine à convertir. * * ctx = contexte de la phase de décompilation. * * * -* Description : Décompile une instruction de type 'invoke-virtual'. * +* Description : Décompile une instruction de type 'invoke-direct'. * * * * Retour : Instruction mise en place ou NULL. * * * @@ -46,112 +50,156 @@ * * ******************************************************************************/ -GDecInstruction *dalvik_decomp_instr_invoke_virtual(const GArchInstruction *instr, GDecContext *ctx) +GDecInstruction *dalvik_decomp_instr_invoke_direct(const GArchInstruction *instr, GDecContext *ctx) { GDecInstruction *result; /* Instruction à retourner */ - - + GDecInstruction *iter; /* Boucle de parcours #1 */ + GDecInstruction *list; /* Instructions décompilées */ size_t count; /* Quantité d'opérandes */ - GArchOperand *op; /* Opérande de l'instruction */ + GArchOperand *operand; /* Opérande de l'instruction */ uint32_t index; /* Indice de l'élément visé */ GDexFormat *format; /* Accès aux constantes */ GBinRoutine *routine; /* Routine visée par l'appel */ + const char *name; /* Chaîne à afficher */ + GDecInstruction *src; /* Source de l'assignation */ + GDecInstruction *dest; /* Destination de l'assignat° */ + size_t i; /* Boucle de parcours #2 */ + GArchOperand *arg; /* Argument brut de l'appel */ + GDecInstruction *reg; /* Argument converti */ - const char *string; /* Chaîne à afficher */ - GOpenidaType *type; /* Type quelconque */ - char *tmp; /* Chaîne à afficher & libérer */ + result = NULL; + iter = NULL; + list = g_dec_context_get_decomp_instrs(ctx); + if (list == NULL) return NULL; + /* Récupération de la méthode */ - GArchOperand *operand; /* Opérande de l'instruction */ - GDecInstruction *reg; /* Pseudo-registre redéfini */ - GDecInstruction *imm; /* Valeur immédiate décompilée */ + count = g_arch_instruction_count_operands(instr); + operand = g_arch_instruction_get_operand(instr, count - 1); - GArchInstruction *iter; /* Boucle de parcours */ - vmpa_t max; /* Limite à ne pas dépasser */ + index = g_dalvik_pool_operand_get_index(G_DALVIK_POOL_OPERAND(operand)); + format = G_DEX_FORMAT(g_object_get_data(G_OBJECT(ctx), "format")); + routine = get_routine_from_dex_pool(format, index); + if (routine == NULL) return NULL; - result = NULL; + /* Détermination de la routine-cible exacte */ + name = g_binary_routine_get_name(routine); - printf("PAssaage !\n"); + if (strcmp(name, "<init>") != 0) + result = g_routine_call_new(routine); + else + { + src = NULL; /* Pour gcc... */ + for (iter = g_dec_instruction_get_last(list); + iter != NULL; + iter = g_dec_instruction_get_prev_iter(list, iter)) + { + if (!G_IS_ASSIGN_EXPRESSION(iter)) continue; + src = g_assign_expression_get_src(G_ASSIGN_EXPRESSION(iter)); + if (!G_IS_ROUTINE_CALL(src)) continue; + dest = g_assign_expression_get_dest(G_ASSIGN_EXPRESSION(iter)); + /* TODO : vérifier aussi la concordance des registres src && instr */ + break; - /* Récupération de la méthode */ + } - count = g_arch_instruction_count_operands(instr); - op = g_arch_instruction_get_operand(instr, count - 1); + if (iter == NULL) return NULL; - index = g_dalvik_pool_operand_get_index(G_DALVIK_POOL_OPERAND(op)); + result = src; - printf("POOL ?? %d -> %d\n", G_IS_DALVIK_POOL_OPERAND(op), index); + g_dec_instruction_delete(&list, iter); + g_dec_context_set_decomp_instrs(ctx, list); - format = G_DEX_FORMAT(g_object_get_data(G_OBJECT(ctx), "format")); - routine = get_routine_from_dex_pool(format, index); - if (routine == NULL) return NULL; + } + /* Ajout des arguments */ -#if 0 - if (operand->cache.method == NULL) - g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, - "<bad_method_index>", 18, RTT_VAR_NAME); + operand = g_arch_instruction_get_operand(instr, 0); + count = g_dalvik_args_count(G_DALVIK_ARGS_OPERAND(operand)); - else - { - tmp = g_binary_routine_to_string(operand->cache.method); + for (i = 1; i < count; i++) + { + arg = g_dalvik_args_operand_get(G_DALVIK_ARGS_OPERAND(operand), i); + reg = g_dec_context_convert_register(ctx, arg); - g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, - tmp, strlen(tmp), RTT_VAR_NAME); + g_routine_call_add_arg(G_ROUTINE_CALL(result), reg); - free(tmp); + } + return (iter != NULL ? iter : result); -#endif +} - result = g_routine_call_new(routine, true); - //GDecInstruction *g_routine_call_new(GBinRoutine *routine, bool is_object) - /* - operand = g_arch_instruction_get_operand(instr, 1); - reg = g_dec_context_convert_register(ctx, operand); +/****************************************************************************** +* * +* Paramètres : instr = instruction d'origine à convertir. * +* ctx = contexte de la phase de décompilation. * +* * +* Description : Décompile une instruction de type 'invoke-virtual'. * +* * +* Retour : Instruction mise en place ou NULL. * +* * +* Remarques : - * +* * +******************************************************************************/ - operand = g_arch_instruction_get_operand(instr, 1); - imm = g_imm_expression_new(G_IMM_OPERAND(operand)); +GDecInstruction *dalvik_decomp_instr_invoke_virtual(const GArchInstruction *instr, GDecContext *ctx) +{ + GDecInstruction *result; /* Instruction à retourner */ + size_t count; /* Quantité d'opérandes */ + GArchOperand *operand; /* Opérande de l'instruction */ + uint32_t index; /* Indice de l'élément visé */ + GDexFormat *format; /* Accès aux constantes */ + GBinRoutine *routine; /* Routine visée par l'appel */ + GDecInstruction *call; /* Représentation de l'appel */ + size_t i; /* Boucle de parcours #2 */ + GArchOperand *arg; /* Argument brut de l'appel */ + GDecInstruction *reg; /* Argument converti */ - result = g_assign_expression_new(G_DEC_EXPRESSION(reg), G_DEC_EXPRESSION(imm)); - */ + result = NULL; + /* Récupération de la méthode */ + count = g_arch_instruction_count_operands(instr); + operand = g_arch_instruction_get_operand(instr, count - 1); + index = g_dalvik_pool_operand_get_index(G_DALVIK_POOL_OPERAND(operand)); + format = G_DEX_FORMAT(g_object_get_data(G_OBJECT(ctx), "format")); + routine = get_routine_from_dex_pool(format, index); + if (routine == NULL) return NULL; - /* Récupération d'un résultat ? */ + call = g_routine_call_new(routine); - iter = instr; - max = g_dec_context_get_max_address(ctx); + /* Ajout des arguments */ - iter = g_arch_instruction_get_next_iter(instr, iter, max); + operand = g_arch_instruction_get_operand(instr, 0); + count = g_dalvik_args_count(G_DALVIK_ARGS_OPERAND(operand)); - if (iter != NULL) - switch (g_dalvik_instruction_get_opcode(G_DALVIK_INSTRUCTION(iter))) - { - case DOP_MOVE_RESULT: + for (i = 1; i < count; i++) + { + arg = g_dalvik_args_operand_get(G_DALVIK_ARGS_OPERAND(operand), i); + reg = g_dec_context_convert_register(ctx, arg); - operand = g_arch_instruction_get_operand(iter, 0); - reg = g_dec_context_convert_register(ctx, operand); + g_routine_call_add_arg(G_ROUTINE_CALL(call), reg); - result = g_assign_expression_new(G_DEC_EXPRESSION(reg), G_DEC_EXPRESSION(result)); + } - break; + /* Appel depuis le propriétaire */ - default: - break; + arg = g_dalvik_args_operand_get(G_DALVIK_ARGS_OPERAND(operand), 0); + reg = g_dec_context_convert_register(ctx, arg); - } + result = g_access_expression_new(G_DEC_EXPRESSION(reg), G_DEC_EXPRESSION(call)); return result; |