summaryrefslogtreecommitdiff
path: root/src/arch/dalvik
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2012-07-29 21:41:52 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2012-07-29 21:41:52 (GMT)
commit8e1f2335773a9025cd46d45a33261725707af3ba (patch)
tree6001a1095985514bbde3c8ec49b4dd5d32182fc8 /src/arch/dalvik
parent8b35a66464636d0c46237af7490a6ca6866ecc4d (diff)
Updated all decompiled instructions using right pseudo registers.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@253 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/arch/dalvik')
-rw-r--r--src/arch/dalvik/context.c224
-rw-r--r--src/arch/dalvik/context.h27
-rw-r--r--src/arch/dalvik/decomp/aget.c14
-rw-r--r--src/arch/dalvik/decomp/aput.c8
-rw-r--r--src/arch/dalvik/decomp/arithm.c34
-rw-r--r--src/arch/dalvik/decomp/array.c20
-rw-r--r--src/arch/dalvik/decomp/const.c6
-rw-r--r--src/arch/dalvik/decomp/if.c6
-rw-r--r--src/arch/dalvik/decomp/iget.c10
-rw-r--r--src/arch/dalvik/decomp/invoke.c8
-rw-r--r--src/arch/dalvik/decomp/iput.c4
-rw-r--r--src/arch/dalvik/decomp/move.c18
-rw-r--r--src/arch/dalvik/decomp/new.c8
-rw-r--r--src/arch/dalvik/decomp/ret.c4
-rw-r--r--src/arch/dalvik/operands/register.c19
-rw-r--r--src/arch/dalvik/operands/register.h3
-rw-r--r--src/arch/dalvik/processor.c23
-rw-r--r--src/arch/dalvik/register.c19
-rw-r--r--src/arch/dalvik/register.h3
19 files changed, 383 insertions, 75 deletions
diff --git a/src/arch/dalvik/context.c b/src/arch/dalvik/context.c
index 67c1861..c7b5ee6 100644
--- a/src/arch/dalvik/context.c
+++ b/src/arch/dalvik/context.c
@@ -28,7 +28,11 @@
#include <string.h>
+#include "operands/register.h"
#include "../context-int.h"
+#include "../../decomp/context-int.h"
+#include "../../decomp/expr/pseudo.h"
+#include "../../format/dex/dex-int.h"
@@ -36,6 +40,7 @@
typedef struct _skipped_dalvik_area skipped_dalvik_area;
+
/* ------------------------ MANIPULATION GLOBALE DU CONTEXTE ------------------------ */
@@ -79,6 +84,41 @@ struct _skipped_dalvik_area
+/* ------------------------- CONTEXTE POUR LA DECOMPILATION ------------------------- */
+
+
+/* Définition d'un contexte pour décompilation Dalkvik (instance) */
+struct _GDalvikDContext
+{
+ GDecContext parent; /* A laisser en premier */
+
+ GDecInstruction *this; /* Représentation de la classe */
+ GHashTable *args; /* Correspondance arg./pseudo */
+ GHashTable *locals; /* Correspondance var./pseudo */
+ size_t locals_count; /* Quantité de var. locales */
+
+};
+
+
+/* Définition d'un contexte pour décompilation Dalkvik (classe) */
+struct _GDalvikDContextClass
+{
+ GDecContextClass parent; /* A laisser en premier */
+
+};
+
+
+/* Initialise la classe des contextes de décompilation Dalkvik. */
+static void g_dalvik_dcontext_class_init(GDalvikDContextClass *);
+
+/* Initialise une instance de contexte de décompilation Dalkvik. */
+static void g_dalvik_dcontext_init(GDalvikDContext *);
+
+/* Convertit un registre machine en un pseudo-registre. */
+static GDecInstruction *g_dalvik_dcontext_convert_register(GDalvikDContext *, GDalvikRegisterOperand *, bool);
+
+
+
/* ---------------------------------------------------------------------------------- */
/* MANIPULATION GLOBALE DU CONTEXTE */
/* ---------------------------------------------------------------------------------- */
@@ -227,3 +267,187 @@ bool g_dalvik_context_have_to_skip(GDalvikContext *ctx, vmpa_t addr)
return result;
}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* CONTEXTE POUR LA DECOMPILATION */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type définit par la GLib pour le contexte de décompilation Dalkvik. */
+G_DEFINE_TYPE(GDalvikDContext, g_dalvik_dcontext, G_TYPE_DEC_CONTEXT);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des contextes de décompilation Dalkvik. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dalvik_dcontext_class_init(GDalvikDContextClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : ctx = instance à initialiser. *
+* *
+* Description : Initialise une instance de contexte de décompilation Dalkvik.*
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dalvik_dcontext_init(GDalvikDContext *ctx)
+{
+ GDecContext *parent; /* Instance parente */
+
+ ctx->args = g_hash_table_new(g_constant_hash, g_direct_equal);
+ ctx->locals = g_hash_table_new(g_constant_hash, g_direct_equal);
+
+ parent = G_DEC_CONTEXT(ctx);
+
+ parent->convert_reg = (convert_register_fc)g_dalvik_dcontext_convert_register;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Crée un contexte pour la décompilation Dalvik. *
+* *
+* Retour : Contexte mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDalvikDContext *g_dalvik_dcontext_new(void)
+{
+ GDalvikDContext *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_DALVIK_DCONTEXT, NULL);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : ctx = instance à consulter, voire mettre à jour. *
+* operand = opérande représentant un registre quelconque. *
+* assign = précise le sort prochain du registre. *
+* *
+* Description : Convertit un registre machine en un pseudo-registre. *
+* *
+* Retour : Pseudo-registre, existant ou non, prêt à emploi. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GDecInstruction *g_dalvik_dcontext_convert_register(GDalvikDContext *ctx, GDalvikRegisterOperand *operand, bool assign)
+{
+ GDecInstruction *result; /* Instance à retourner */
+ GDexFormat *format; /* Recherche de méthode */
+ GBinRoutine *routine; /* Objet des recherches */
+ GDexMethod *method; /* Méthode décompilée */
+ GDalvikRegister *reg; /* Registre Dalvik représenté */
+ uint16_t index; /* Identifiant du registre */
+ DexVariableIndex info; /* Nature du registre */
+ GBinVariable *this; /* Définition de "this" */
+ gpointer *found; /* Pseudo-registre trouvé */
+
+ format = G_DEX_FORMAT(g_object_get_data(G_OBJECT(ctx), "format"));
+ routine = G_BIN_ROUTINE(g_object_get_data(G_OBJECT(ctx), "routine"));
+
+ method = g_dex_format_find_method_by_address(format, g_binary_routine_get_address(routine));
+
+ reg = g_dalvik_register_operand_get(operand);
+
+ index = g_dalvik_register_get_index(reg);
+ info = g_dex_method_get_variable(method, index);
+
+ /* Objet "this" */
+ if (info & DVI_THIS)
+ {
+ if (ctx->this != NULL)
+ g_object_ref(G_OBJECT(ctx->this));
+
+ else
+ {
+ this = g_binary_variable_new(/* FIXME */g_basic_type_new(BTP_OTHER) /* FIXME */);
+ g_binary_variable_set_name(this, "this");
+
+ ctx->this = g_pseudo_register_new();
+ g_pseudo_register_set_variable(G_PSEUDO_REGISTER(ctx->this), this);
+
+ }
+
+ result = ctx->this;
+
+ }
+
+ /* Argument d'appel */
+ else if (info & DVI_ARGUMENT)
+ {
+ found = g_hash_table_lookup(ctx->args, GUINT_TO_POINTER(DVI_INDEX(info)));
+
+ if (found != NULL)
+ {
+ g_object_ref(G_OBJECT(found));
+ result = G_DEC_INSTRUCTION(found);
+ }
+ else
+ {
+ result = g_pseudo_register_new();
+ g_pseudo_register_set_basename(G_PSEUDO_REGISTER(result), "arg");
+ g_pseudo_register_set_index(G_PSEUDO_REGISTER(result), DVI_INDEX(info));
+
+ g_hash_table_insert(ctx->args, GUINT_TO_POINTER(DVI_INDEX(info)), result);
+
+ }
+
+ }
+
+ /* Variable locale */
+ else
+ {
+ found = g_hash_table_lookup(ctx->locals, GUINT_TO_POINTER(DVI_INDEX(info)));
+
+ if (!assign && found != NULL)
+ {
+ g_object_ref(G_OBJECT(found));
+ result = G_DEC_INSTRUCTION(found);
+ }
+ else
+ {
+ result = g_pseudo_register_new();
+ g_pseudo_register_set_basename(G_PSEUDO_REGISTER(result), "var");
+ g_pseudo_register_set_index(G_PSEUDO_REGISTER(result), ctx->locals_count);
+
+ g_hash_table_insert(ctx->locals, GUINT_TO_POINTER(DVI_INDEX(info)), result);
+ ctx->locals_count++;
+
+ }
+
+ }
+
+ return result;
+
+}
diff --git a/src/arch/dalvik/context.h b/src/arch/dalvik/context.h
index 459cc22..c1c93a4 100644
--- a/src/arch/dalvik/context.h
+++ b/src/arch/dalvik/context.h
@@ -30,6 +30,7 @@
#include "../archbase.h"
+#include "../../decomp/context.h"
@@ -70,4 +71,30 @@ bool g_dalvik_context_have_to_skip(GDalvikContext *, vmpa_t);
+/* ------------------------- CONTEXTE POUR LA DECOMPILATION ------------------------- */
+
+
+#define G_TYPE_DALVIK_DCONTEXT g_dalvik_dcontext_get_type()
+#define G_DALVIK_DCONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_dalvik_dcontext_get_type(), GDalvikDContext))
+#define G_IS_DALVIK_DCONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_dalvik_dcontext_get_type()))
+#define G_DALVIK_DCONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DALVIK_DCONTEXT, GGDalvikDContextClass))
+#define G_IS_DALVIK_DCONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DALVIK_DCONTEXT))
+#define G_DALVIK_DCONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DALVIK_DCONTEXT, GGDalvikDContextClass))
+
+
+/* Définition d'un contexte pour décompilation Dalkvik (instance) */
+typedef struct _GDalvikDContext GDalvikDContext;
+
+/* Définition d'un contexte pour décompilation Dalkvik (classe) */
+typedef struct _GDalvikDContextClass GDalvikDContextClass;
+
+
+/* Indique le type définit par la GLib pour le contexte de décompilation Dalkvik. */
+GType g_dalvik_dcontext_get_type(void);
+
+/* Crée un contexte pour la décompilation Dalvik. */
+GDalvikDContext *g_dalvik_dcontext_new(void);
+
+
+
#endif /* _ARCH_DALVIK_CONTEXT_H */
diff --git a/src/arch/dalvik/decomp/aget.c b/src/arch/dalvik/decomp/aget.c
index 41b7e34..0fa66eb 100644
--- a/src/arch/dalvik/decomp/aget.c
+++ b/src/arch/dalvik/decomp/aget.c
@@ -2,7 +2,7 @@
/* OpenIDA - Outil d'analyse de fichiers binaires
* aget.c - décompilation des instructions manipulant des tableaux (chargement)
*
- * Copyright (C) 2010-2011 Cyrille Bagard
+ * Copyright (C) 2010-2012 Cyrille Bagard
*
* This file is part of OpenIDA.
*
@@ -46,19 +46,19 @@ GDecInstruction *dalvik_decomp_instr_aget(const GArchInstruction *instr, GDecCon
{
GDecInstruction *result; /* Instruction à retourner */
GArchOperand *operand; /* Opérande de l'instruction */
- GDecInstruction *content; /* Contenu de cellule visé */
GDecInstruction *array; /* Tableau accédé */
GDecInstruction *index; /* Indice de cellule considérée*/
+ GDecInstruction *content; /* Contenu de cellule visé */
GDecInstruction *access; /* Représentation de l'accès */
- operand = g_arch_instruction_get_operand(instr, 0);
- content = g_dec_context_convert_register(ctx, operand);
-
operand = g_arch_instruction_get_operand(instr, 1);
- array = g_dec_context_convert_register(ctx, operand);
+ array = g_dec_context_convert_register(ctx, operand, false);
operand = g_arch_instruction_get_operand(instr, 2);
- index = g_dec_context_convert_register(ctx, operand);
+ index = g_dec_context_convert_register(ctx, operand, false);
+
+ operand = g_arch_instruction_get_operand(instr, 0);
+ content = g_dec_context_convert_register(ctx, operand, true);
access = g_array_access_new(G_DEC_EXPRESSION(array), G_DEC_EXPRESSION(index));
result = g_assign_expression_new(G_DEC_EXPRESSION(content), G_DEC_EXPRESSION(access));
diff --git a/src/arch/dalvik/decomp/aput.c b/src/arch/dalvik/decomp/aput.c
index 8d86789..41bd89f 100644
--- a/src/arch/dalvik/decomp/aput.c
+++ b/src/arch/dalvik/decomp/aput.c
@@ -2,7 +2,7 @@
/* OpenIDA - Outil d'analyse de fichiers binaires
* aput.c - décompilation des instructions manipulant des tableaux (enregistrement)
*
- * Copyright (C) 2010-2011 Cyrille Bagard
+ * Copyright (C) 2010-2012 Cyrille Bagard
*
* This file is part of OpenIDA.
*
@@ -52,13 +52,13 @@ GDecInstruction *dalvik_decomp_instr_aput(const GArchInstruction *instr, GDecCon
GDecInstruction *access; /* Représentation de l'accès */
operand = g_arch_instruction_get_operand(instr, 0);
- content = g_dec_context_convert_register(ctx, operand);
+ content = g_dec_context_convert_register(ctx, operand, false);
operand = g_arch_instruction_get_operand(instr, 1);
- array = g_dec_context_convert_register(ctx, operand);
+ array = g_dec_context_convert_register(ctx, operand, false);
operand = g_arch_instruction_get_operand(instr, 2);
- index = g_dec_context_convert_register(ctx, operand);
+ index = g_dec_context_convert_register(ctx, operand, false);
access = g_array_access_new(G_DEC_EXPRESSION(array), G_DEC_EXPRESSION(index));
result = g_assign_expression_new(G_DEC_EXPRESSION(access), G_DEC_EXPRESSION(content));
diff --git a/src/arch/dalvik/decomp/arithm.c b/src/arch/dalvik/decomp/arithm.c
index 257c59a..a217adf 100644
--- a/src/arch/dalvik/decomp/arithm.c
+++ b/src/arch/dalvik/decomp/arithm.c
@@ -2,7 +2,7 @@
/* OpenIDA - Outil d'analyse de fichiers binaires
* arithm.c - décompilation des opérations arithmétiques
*
- * Copyright (C) 2010-2011 Cyrille Bagard
+ * Copyright (C) 2010-2012 Cyrille Bagard
*
* This file is part of OpenIDA.
*
@@ -49,9 +49,9 @@ GDecInstruction *dalvik_decomp_instr_arithm(const GArchInstruction *instr, GDecC
GDecInstruction *result; /* Instruction à retourner */
ArithmOperationType type; /* Type d'opération menée */
GArchOperand *operand; /* Opérande de l'instruction */
- GDecInstruction *dest; /* Enregistrement du résultat */
GDecInstruction *op1; /* Premier opérande utilisé */
GDecInstruction *op2; /* Second opérande utilisé */
+ GDecInstruction *dest; /* Enregistrement du résultat */
GDecInstruction *arithm; /* Opération arithmétique */
switch (g_dalvik_instruction_get_opcode(G_DALVIK_INSTRUCTION(instr)))
@@ -85,14 +85,14 @@ GDecInstruction *dalvik_decomp_instr_arithm(const GArchInstruction *instr, GDecC
break;
}
- operand = g_arch_instruction_get_operand(instr, 0);
- dest = g_dec_context_convert_register(ctx, operand);
-
operand = g_arch_instruction_get_operand(instr, 1);
- op1 = g_dec_context_convert_register(ctx, operand);
+ op1 = g_dec_context_convert_register(ctx, operand, false);
operand = g_arch_instruction_get_operand(instr, 2);
- op2 = g_dec_context_convert_register(ctx, operand);
+ op2 = 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);
arithm = g_arithm_expression_new(G_DEC_EXPRESSION(op1), type, G_DEC_EXPRESSION(op2));
result = g_assign_expression_new(G_DEC_EXPRESSION(dest), G_DEC_EXPRESSION(arithm));
@@ -120,8 +120,8 @@ GDecInstruction *dalvik_decomp_instr_arithm_2addr(const GArchInstruction *instr,
GDecInstruction *result; /* Instruction à retourner */
ArithmOperationType type; /* Type d'opération menée */
GArchOperand *operand; /* Opérande de l'instruction */
- GDecInstruction *dest; /* Enregistrement du résultat */
GDecInstruction *op1; /* Premier opérande utilisé */
+ GDecInstruction *dest; /* Enregistrement du résultat */
GDecInstruction *arithm; /* Opération arithmétique */
switch (g_dalvik_instruction_get_opcode(G_DALVIK_INSTRUCTION(instr)))
@@ -153,11 +153,11 @@ GDecInstruction *dalvik_decomp_instr_arithm_2addr(const GArchInstruction *instr,
break;
}
- operand = g_arch_instruction_get_operand(instr, 0);
- dest = g_dec_context_convert_register(ctx, operand);
-
operand = g_arch_instruction_get_operand(instr, 1);
- op1 = g_dec_context_convert_register(ctx, operand);
+ op1 = 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);
arithm = g_arithm_expression_new(G_DEC_EXPRESSION(dest), type, G_DEC_EXPRESSION(op1));
result = g_assign_expression_new(G_DEC_EXPRESSION(dest), G_DEC_EXPRESSION(arithm));
@@ -185,9 +185,9 @@ GDecInstruction *dalvik_decomp_instr_arithm_lit(const GArchInstruction *instr, G
GDecInstruction *result; /* Instruction à retourner */
ArithmOperationType type; /* Type d'opération menée */
GArchOperand *operand; /* Opérande de l'instruction */
- GDecInstruction *dest; /* Enregistrement du résultat */
GDecInstruction *op1; /* Premier opérande utilisé */
GDecInstruction *op2; /* Second opérande utilisé */
+ GDecInstruction *dest; /* Enregistrement du résultat */
GDecInstruction *arithm; /* Opération arithmétique */
switch (g_dalvik_instruction_get_opcode(G_DALVIK_INSTRUCTION(instr)))
@@ -225,15 +225,15 @@ GDecInstruction *dalvik_decomp_instr_arithm_lit(const GArchInstruction *instr, G
break;
}
- operand = g_arch_instruction_get_operand(instr, 0);
- dest = g_dec_context_convert_register(ctx, operand);
-
operand = g_arch_instruction_get_operand(instr, 1);
- op1 = g_dec_context_convert_register(ctx, operand);
+ op1 = g_dec_context_convert_register(ctx, operand, false);
operand = g_arch_instruction_get_operand(instr, 2);
op2 = g_imm_expression_new(G_IMM_OPERAND(operand));
+ operand = g_arch_instruction_get_operand(instr, 0);
+ dest = g_dec_context_convert_register(ctx, operand, true);
+
arithm = g_arithm_expression_new(G_DEC_EXPRESSION(op1), type, G_DEC_EXPRESSION(op2));
result = g_assign_expression_new(G_DEC_EXPRESSION(dest), G_DEC_EXPRESSION(arithm));
diff --git a/src/arch/dalvik/decomp/array.c b/src/arch/dalvik/decomp/array.c
index a841986..3422461 100644
--- a/src/arch/dalvik/decomp/array.c
+++ b/src/arch/dalvik/decomp/array.c
@@ -2,7 +2,7 @@
/* OpenIDA - Outil d'analyse de fichiers binaires
* array.c - décompilation de l'opération récupérant la longueur d'un tableau
*
- * Copyright (C) 2010-2011 Cyrille Bagard
+ * Copyright (C) 2010-2012 Cyrille Bagard
*
* This file is part of OpenIDA.
*
@@ -45,29 +45,19 @@
GDecInstruction *dalvik_decomp_instr_array_length(const GArchInstruction *instr, GDecContext *ctx)
{
GDecInstruction *result; /* Instruction à retourner */
-
-
GArchOperand *operand; /* Opérande de l'instruction */
GDecInstruction *reg; /* Pseudo-registre redéfini */
GDecInstruction *len; /* Enregistrement de taille */
-
-
- result = NULL;
-
-
- //printf("PAssaage !\n");
-
-
+ GDecInstruction *dest; /* Destination de la création */
operand = g_arch_instruction_get_operand(instr, 1);
- reg = g_dec_context_convert_register(ctx, operand);
+ reg = g_dec_context_convert_register(ctx, operand, false);
len = g_dalvik_alength_new(G_DEC_EXPRESSION(reg));
operand = g_arch_instruction_get_operand(instr, 0);
- reg = g_dec_context_convert_register(ctx, operand);
-
+ dest = g_dec_context_convert_register(ctx, operand, true);
- result = g_assign_expression_new(G_DEC_EXPRESSION(reg), G_DEC_EXPRESSION(len));
+ result = g_assign_expression_new(G_DEC_EXPRESSION(dest), G_DEC_EXPRESSION(len));
return result;
diff --git a/src/arch/dalvik/decomp/const.c b/src/arch/dalvik/decomp/const.c
index dce6b35..2e63b36 100644
--- a/src/arch/dalvik/decomp/const.c
+++ b/src/arch/dalvik/decomp/const.c
@@ -2,7 +2,7 @@
/* OpenIDA - Outil d'analyse de fichiers binaires
* const.c - décompilation des chargements de constantes
*
- * Copyright (C) 2010-2011 Cyrille Bagard
+ * Copyright (C) 2010-2012 Cyrille Bagard
*
* This file is part of OpenIDA.
*
@@ -52,7 +52,7 @@ GDecInstruction *dalvik_decomp_instr_const(const GArchInstruction *instr, GDecCo
GDecInstruction *imm; /* Valeur immédiate décompilée */
operand = g_arch_instruction_get_operand(instr, 0);
- reg = g_dec_context_convert_register(ctx, operand);
+ reg = g_dec_context_convert_register(ctx, operand, true);
operand = g_arch_instruction_get_operand(instr, 1);
imm = g_imm_expression_new(G_IMM_OPERAND(operand));
@@ -88,7 +88,7 @@ GDecInstruction *dalvik_decomp_instr_const_str(const GArchInstruction *instr, GD
GDecInstruction *str; /* Chaîne décompilée */
operand = g_arch_instruction_get_operand(instr, 0);
- reg = g_dec_context_convert_register(ctx, operand);
+ reg = g_dec_context_convert_register(ctx, operand, true);
operand = g_arch_instruction_get_operand(instr, 1);
index = g_dalvik_pool_operand_get_index(G_DALVIK_POOL_OPERAND(operand));
diff --git a/src/arch/dalvik/decomp/if.c b/src/arch/dalvik/decomp/if.c
index 1a8663c..43406c7 100644
--- a/src/arch/dalvik/decomp/if.c
+++ b/src/arch/dalvik/decomp/if.c
@@ -2,7 +2,7 @@
/* OpenIDA - Outil d'analyse de fichiers binaires
* array.c - décompilation des branchements conditionnels
*
- * Copyright (C) 2010-2011 Cyrille Bagard
+ * Copyright (C) 2010-2012 Cyrille Bagard
*
* This file is part of OpenIDA.
*
@@ -79,10 +79,10 @@ GDecInstruction *dalvik_decomp_instr_if(const GArchInstruction *instr, GDecConte
}
operand = g_arch_instruction_get_operand(instr, 0);
- op1 = g_dec_context_convert_register(ctx, operand);
+ op1 = g_dec_context_convert_register(ctx, operand, false);
operand = g_arch_instruction_get_operand(instr, 1);
- op2 = g_dec_context_convert_register(ctx, operand);
+ op2 = g_dec_context_convert_register(ctx, operand, false);
operand = g_arch_instruction_get_operand(instr, 2);
jmp = 0x1234ull;/*g_dec_context_convert_register(ctx, operand);*/
diff --git a/src/arch/dalvik/decomp/iget.c b/src/arch/dalvik/decomp/iget.c
index 8b8f9f0..931438c 100644
--- a/src/arch/dalvik/decomp/iget.c
+++ b/src/arch/dalvik/decomp/iget.c
@@ -48,19 +48,16 @@ GDecInstruction *dalvik_decomp_instr_iget(const GArchInstruction *instr, GDecCon
{
GDecInstruction *result; /* Instruction à retourner */
GArchOperand *operand; /* Opérande de l'instruction */
- GDecInstruction *dest; /* Registre de destination */
GDecInstruction *src; /* Registre de l'object */
uint32_t index; /* Indice dans la table */
GDexFormat *format; /* Accès aux constantes */
GDecInstruction *field; /* Champ concerné par l'opérat°*/
GBinVariable *var; /* Variable / champ accédé */
+ GDecInstruction *dest; /* Registre de destination */
GDecInstruction *access; /* Représentation de l'accès */
- operand = g_arch_instruction_get_operand(instr, 0);
- dest = g_dec_context_convert_register(ctx, operand);
-
operand = g_arch_instruction_get_operand(instr, 1);
- src = g_dec_context_convert_register(ctx, operand);
+ src = g_dec_context_convert_register(ctx, operand, false);
operand = g_arch_instruction_get_operand(instr, 2);
index = g_dalvik_pool_operand_get_index(G_DALVIK_POOL_OPERAND(operand));
@@ -70,6 +67,9 @@ GDecInstruction *dalvik_decomp_instr_iget(const GArchInstruction *instr, GDecCon
field = g_pseudo_register_new();
g_pseudo_register_set_variable(G_PSEUDO_REGISTER(field), var);
+ operand = g_arch_instruction_get_operand(instr, 0);
+ dest = g_dec_context_convert_register(ctx, operand, true);
+
access = g_access_expression_new(G_DEC_EXPRESSION(src), G_DEC_EXPRESSION(field));
result = g_assign_expression_new(G_DEC_EXPRESSION(dest), G_DEC_EXPRESSION(access));
diff --git a/src/arch/dalvik/decomp/invoke.c b/src/arch/dalvik/decomp/invoke.c
index a8772cd..c3650b4 100644
--- a/src/arch/dalvik/decomp/invoke.c
+++ b/src/arch/dalvik/decomp/invoke.c
@@ -2,7 +2,7 @@
/* OpenIDA - Outil d'analyse de fichiers binaires
* invoke.c - décompilation des appels de méthode
*
- * Copyright (C) 2010-2011 Cyrille Bagard
+ * Copyright (C) 2010-2012 Cyrille Bagard
*
* This file is part of OpenIDA.
*
@@ -128,7 +128,7 @@ GDecInstruction *dalvik_decomp_instr_invoke_direct(const GArchInstruction *instr
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);
+ reg = g_dec_context_convert_register(ctx, arg, false);
g_routine_call_add_arg(G_ROUTINE_CALL(result), reg);
@@ -188,7 +188,7 @@ GDecInstruction *dalvik_decomp_instr_invoke_virtual(const GArchInstruction *inst
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);
+ reg = g_dec_context_convert_register(ctx, arg, false);
g_routine_call_add_arg(G_ROUTINE_CALL(call), reg);
@@ -197,7 +197,7 @@ GDecInstruction *dalvik_decomp_instr_invoke_virtual(const GArchInstruction *inst
/* Appel depuis le propriétaire */
arg = g_dalvik_args_operand_get(G_DALVIK_ARGS_OPERAND(operand), 0);
- reg = g_dec_context_convert_register(ctx, arg);
+ reg = g_dec_context_convert_register(ctx, arg, false);
result = g_access_expression_new(G_DEC_EXPRESSION(reg), G_DEC_EXPRESSION(call));
diff --git a/src/arch/dalvik/decomp/iput.c b/src/arch/dalvik/decomp/iput.c
index 4db4770..002bdd4 100644
--- a/src/arch/dalvik/decomp/iput.c
+++ b/src/arch/dalvik/decomp/iput.c
@@ -57,10 +57,10 @@ GDecInstruction *dalvik_decomp_instr_iput(const GArchInstruction *instr, GDecCon
GDecInstruction *access; /* Représentation de l'accès */
operand = g_arch_instruction_get_operand(instr, 0);
- src = g_dec_context_convert_register(ctx, operand);
+ src = g_dec_context_convert_register(ctx, operand, false);
operand = g_arch_instruction_get_operand(instr, 1);
- dest = g_dec_context_convert_register(ctx, operand);
+ dest = g_dec_context_convert_register(ctx, operand, false);
operand = g_arch_instruction_get_operand(instr, 2);
index = g_dalvik_pool_operand_get_index(G_DALVIK_POOL_OPERAND(operand));
diff --git a/src/arch/dalvik/decomp/move.c b/src/arch/dalvik/decomp/move.c
index 798b6b0..f700737 100644
--- a/src/arch/dalvik/decomp/move.c
+++ b/src/arch/dalvik/decomp/move.c
@@ -45,14 +45,14 @@ GDecInstruction *dalvik_decomp_instr_move_object(const GArchInstruction *instr,
{
GDecInstruction *result; /* Instruction à retourner */
GArchOperand *operand; /* Opérande de l'instruction */
- GDecInstruction *dest; /* Registre de destination */
GDecInstruction *src; /* Registre de l'object */
-
- operand = g_arch_instruction_get_operand(instr, 0);
- dest = g_dec_context_convert_register(ctx, operand);
+ GDecInstruction *dest; /* Registre de destination */
operand = g_arch_instruction_get_operand(instr, 1);
- src = g_dec_context_convert_register(ctx, operand);
+ 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));
@@ -79,19 +79,19 @@ GDecInstruction *dalvik_decomp_instr_move_result(const GArchInstruction *instr,
GDecInstruction *result; /* Instruction à retourner */
GDecInstruction *list; /* Instructions décompilées */
GArchOperand *operand; /* Opérande de l'instruction */
- GDecInstruction *dest; /* Registre de destination */
GDecInstruction *last; /* Instruction précédante */
+ GDecInstruction *dest; /* Registre de destination */
list = g_dec_context_get_decomp_instrs(ctx);
if (list == NULL) return NULL;
- operand = g_arch_instruction_get_operand(instr, 0);
- dest = g_dec_context_convert_register(ctx, operand);
-
last = g_dec_instruction_get_last(list);
g_dec_instruction_delete(&list, last);
g_dec_context_set_decomp_instrs(ctx, list);
+ 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(last));
return result;
diff --git a/src/arch/dalvik/decomp/new.c b/src/arch/dalvik/decomp/new.c
index 1c4c06e..65da469 100644
--- a/src/arch/dalvik/decomp/new.c
+++ b/src/arch/dalvik/decomp/new.c
@@ -47,15 +47,12 @@ GDecInstruction *dalvik_decomp_instr_new_instance(const GArchInstruction *instr,
{
GDecInstruction *result; /* Instruction à retourner */
GArchOperand *operand; /* Opérande de l'instruction */
- GDecInstruction *dest; /* Registre de destination */
uint32_t index; /* Indice dans la table */
GDexFormat *format; /* Accès aux constantes */
GOpenidaType *type; /* Type concerné par l'opérat° */
GBinRoutine *constructor; /* Constructeur reconstruit */
GDecInstruction *call; /* Appel au constructeur */
-
- operand = g_arch_instruction_get_operand(instr, 0);
- dest = g_dec_context_convert_register(ctx, operand);
+ GDecInstruction *dest; /* Registre de destination */
operand = g_arch_instruction_get_operand(instr, 1);
index = g_dalvik_pool_operand_get_index(G_DALVIK_POOL_OPERAND(operand));
@@ -65,6 +62,9 @@ GDecInstruction *dalvik_decomp_instr_new_instance(const GArchInstruction *instr,
constructor = g_binary_routine_new_constructor(type);
call = g_routine_call_new(constructor);
+ 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(call));
return result;
diff --git a/src/arch/dalvik/decomp/ret.c b/src/arch/dalvik/decomp/ret.c
index 3717529..b7c5414 100644
--- a/src/arch/dalvik/decomp/ret.c
+++ b/src/arch/dalvik/decomp/ret.c
@@ -2,7 +2,7 @@
/* OpenIDA - Outil d'analyse de fichiers binaires
* ret.c - décompilation des ordres de retour
*
- * Copyright (C) 2010-2011 Cyrille Bagard
+ * Copyright (C) 2010-2012 Cyrille Bagard
*
* This file is part of OpenIDA.
*
@@ -48,7 +48,7 @@ GDecInstruction *dalvik_decomp_instr_return(const GArchInstruction *instr, GDecC
GDecInstruction *reg; /* Pseudo-registre redéfini */
operand = g_arch_instruction_get_operand(instr, 0);
- reg = g_dec_context_convert_register(ctx, operand);
+ reg = g_dec_context_convert_register(ctx, operand, false);
result = g_return_expression_new(G_DEC_EXPRESSION(reg));
diff --git a/src/arch/dalvik/operands/register.c b/src/arch/dalvik/operands/register.c
index ced6608..cca4ee7 100644
--- a/src/arch/dalvik/operands/register.c
+++ b/src/arch/dalvik/operands/register.c
@@ -197,6 +197,25 @@ GArchOperand *g_dalvik_register_operand_new_from_existing(GDalvikRegister *reg)
/******************************************************************************
* *
+* Paramètres : operand = opérande représentant un registre. *
+* *
+* Description : Fournit le registre Dalvik associé à l'opérande. *
+* *
+* Retour : Représentation interne du registre. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDalvikRegister *g_dalvik_register_operand_get(const GDalvikRegisterOperand *operand)
+{
+ return operand->reg;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : a = premier opérande à consulter. *
* b = second opérande à consulter. *
* *
diff --git a/src/arch/dalvik/operands/register.h b/src/arch/dalvik/operands/register.h
index a4151f9..ee83b79 100644
--- a/src/arch/dalvik/operands/register.h
+++ b/src/arch/dalvik/operands/register.h
@@ -58,6 +58,9 @@ GArchOperand *g_dalvik_register_operand_new(const bin_t *, off_t *, off_t, bool
/* Crée un opérande visant un registre Dalvik. */
GArchOperand *g_dalvik_register_operand_new_from_existing(GDalvikRegister *);
+/* Fournit le registre Dalvik associé à l'opérande. */
+GDalvikRegister *g_dalvik_register_operand_get(const GDalvikRegisterOperand *);
+
#endif /* _ARCH_DALVIK_OPERANDS_REGISTER_H */
diff --git a/src/arch/dalvik/processor.c b/src/arch/dalvik/processor.c
index ca571c6..9936738 100644
--- a/src/arch/dalvik/processor.c
+++ b/src/arch/dalvik/processor.c
@@ -58,6 +58,9 @@ static void g_dalvik_processor_init(GDalvikProcessor *);
/* Fournit un contexte pour l'exécution du processeur Dalvik. */
static GDalvikContext *g_dalvik_processor_get_context(const GDalvikProcessor *);
+/* Fournit un contexte pour la décompilation Dalvik. */
+static GDalvikDContext *g_dalvik_processor_get_decomp_context(const GDalvikProcessor *);
+
/* Décode une pseudo-instruction dans un flux de données. */
static GArchInstruction *g_dalvik_guess_pseudo_instruction(const GDalvikProcessor *, const bin_t *, off_t *, off_t, vmpa_t);
@@ -111,6 +114,7 @@ static void g_dalvik_processor_init(GDalvikProcessor *proc)
parent->inssize = MDS_16_BITS;
parent->get_ctx = (get_processor_context_fc)g_dalvik_processor_get_context;
+ parent->get_dec_ctx = (get_decomp_context_fc)g_dalvik_processor_get_decomp_context;
parent->decode = (decode_instruction_fc)g_dalvik_processor_decode_instruction;
}
@@ -160,6 +164,25 @@ static GDalvikContext *g_dalvik_processor_get_context(const GDalvikProcessor *pr
/******************************************************************************
* *
+* Paramètres : proc = architecture, spectatrice ici. *
+* *
+* Description : Fournit un contexte pour la décompilation Dalvik. *
+* *
+* Retour : Contexte mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GDalvikDContext *g_dalvik_processor_get_decomp_context(const GDalvikProcessor *proc)
+{
+ return g_dalvik_dcontext_new();
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : proc = architecture visée par la procédure. *
* data = flux de données à analyser. *
* pos = position courante dans ce flux. [OUT] *
diff --git a/src/arch/dalvik/register.c b/src/arch/dalvik/register.c
index cf926d2..6e709f9 100644
--- a/src/arch/dalvik/register.c
+++ b/src/arch/dalvik/register.c
@@ -127,6 +127,25 @@ GDalvikRegister *g_dalvik_register_new(uint16_t index)
/******************************************************************************
* *
+* Paramètres : reg = registre à consulter. *
+* *
+* Description : Fournit l'indice d'un registre Dalvik. *
+* *
+* Retour : Inditifiant représentant le registre. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+uint16_t g_dalvik_register_get_index(const GDalvikRegister *reg)
+{
+ return reg->index;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : a = premier opérande à consulter. *
* b = second opérande à consulter. *
* *
diff --git a/src/arch/dalvik/register.h b/src/arch/dalvik/register.h
index 9b405a5..3fc551a 100644
--- a/src/arch/dalvik/register.h
+++ b/src/arch/dalvik/register.h
@@ -55,6 +55,9 @@ GType g_dalvik_register_get_type(void);
/* Crée une réprésentation de registre Dalvik. */
GDalvikRegister *g_dalvik_register_new(uint16_t);
+/* Fournit l'indice d'un registre Dalvik. */
+uint16_t g_dalvik_register_get_index(const GDalvikRegister *);
+
/* Compare un registre avec un autre. */
bool g_dalvik_register_compare(const GDalvikRegister *, const GDalvikRegister *);