summaryrefslogtreecommitdiff
path: root/src/arch/dalvik
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2012-11-28 09:43:50 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2012-11-28 09:43:50 (GMT)
commitf95598b68b98f6eda701f8f02bc09cb13f65fc72 (patch)
treeeefee33963448a1ce53a7eb80dacabbcdce8fc21 /src/arch/dalvik
parentfbb4b6f53d2189ba9f61c1fd149534d8aef82dcd (diff)
Followed the excution flow to decompile instructions.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@293 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/arch/dalvik')
-rw-r--r--src/arch/dalvik/context.c2
-rw-r--r--src/arch/dalvik/decomp/if.c66
-rw-r--r--src/arch/dalvik/decomp/invoke.c60
-rw-r--r--src/arch/dalvik/decomp/move.c33
-rw-r--r--src/arch/dalvik/decomp/translate.h9
-rw-r--r--src/arch/dalvik/instruction.c16
6 files changed, 177 insertions, 9 deletions
diff --git a/src/arch/dalvik/context.c b/src/arch/dalvik/context.c
index c7b5ee6..e5041cb 100644
--- a/src/arch/dalvik/context.c
+++ b/src/arch/dalvik/context.c
@@ -430,7 +430,7 @@ static GDecInstruction *g_dalvik_dcontext_convert_register(GDalvikDContext *ctx,
{
found = g_hash_table_lookup(ctx->locals, GUINT_TO_POINTER(DVI_INDEX(info)));
- if (!assign && found != NULL)
+ if (/*!assign && */found != NULL)
{
g_object_ref(G_OBJECT(found));
result = G_DEC_INSTRUCTION(found);
diff --git a/src/arch/dalvik/decomp/if.c b/src/arch/dalvik/decomp/if.c
index 43406c7..b274ead 100644
--- a/src/arch/dalvik/decomp/if.c
+++ b/src/arch/dalvik/decomp/if.c
@@ -93,3 +93,69 @@ GDecInstruction *dalvik_decomp_instr_if(const GArchInstruction *instr, GDecConte
return result;
}
+
+
+
+/******************************************************************************
+* *
+* Paramètres : instr = instruction d'origine à convertir. *
+* ctx = contexte de la phase de décompilation. *
+* *
+* Description : Décompile une instruction de comparaison d'opérandes. *
+* *
+* Retour : Instruction mise en place ou NULL. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDecInstruction *dalvik_decomp_instr_if_zero(const GArchInstruction *instr, GDecContext *ctx)
+{
+ GDecInstruction *result; /* Instruction à retourner */
+ CompSignType sign; /* Type d'opération menée */
+ GArchOperand *operand; /* Opérande de l'instruction */
+ GDecInstruction *op1; /* Premier opérande utilisé */
+ GDecInstruction *op2; /* Second opérande utilisé */
+ vmpa_t jmp; /* Adresse de saut */
+ GDecInstruction *cond; /* Comparaison à restituer */
+
+ switch (g_dalvik_instruction_get_opcode(G_DALVIK_INSTRUCTION(instr)))
+ {
+ case DOP_IF_EQ:
+ sign = CST_EQ;
+ break;
+ case DOP_IF_NE:
+ sign = CST_NE;
+ break;
+ case DOP_IF_LT:
+ sign = CST_LT;
+ break;
+ case DOP_IF_GE:
+ sign = CST_GE;
+ break;
+ case DOP_IF_GT:
+ sign = CST_GT;
+ break;
+ case DOP_IF_LE:
+ sign = CST_LE;
+ break;
+ default:
+ sign = CST_COUNT;
+ break;
+ }
+
+ operand = g_arch_instruction_get_operand(instr, 0);
+ op1 = g_dec_context_convert_register(ctx, operand, false);
+
+ operand = g_imm_operand_new_from_value(MDS_8_BITS_UNSIGNED, (unsigned int)0);
+ op2 = g_imm_expression_new(operand);
+
+ operand = g_arch_instruction_get_operand(instr, 2);
+ jmp = 0x1234ull;/*g_dec_context_convert_register(ctx, operand);*/
+
+ cond = g_cond_expression_new(G_DEC_EXPRESSION(op1), sign, G_DEC_EXPRESSION(op2));
+ result = g_ite_instruction_new(G_DEC_EXPRESSION(cond), jmp, jmp);
+
+ return result;
+
+}
diff --git a/src/arch/dalvik/decomp/invoke.c b/src/arch/dalvik/decomp/invoke.c
index c3650b4..6f863be 100644
--- a/src/arch/dalvik/decomp/invoke.c
+++ b/src/arch/dalvik/decomp/invoke.c
@@ -144,6 +144,66 @@ GDecInstruction *dalvik_decomp_instr_invoke_direct(const GArchInstruction *instr
* Paramètres : instr = instruction d'origine à convertir. *
* ctx = contexte de la phase de décompilation. *
* *
+* Description : Décompile une instruction de type 'invoke-static'. *
+* *
+* Retour : Instruction mise en place ou NULL. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDecInstruction *dalvik_decomp_instr_invoke_static(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 = 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;
+
+ call = g_routine_call_new(routine);
+
+ /* Ajout des arguments */
+
+ operand = g_arch_instruction_get_operand(instr, 0);
+ count = g_dalvik_args_count(G_DALVIK_ARGS_OPERAND(operand));
+
+ for (i = 0; i < count; i++)
+ {
+ arg = g_dalvik_args_operand_get(G_DALVIK_ARGS_OPERAND(operand), i);
+ reg = g_dec_context_convert_register(ctx, arg, false);
+
+ g_routine_call_add_arg(G_ROUTINE_CALL(call), reg);
+
+ }
+
+ return call;
+
+}
+
+
+/******************************************************************************
+* *
+* 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. *
diff --git a/src/arch/dalvik/decomp/move.c b/src/arch/dalvik/decomp/move.c
index f700737..9165447 100644
--- a/src/arch/dalvik/decomp/move.c
+++ b/src/arch/dalvik/decomp/move.c
@@ -33,6 +33,39 @@
* Paramètres : instr = instruction d'origine à convertir. *
* ctx = contexte de la phase de décompilation. *
* *
+* Description : Décompile une instruction de type 'move'. *
+* *
+* Retour : Instruction mise en place ou NULL. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDecInstruction *dalvik_decomp_instr_move(const GArchInstruction *instr, GDecContext *ctx)
+{
+ GDecInstruction *result; /* Instruction à retourner */
+ GArchOperand *operand; /* Opérande de l'instruction */
+ GDecInstruction *src; /* Registre de l'object */
+ GDecInstruction *dest; /* Registre de destination */
+
+ operand = g_arch_instruction_get_operand(instr, 1);
+ src = g_dec_context_convert_register(ctx, operand, false);
+
+ operand = g_arch_instruction_get_operand(instr, 0);
+ dest = g_dec_context_convert_register(ctx, operand, true);
+
+ result = g_assign_expression_new(G_DEC_EXPRESSION(dest), G_DEC_EXPRESSION(src));
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : instr = instruction d'origine à convertir. *
+* ctx = contexte de la phase de décompilation. *
+* *
* Description : Décompile une instruction de type 'move-object'. *
* *
* Retour : Instruction mise en place ou NULL. *
diff --git a/src/arch/dalvik/decomp/translate.h b/src/arch/dalvik/decomp/translate.h
index 7779ab7..b8753db 100644
--- a/src/arch/dalvik/decomp/translate.h
+++ b/src/arch/dalvik/decomp/translate.h
@@ -50,12 +50,18 @@ GDecInstruction *dalvik_decomp_instr_iget(const GArchInstruction *, GDecContext
/* Décompile une instruction de type 'invoke-direct'. */
GDecInstruction *dalvik_decomp_instr_invoke_direct(const GArchInstruction *, GDecContext *);
+/* Décompile une instruction de type 'invoke-static'. */
+GDecInstruction *dalvik_decomp_instr_invoke_static(const GArchInstruction *, GDecContext *);
+
/* Décompile une instruction de type 'invoke-virtual'. */
GDecInstruction *dalvik_decomp_instr_invoke_virtual(const GArchInstruction *, GDecContext *);
/* Décompile une instruction de type 'iput'. */
GDecInstruction *dalvik_decomp_instr_iput(const GArchInstruction *, GDecContext *);
+/* Décompile une instruction de type 'move'. */
+GDecInstruction *dalvik_decomp_instr_move(const GArchInstruction *, GDecContext *);
+
/* Décompile une instruction de type 'move-object'. */
GDecInstruction *dalvik_decomp_instr_move_object(const GArchInstruction *, GDecContext *);
@@ -84,6 +90,9 @@ GDecInstruction *dalvik_decomp_instr_arithm_lit(const GArchInstruction *, GDecCo
/* Décompile une instruction de comparaison d'opérandes. */
GDecInstruction *dalvik_decomp_instr_if(const GArchInstruction *, GDecContext *);
+/* Décompile une instruction de comparaison d'opérandes. */
+GDecInstruction *dalvik_decomp_instr_if_zero(const GArchInstruction *, GDecContext *);
+
#endif /* _ANALYSIS_DECOMP_RTL_DALVIK_TRANSLATE_H */
diff --git a/src/arch/dalvik/instruction.c b/src/arch/dalvik/instruction.c
index f0e679f..5f3a1f4 100644
--- a/src/arch/dalvik/instruction.c
+++ b/src/arch/dalvik/instruction.c
@@ -57,7 +57,7 @@ typedef struct _dalvik_instruction
static dalvik_instruction _instructions[DOP_COUNT] = {
[DOP_NOP] = { 0x00, "nop", NULL },
- [DOP_MOVE] = { 0x01, "move" },
+ [DOP_MOVE] = { 0x01, "move", dalvik_decomp_instr_move },
[DOP_MOVE_FROM_16] = { 0x02, "move/from16" },
[DOP_MOVE_16] = { 0x03, "move/16" },
[DOP_MOVE_WIDE] = { 0x04, "move-wide" },
@@ -112,12 +112,12 @@ static dalvik_instruction _instructions[DOP_COUNT] = {
[DOP_IF_GE] = { 0x35, "if-ge", dalvik_decomp_instr_if },
[DOP_IF_GT] = { 0x36, "if-gt", dalvik_decomp_instr_if },
[DOP_IF_LE] = { 0x37, "if-le", dalvik_decomp_instr_if },
- [DOP_IF_EQZ] = { 0x38, "if-eqz" },
- [DOP_IF_NEZ] = { 0x39, "if-nez" },
- [DOP_IF_LTZ] = { 0x3a, "if-ltz" },
- [DOP_IF_GEZ] = { 0x3b, "if-gez" },
- [DOP_IF_GTZ] = { 0x3c, "if-gtz" },
- [DOP_IF_LEZ] = { 0x3d, "if-lez" },
+ [DOP_IF_EQZ] = { 0x38, "if-eqz", dalvik_decomp_instr_if_zero },
+ [DOP_IF_NEZ] = { 0x39, "if-nez", dalvik_decomp_instr_if_zero },
+ [DOP_IF_LTZ] = { 0x3a, "if-ltz", dalvik_decomp_instr_if_zero },
+ [DOP_IF_GEZ] = { 0x3b, "if-gez", dalvik_decomp_instr_if_zero },
+ [DOP_IF_GTZ] = { 0x3c, "if-gtz", dalvik_decomp_instr_if_zero },
+ [DOP_IF_LEZ] = { 0x3d, "if-lez", dalvik_decomp_instr_if_zero },
[DOP_UNUSED_3E] = { 0x3e, NULL /* unused */ },
[DOP_UNUSED_3F] = { 0x3f, NULL /* unused */ },
[DOP_UNUSED_40] = { 0x40, NULL /* unused */ },
@@ -169,7 +169,7 @@ static dalvik_instruction _instructions[DOP_COUNT] = {
[DOP_INVOKE_VIRTUAL] = { 0x6e, "invoke-virtual", dalvik_decomp_instr_invoke_virtual },
[DOP_INVOKE_SUPER] = { 0x6f, "invoke-static" },
[DOP_INVOKE_DIRECT] = { 0x70, "invoke-direct", dalvik_decomp_instr_invoke_direct },
- [DOP_INVOKE_STATIC] = { 0x71, "invoke-static" },
+ [DOP_INVOKE_STATIC] = { 0x71, "invoke-static", dalvik_decomp_instr_invoke_static },
[DOP_INVOKE_INTERFACE] = { 0x72, "invoke-interface" },
[DOP_UNUSED_73] = { 0x73, NULL /* unused */ },
[DOP_INVOKE_VIRTUAL_RANGE] = { 0x74, "invoke-virtual/range" },