summaryrefslogtreecommitdiff
path: root/src/arch
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2010-11-11 01:22:43 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2010-11-11 01:22:43 (GMT)
commitb33a52031c0d44a79604bc8d9036c30bffd020cb (patch)
treec825e3330684ca57f7c423328cd116b2d6ec0f6a /src/arch
parent828124e38d266e382bb1477ef51c9fac8e81c591 (diff)
Built some expressions for the decompilation tree.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@190 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/arch')
-rw-r--r--src/arch/Makefile.am3
-rw-r--r--src/arch/dalvik/Makefile.am9
-rw-r--r--src/arch/dalvik/dop_aget.c68
-rw-r--r--src/arch/dalvik/dop_aput.c68
-rw-r--r--src/arch/dalvik/dop_arithm.c175
-rw-r--r--src/arch/dalvik/dop_array.c74
-rw-r--r--src/arch/dalvik/dop_const.c72
-rw-r--r--src/arch/dalvik/dop_invoke.c158
-rw-r--r--src/arch/dalvik/instruction.c110
-rw-r--r--src/arch/dalvik/instruction.h3
-rw-r--r--src/arch/dalvik/translate.h56
-rw-r--r--src/arch/immediate.c87
-rw-r--r--src/arch/instruction-int.h4
-rw-r--r--src/arch/instruction.c31
-rw-r--r--src/arch/instruction.h7
-rw-r--r--src/arch/operand-int.h3
-rw-r--r--src/arch/operand.c21
-rw-r--r--src/arch/operand.h6
-rw-r--r--src/arch/translate.h39
19 files changed, 956 insertions, 38 deletions
diff --git a/src/arch/Makefile.am b/src/arch/Makefile.am
index 8f1c1ff..1a02c07 100644
--- a/src/arch/Makefile.am
+++ b/src/arch/Makefile.am
@@ -10,7 +10,8 @@ libarch_la_SOURCES = \
operand-int.h \
operand.h operand.c \
processor-int.h \
- processor.h processor.c
+ processor.h processor.c \
+ translate.h
libarch_la_LIBADD = \
arm/libarcharm.la \
diff --git a/src/arch/dalvik/Makefile.am b/src/arch/dalvik/Makefile.am
index a7e099f..8dc93ae 100644
--- a/src/arch/dalvik/Makefile.am
+++ b/src/arch/dalvik/Makefile.am
@@ -3,6 +3,12 @@ noinst_LTLIBRARIES = libarchdalvik.la
libarchdalvik_la_SOURCES = \
instruction.h instruction.c \
+ dop_aget.c \
+ dop_aput.c \
+ dop_arithm.c \
+ dop_array.c \
+ dop_const.c \
+ dop_invoke.c \
op_add.c \
op_aget.c \
op_and.c \
@@ -33,7 +39,8 @@ libarchdalvik_la_SOURCES = \
opcodes.h \
operand.h operand.c \
processor.h processor.c \
- register.h register.c
+ register.h register.c \
+ translate.h
libarchdalvik_la_CFLAGS = $(AM_CFLAGS)
diff --git a/src/arch/dalvik/dop_aget.c b/src/arch/dalvik/dop_aget.c
new file mode 100644
index 0000000..77e6ef2
--- /dev/null
+++ b/src/arch/dalvik/dop_aget.c
@@ -0,0 +1,68 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * dop_aget.c - décompilation des instructions manipulant des tableaux (chargement)
+ *
+ * Copyright (C) 2010 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "translate.h"
+
+
+#include "../../decomp/expr/array.h"
+#include "../../decomp/expr/assign.h"
+
+
+
+/******************************************************************************
+* *
+* Paramètres : instr = instruction d'origine à convertir. *
+* ctx = contexte de la phase de décompilation. *
+* *
+* Description : Décompile une instruction de type 'aget'. *
+* *
+* Retour : Instruction mise en place ou NULL. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDecInstruction *dalvik_decomp_instr_aget(const GArchInstruction *instr, GDecContext *ctx)
+{
+ 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 *access; /* Représentation de l'accès */
+
+ operand = g_arch_instruction_get_operand(instr, 0);
+ content = g_pseudo_register_new();
+
+ operand = g_arch_instruction_get_operand(instr, 1);
+ array = g_pseudo_register_new();
+
+ operand = g_arch_instruction_get_operand(instr, 2);
+ index = g_pseudo_register_new();
+
+ 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));
+
+ return result;
+
+}
diff --git a/src/arch/dalvik/dop_aput.c b/src/arch/dalvik/dop_aput.c
new file mode 100644
index 0000000..2e4527e
--- /dev/null
+++ b/src/arch/dalvik/dop_aput.c
@@ -0,0 +1,68 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * dop_aput.c - décompilation des instructions manipulant des tableaux (enregistrement)
+ *
+ * Copyright (C) 2010 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "translate.h"
+
+
+#include "../../decomp/expr/array.h"
+#include "../../decomp/expr/assign.h"
+
+
+
+/******************************************************************************
+* *
+* Paramètres : instr = instruction d'origine à convertir. *
+* ctx = contexte de la phase de décompilation. *
+* *
+* Description : Décompile une instruction de type 'aput'. *
+* *
+* Retour : Instruction mise en place ou NULL. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDecInstruction *dalvik_decomp_instr_aput(const GArchInstruction *instr, GDecContext *ctx)
+{
+ 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 *access; /* Représentation de l'accès */
+
+ operand = g_arch_instruction_get_operand(instr, 0);
+ content = g_pseudo_register_new();
+
+ operand = g_arch_instruction_get_operand(instr, 1);
+ array = g_pseudo_register_new();
+
+ operand = g_arch_instruction_get_operand(instr, 2);
+ index = g_pseudo_register_new();
+
+ 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));
+
+ return result;
+
+}
diff --git a/src/arch/dalvik/dop_arithm.c b/src/arch/dalvik/dop_arithm.c
new file mode 100644
index 0000000..388f906
--- /dev/null
+++ b/src/arch/dalvik/dop_arithm.c
@@ -0,0 +1,175 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * dop_arithm.c - décompilation des opérations arithmétiques
+ *
+ * Copyright (C) 2010 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "translate.h"
+
+
+#include "instruction.h"
+#include "../../decomp/expr/arithm.h"
+#include "../../decomp/expr/assign.h"
+#include "../../decomp/expr/immediate.h"
+
+
+
+/******************************************************************************
+* *
+* Paramètres : instr = instruction d'origine à convertir. *
+* ctx = contexte de la phase de décompilation. *
+* *
+* Description : Décompile une instruction de type 'opérations arithmétiques'.*
+* *
+* Retour : Instruction mise en place ou NULL. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDecInstruction *dalvik_decomp_instr_arithm_2addr(const GArchInstruction *instr, GDecContext *ctx)
+{
+ 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 *arithm; /* Opération arithmétique */
+
+ switch (g_dalvik_instruction_get_opcode(G_DALVIK_INSTRUCTION(instr)))
+ {
+ case DOP_ADD_INT_2ADDR:
+ type = AOT_ADD;
+ break;
+ case DOP_MUL_INT_2ADDR:
+ case DOP_MUL_DOUBLE_2ADDR:
+ type = AOT_MUL;
+ break;
+ case DOP_DIV_INT_2ADDR:
+ type = AOT_DIV;
+ break;
+ case DOP_REM_INT_2ADDR:
+ type = AOT_REM;
+ break;
+ case DOP_AND_INT_2ADDR:
+ type = AOT_AND;
+ break;
+ case DOP_OR_INT_2ADDR:
+ type = AOT_OR;
+ break;
+ case DOP_XOR_INT_2ADDR:
+ type = AOT_XOR;
+ break;
+ default:
+ type = AOT_COUNT;
+ break;
+ }
+
+ operand = g_arch_instruction_get_operand(instr, 0);
+ dest = g_pseudo_register_new();
+
+ operand = g_arch_instruction_get_operand(instr, 1);
+ op1 = g_pseudo_register_new();
+
+ operand = g_arch_instruction_get_operand(instr, 2);
+ op2 = g_pseudo_register_new();
+
+ 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));
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : instr = instruction d'origine à convertir. *
+* ctx = contexte de la phase de décompilation. *
+* *
+* Description : Décompile une instruction de type 'opérations arithmétiques'.*
+* *
+* Retour : Instruction mise en place ou NULL. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDecInstruction *dalvik_decomp_instr_arithm_lit(const GArchInstruction *instr, GDecContext *ctx)
+{
+ 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 *arithm; /* Opération arithmétique */
+
+ switch (g_dalvik_instruction_get_opcode(G_DALVIK_INSTRUCTION(instr)))
+ {
+ case DOP_ADD_INT_LIT8:
+ case DOP_ADD_INT_LIT16:
+ type = AOT_ADD;
+ break;
+ case DOP_MUL_INT_LIT8:
+ case DOP_MUL_INT_LIT16:
+ type = AOT_MUL;
+ break;
+ case DOP_DIV_INT_LIT8:
+ case DOP_DIV_INT_LIT16:
+ type = AOT_DIV;
+ break;
+ case DOP_REM_INT_LIT8:
+ case DOP_REM_INT_LIT16:
+ type = AOT_REM;
+ break;
+ case DOP_AND_INT_LIT8:
+ case DOP_AND_INT_LIT16:
+ type = AOT_AND;
+ break;
+ case DOP_OR_INT_LIT8:
+ case DOP_OR_INT_LIT16:
+ type = AOT_OR;
+ break;
+ case DOP_XOR_INT_LIT8:
+ case DOP_XOR_INT_LIT16:
+ type = AOT_XOR;
+ break;
+ default:
+ type = AOT_COUNT;
+ break;
+ }
+
+ operand = g_arch_instruction_get_operand(instr, 0);
+ dest = g_pseudo_register_new();
+
+ operand = g_arch_instruction_get_operand(instr, 1);
+ op1 = g_pseudo_register_new();
+
+ operand = g_arch_instruction_get_operand(instr, 2);
+ op2 = g_imm_expression_new(G_IMM_OPERAND(operand));
+
+ 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));
+
+ return result;
+
+}
diff --git a/src/arch/dalvik/dop_array.c b/src/arch/dalvik/dop_array.c
new file mode 100644
index 0000000..035b3eb
--- /dev/null
+++ b/src/arch/dalvik/dop_array.c
@@ -0,0 +1,74 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * dop_array.c - décompilation de l'opération récupérant la longueur d'un tableau
+ *
+ * Copyright (C) 2010 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "translate.h"
+
+
+#include "../../decomp/expr/assign.h"
+#include "../../decomp/expr/dalvik/array.h"
+
+
+
+/******************************************************************************
+* *
+* Paramètres : instr = instruction d'origine à convertir. *
+* ctx = contexte de la phase de décompilation. *
+* *
+* Description : Décompile une instruction de type 'array-length'. *
+* *
+* Retour : Instruction mise en place ou NULL. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+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");
+
+
+
+ operand = g_arch_instruction_get_operand(instr, 1);
+ reg = g_pseudo_register_new();
+ len = g_dalvik_alength_new(G_DEC_EXPRESSION(reg));
+
+ operand = g_arch_instruction_get_operand(instr, 0);
+ reg = g_pseudo_register_new();
+
+
+ result = g_assign_expression_new(G_DEC_EXPRESSION(reg), G_DEC_EXPRESSION(len));
+
+ return result;
+
+}
diff --git a/src/arch/dalvik/dop_const.c b/src/arch/dalvik/dop_const.c
new file mode 100644
index 0000000..eab7acd
--- /dev/null
+++ b/src/arch/dalvik/dop_const.c
@@ -0,0 +1,72 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * dop_const.c - décompilation des chargements de constantes
+ *
+ * Copyright (C) 2010 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "translate.h"
+
+
+#include "../../decomp/expr/assign.h"
+#include "../../decomp/expr/immediate.h"
+
+
+
+/******************************************************************************
+* *
+* Paramètres : instr = instruction d'origine à convertir. *
+* ctx = contexte de la phase de décompilation. *
+* *
+* Description : Décompile une instruction de type 'const'. *
+* *
+* Retour : Instruction mise en place ou NULL. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDecInstruction *dalvik_decomp_instr_const(const GArchInstruction *instr, GDecContext *ctx)
+{
+ GDecInstruction *result; /* Instruction à retourner */
+
+
+ GArchOperand *operand; /* Opérande de l'instruction */
+ GDecInstruction *reg; /* Pseudo-registre redéfini */
+ GDecInstruction *imm; /* Valeur immédiate décompilée */
+
+
+ result = NULL;
+
+
+ printf("PAssaage !\n");
+
+
+
+ operand = g_arch_instruction_get_operand(instr, 1);
+ reg = g_pseudo_register_new();
+
+ operand = g_arch_instruction_get_operand(instr, 1);
+ imm = g_imm_expression_new(G_IMM_OPERAND(operand));
+
+ result = g_assign_expression_new(G_DEC_EXPRESSION(reg), G_DEC_EXPRESSION(imm));
+
+ return result;
+
+}
diff --git a/src/arch/dalvik/dop_invoke.c b/src/arch/dalvik/dop_invoke.c
new file mode 100644
index 0000000..e4fa1fb
--- /dev/null
+++ b/src/arch/dalvik/dop_invoke.c
@@ -0,0 +1,158 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * dop_invoke.c - décompilation des appels de méthode
+ *
+ * Copyright (C) 2010 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "translate.h"
+
+
+#include "instruction.h"
+#include "operand.h"
+#include "../../decomp/expr/assign.h"
+#include "../../decomp/expr/call.h"
+#include "../../format/dex/pool.h"
+
+
+
+
+/******************************************************************************
+* *
+* 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 : - *
+* *
+******************************************************************************/
+
+GDecInstruction *dalvik_decomp_instr_invoke_virtual(const GArchInstruction *instr, GDecContext *ctx)
+{
+ GDecInstruction *result; /* Instruction à retourner */
+
+
+ size_t count; /* Quantité d'opérandes */
+ GArchOperand *op; /* 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 *string; /* Chaîne à afficher */
+ GOpenidaType *type; /* Type quelconque */
+ char *tmp; /* Chaîne à afficher & libérer */
+
+
+
+ GArchOperand *operand; /* Opérande de l'instruction */
+ GDecInstruction *reg; /* Pseudo-registre redéfini */
+ GDecInstruction *imm; /* Valeur immédiate décompilée */
+
+ GArchInstruction *iter; /* Boucle de parcours */
+ vmpa_t max; /* Limite à ne pas dépasser */
+
+
+ result = NULL;
+
+
+ printf("PAssaage !\n");
+
+
+
+
+
+
+ /* Récupération de la méthode */
+
+ count = g_arch_instruction_count_operands(instr);
+ op = g_arch_instruction_get_operand(instr, count - 1);
+
+ index = g_dalvik_pool_operand_get_index(G_DALVIK_POOL_OPERAND(op));
+
+ printf("POOL ?? %d -> %d\n", G_IS_DALVIK_POOL_OPERAND(op), index);
+
+ 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;
+
+
+#if 0
+ if (operand->cache.method == NULL)
+ g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY,
+ "<bad_method_index>", 18, RTT_VAR_NAME);
+
+ else
+ {
+ tmp = g_binary_routine_to_string(operand->cache.method);
+
+ g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY,
+ tmp, strlen(tmp), RTT_VAR_NAME);
+
+ free(tmp);
+
+
+#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_pseudo_register_new();
+
+ operand = g_arch_instruction_get_operand(instr, 1);
+ imm = g_imm_expression_new(G_IMM_OPERAND(operand));
+
+ result = g_assign_expression_new(G_DEC_EXPRESSION(reg), G_DEC_EXPRESSION(imm));
+ */
+
+
+
+
+
+ /* Récupération d'un résultat ? */
+
+ iter = instr;
+ max = g_dec_context_get_max_address(ctx);
+
+ iter = g_arch_instruction_get_next_iter(instr, iter, max);
+
+ if (iter != NULL)
+ switch (g_dalvik_instruction_get_opcode(G_DALVIK_INSTRUCTION(iter)))
+ {
+ case DOP_MOVE_RESULT:
+
+ operand = g_arch_instruction_get_operand(instr, 0);
+ reg = g_pseudo_register_new();
+
+ result = g_assign_expression_new(G_DEC_EXPRESSION(reg), G_DEC_EXPRESSION(result));
+
+ break;
+
+ default:
+ break;
+
+ }
+
+ return result;
+
+}
diff --git a/src/arch/dalvik/instruction.c b/src/arch/dalvik/instruction.c
index 13c8e83..e8059d6 100644
--- a/src/arch/dalvik/instruction.c
+++ b/src/arch/dalvik/instruction.c
@@ -24,7 +24,8 @@
#include "instruction.h"
-#include "../instruction-int.h"
+#include "translate.h"
+#include "../instruction-int.h"
@@ -63,6 +64,8 @@ typedef struct _dalvik_instruction
const char *keyword; /* Mot clef de la commande */
+ decomp_instr_fc decomp; /* Procédure de décompilation */
+
} dalvik_instruction;
@@ -81,7 +84,7 @@ static dalvik_instruction _instructions[DOP_COUNT] = {
[DOP_RETURN] = { 0x0f, "return" },
[DOP_RETURN_WIDE] = { 0x10, "return-wide" },
[DOP_RETURN_OBJECT] = { 0x11, "return-object" },
- [DOP_CONST_4] = { 0x12, "const/4" },
+ [DOP_CONST_4] = { 0x12, "const/4", dalvik_decomp_instr_const },
[DOP_CONST_16] = { 0x13, "const/16" },
[DOP_CONST] = { 0x14, "const" },
[DOP_CONST_HIGH16] = { 0x15, "const/high16" },
@@ -94,7 +97,7 @@ static dalvik_instruction _instructions[DOP_COUNT] = {
[DOP_CHECK_CAST] = { 0x1f, "check-cast" },
- [DOP_ARRAY_LENGTH] = { 0x21, "array-length" },
+ [DOP_ARRAY_LENGTH] = { 0x21, "array-length", dalvik_decomp_instr_array_length },
[DOP_NEW_INSTANCE] = { 0x22, "new-instance" },
[DOP_NEW_ARRAY] = { 0x23, "new-array" },
@@ -126,14 +129,14 @@ static dalvik_instruction _instructions[DOP_COUNT] = {
[DOP_AGET_WIDE] = { 0x45, "aget-wide" },
[DOP_AGET_OBJECT] = { 0x46, "aget-object" },
[DOP_AGET_BOOLEAN] = { 0x47, "aget-boolean" },
- [DOP_AGET_BYTE] = { 0x48, "aget-byte" },
+ [DOP_AGET_BYTE] = { 0x48, "aget-byte", dalvik_decomp_instr_aget },
[DOP_AGET_CHAR] = { 0x49, "aget-char" },
[DOP_AGET_SHORT] = { 0x4a, "aget-short" },
[DOP_APUT] = { 0x4b, "aput" },
[DOP_APUT_WIDE] = { 0x4c, "aput-wide" },
[DOP_APUT_OBJECT] = { 0x4d, "aput-object" },
[DOP_APUT_BOOLEAN] = { 0x4e, "aput-boolean" },
- [DOP_APUT_BYTE] = { 0x4f, "aput-byte" },
+ [DOP_APUT_BYTE] = { 0x4f, "aput-byte", dalvik_decomp_instr_aput },
[DOP_APUT_CHAR] = { 0x50, "aput-char" },
[DOP_APUT_SHORT] = { 0x51, "aput-short" },
[DOP_IGET] = { 0x52, "iget" },
@@ -164,7 +167,7 @@ static dalvik_instruction _instructions[DOP_COUNT] = {
[DOP_SPUT_BYTE] = { 0x6b, "sput-byte" },
[DOP_SPUT_CHAR] = { 0x6c, "sput-char" },
[DOP_SPUT_SHORT] = { 0x6d, "sput-short" },
- [DOP_INVOKE_VIRTUAL] = { 0x6e, "invoke-virtual" },
+ [DOP_INVOKE_VIRTUAL] = { 0x6e, "invoke-virtual", dalvik_decomp_instr_invoke_virtual },
[DOP_INVOKE_SUPER] = { 0x6f, "invoke-static" },
[DOP_INVOKE_DIRECT] = { 0x70, "invoke-direct" },
[DOP_INVOKE_STATIC] = { 0x71, "invoke-static" },
@@ -195,34 +198,34 @@ static dalvik_instruction _instructions[DOP_COUNT] = {
[DOP_XOR_INT] = { 0x97, "xor-int" },
- [DOP_ADD_INT_2ADDR] = { 0xb0, "add-int/2addr" },
+ [DOP_ADD_INT_2ADDR] = { 0xb0, "add-int/2addr", dalvik_decomp_instr_arithm_2addr },
- [DOP_MUL_INT_2ADDR] = { 0xb2, "mul-int/2addr" },
- [DOP_DIV_INT_2ADDR] = { 0xb3, "div-int/2addr" },
- [DOP_REM_INT_2ADDR] = { 0xb4, "rem-int/2addr" },
- [DOP_AND_INT_2ADDR] = { 0xb5, "and-int/2addr" },
- [DOP_OR_INT_2ADDR] = { 0xb6, "or-int/2addr" },
- [DOP_XOR_INT_2ADDR] = { 0xb7, "xor-int/2addr" },
+ [DOP_MUL_INT_2ADDR] = { 0xb2, "mul-int/2addr", dalvik_decomp_instr_arithm_2addr },
+ [DOP_DIV_INT_2ADDR] = { 0xb3, "div-int/2addr", dalvik_decomp_instr_arithm_2addr },
+ [DOP_REM_INT_2ADDR] = { 0xb4, "rem-int/2addr", dalvik_decomp_instr_arithm_2addr },
+ [DOP_AND_INT_2ADDR] = { 0xb5, "and-int/2addr", dalvik_decomp_instr_arithm_2addr },
+ [DOP_OR_INT_2ADDR] = { 0xb6, "or-int/2addr", dalvik_decomp_instr_arithm_2addr },
+ [DOP_XOR_INT_2ADDR] = { 0xb7, "xor-int/2addr", dalvik_decomp_instr_arithm_2addr },
- [DOP_MUL_DOUBLE_2ADDR] = { 0xcd, "mul-double/2addr" },
+ [DOP_MUL_DOUBLE_2ADDR] = { 0xcd, "mul-double/2addr", dalvik_decomp_instr_arithm_2addr },
- [DOP_ADD_INT_LIT16] = { 0xd0, "add-int/lit16" },
+ [DOP_ADD_INT_LIT16] = { 0xd0, "add-int/lit16", dalvik_decomp_instr_arithm_lit },
[DOP_RSUB_INT] = { 0xd1, "rsub-int" },
- [DOP_MUL_INT_LIT16] = { 0xd2, "mul-int/lit16" },
- [DOP_DIV_INT_LIT16] = { 0xd3, "div-int/lit16" },
- [DOP_REM_INT_LIT16] = { 0xd4, "rem-int/lit16" },
- [DOP_AND_INT_LIT16] = { 0xd5, "and-int/lit16" },
- [DOP_OR_INT_LIT16] = { 0xd6, "or-int/lit16" },
- [DOP_XOR_INT_LIT16] = { 0xd7, "xor-int/lit16" },
- [DOP_ADD_INT_LIT8] = { 0xd8, "add-int/lit8" },
+ [DOP_MUL_INT_LIT16] = { 0xd2, "mul-int/lit16", dalvik_decomp_instr_arithm_lit },
+ [DOP_DIV_INT_LIT16] = { 0xd3, "div-int/lit16", dalvik_decomp_instr_arithm_lit },
+ [DOP_REM_INT_LIT16] = { 0xd4, "rem-int/lit16", dalvik_decomp_instr_arithm_lit },
+ [DOP_AND_INT_LIT16] = { 0xd5, "and-int/lit16", dalvik_decomp_instr_arithm_lit },
+ [DOP_OR_INT_LIT16] = { 0xd6, "or-int/lit16", dalvik_decomp_instr_arithm_lit },
+ [DOP_XOR_INT_LIT16] = { 0xd7, "xor-int/lit16", dalvik_decomp_instr_arithm_lit },
+ [DOP_ADD_INT_LIT8] = { 0xd8, "add-int/lit8", dalvik_decomp_instr_arithm_lit },
[DOP_RSUB_INT_LIT8] = { 0xd9, "rsub-int/lit8" },
- [DOP_MUL_INT_LIT8] = { 0xda, "mul-int/lit8" },
- [DOP_DIV_INT_LIT8] = { 0xdb, "div-int/lit8" },
- [DOP_REM_INT_LIT8] = { 0xdc, "rem-int/lit8" },
- [DOP_AND_INT_LIT8] = { 0xdd, "and-int/lit8" },
- [DOP_OR_INT_LIT8] = { 0xde, "or-int/lit8" },
- [DOP_XOR_INT_LIT8] = { 0xdf, "xor-int/lit8" }
+ [DOP_MUL_INT_LIT8] = { 0xda, "mul-int/lit8", dalvik_decomp_instr_arithm_lit },
+ [DOP_DIV_INT_LIT8] = { 0xdb, "div-int/lit8", dalvik_decomp_instr_arithm_lit },
+ [DOP_REM_INT_LIT8] = { 0xdc, "rem-int/lit8", dalvik_decomp_instr_arithm_lit },
+ [DOP_AND_INT_LIT8] = { 0xdd, "and-int/lit8", dalvik_decomp_instr_arithm_lit },
+ [DOP_OR_INT_LIT8] = { 0xde, "or-int/lit8", dalvik_decomp_instr_arithm_lit },
+ [DOP_XOR_INT_LIT8] = { 0xdf, "xor-int/lit8", dalvik_decomp_instr_arithm_lit }
};
@@ -237,6 +240,9 @@ static InstructionLinkType dalvik_get_instruction_link(const GDalvikInstruction
/* Indique si l'instruction correspond à un retour de fonction. */
static bool dalvik_instruction_is_return(const GDalvikInstruction *);
+/* Décompile une instruction de la machine virtuelle Dalvik. */
+GDecInstruction *dalvik_instruction_decompile(const GDalvikInstruction *, GDecContext *);
+
/* Indique le type défini pour une instruction d'architecture Dalvik. */
@@ -283,6 +289,7 @@ static void g_dalvik_instruction_init(GDalvikInstruction *instr)
parent->get_text = (get_instruction_text_fc)dalvik_get_instruction_text;
parent->get_link = (get_instruction_link_fc)dalvik_get_instruction_link;
parent->is_return = (is_instruction_return_fc)dalvik_instruction_is_return;
+ parent->decomp = (decomp_instr_fc)dalvik_instruction_decompile;
}
@@ -312,6 +319,25 @@ GArchInstruction *g_dalvik_instruction_new(DalvikOpcodes type)
}
+/******************************************************************************
+* *
+* Paramètres : instr = instruction Dalvik à consulter. *
+* *
+* Description : Indique l'opcode associé à une instruction Dalvik. *
+* *
+* Retour : Identifiant de l'instruction en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+DalvikOpcodes g_dalvik_instruction_get_opcode(const GDalvikInstruction *instr)
+{
+ return instr->type;
+
+}
+
+
/* ---------------------------------------------------------------------------------- */
/* AIDE A LA MISE EN PLACE D'INSTRUCTIONS */
@@ -409,3 +435,31 @@ static bool dalvik_instruction_is_return(const GDalvikInstruction *instr)
return (instr->type == DOP_RETURN_VOID);
}
+
+
+/******************************************************************************
+* *
+* Paramètres : instr = instruction d'origine à convertir. *
+* ctx = contexte de la phase de décompilation. *
+* *
+* Description : Décompile une instruction de la machine virtuelle Dalvik. *
+* *
+* Retour : Instruction mise en place ou NULL. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDecInstruction *dalvik_instruction_decompile(const GDalvikInstruction *instr, GDecContext *ctx)
+{
+ GDecInstruction *result; /* Instruction à retourner */
+
+ if (_instructions[instr->type].decomp != NULL)
+ result = _instructions[instr->type].decomp(G_ARCH_INSTRUCTION(instr), ctx);
+
+ else
+ result = NULL;
+
+ return result;
+
+}
diff --git a/src/arch/dalvik/instruction.h b/src/arch/dalvik/instruction.h
index cc7f845..8eaed17 100644
--- a/src/arch/dalvik/instruction.h
+++ b/src/arch/dalvik/instruction.h
@@ -214,6 +214,9 @@ GType g_dalvik_instruction_get_type(void);
/* Crée une instruction pour l'architecture Dalvik. */
GArchInstruction *g_dalvik_instruction_new(DalvikOpcodes);
+/* Indique l'opcode associé à une instruction Dalvik. */
+DalvikOpcodes g_dalvik_instruction_get_opcode(const GDalvikInstruction *);
+
/* --------------------- AIDE A LA MISE EN PLACE D'INSTRUCTIONS --------------------- */
diff --git a/src/arch/dalvik/translate.h b/src/arch/dalvik/translate.h
new file mode 100644
index 0000000..779c133
--- /dev/null
+++ b/src/arch/dalvik/translate.h
@@ -0,0 +1,56 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * translate.h - prototypes pour les environnements de traduction d'instructions Dalvik
+ *
+ * Copyright (C) 2010 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _ANALYSIS_DECOMP_RTL_DALVIK_TRANSLATE_H
+#define _ANALYSIS_DECOMP_RTL_DALVIK_TRANSLATE_H
+
+
+#include "../translate.h"
+
+
+
+/* Décompile une instruction de type 'aget'. */
+GDecInstruction *dalvik_decomp_instr_aget(const GArchInstruction *, GDecContext *);
+
+/* Décompile une instruction de type 'aput'. */
+GDecInstruction *dalvik_decomp_instr_aput(const GArchInstruction *, GDecContext *);
+
+/* Décompile une instruction de type 'array-length'. */
+GDecInstruction *dalvik_decomp_instr_array_length(const GArchInstruction *, GDecContext *);
+
+/* Décompile une instruction de type 'const'. */
+GDecInstruction *dalvik_decomp_instr_const(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 'opérations arithmétiques'. */
+GDecInstruction *dalvik_decomp_instr_arithm_2addr(const GArchInstruction *, GDecContext *);
+
+/* Décompile une instruction de type 'opérations arithmétiques'. */
+GDecInstruction *dalvik_decomp_instr_arithm_lit(const GArchInstruction *, GDecContext *);
+
+
+
+#endif /* _ANALYSIS_DECOMP_RTL_DALVIK_TRANSLATE_H */
diff --git a/src/arch/immediate.c b/src/arch/immediate.c
index 3018b6b..ec689b8 100644
--- a/src/arch/immediate.c
+++ b/src/arch/immediate.c
@@ -95,6 +95,9 @@ static void g_imm_operand_add_text(const GImmOperand *, GRenderingOptions *, Mai
/* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */
static void g_imm_operand_to_buffer(const GImmOperand *, GBufferLine *, GRenderingOptions *);
+/* Traduit un opérande en version humainement lisible. */
+static void g_imm_operand_print(const GImmOperand *, GBufferLine *, AsmSyntax);
+
/* Indique le type défini pour un opérande de valeur numérique. */
@@ -134,13 +137,18 @@ static void g_imm_operand_class_init(GImmOperandClass *klass)
static void g_imm_operand_init(GImmOperand *operand)
{
- GContentExporter *parent; /* Instance parente */
+ GContentExporter *parent; /* Instance parente #1 */
+ GArchOperand *arch; /* Instance parente #2 */
parent = G_CONTENT_EXPORTER(operand);
parent->add_text = (add_text_fc)g_imm_operand_add_text;
parent->export_buffer = (export_buffer_fc)g_imm_operand_to_buffer;
+ arch = G_ARCH_OPERAND(operand);
+
+ arch->print = (operand_print_fc)g_imm_operand_print;
+
operand->zpad = false;
}
@@ -653,7 +661,52 @@ static size_t g_imm_operand_to_string(const GImmOperand *operand, AsmSyntax synt
}
break;
- default:
+ case ASX_COUNT:
+ switch (operand->size)
+ {
+ case MDS_UNDEFINED:
+ result = snprintf(value, VMPA_MAX_SIZE, "0x???");
+ break;
+
+ case MDS_4_BITS_UNSIGNED:
+ result = snprintf(value, VMPA_MAX_SIZE, "%hhu", operand->unsigned_imm.val8);
+
+ case MDS_8_BITS_UNSIGNED:
+ result = snprintf(value, VMPA_MAX_SIZE, "%hhu", operand->unsigned_imm.val8);
+ break;
+
+ case MDS_16_BITS_UNSIGNED:
+ result = snprintf(value, VMPA_MAX_SIZE, "%hu", operand->unsigned_imm.val16);
+ break;
+
+ case MDS_32_BITS_UNSIGNED:
+ result = snprintf(value, VMPA_MAX_SIZE, "%u", operand->unsigned_imm.val32);
+ break;
+
+ case MDS_64_BITS_UNSIGNED:
+ result = snprintf(value, VMPA_MAX_SIZE, "%llu", operand->unsigned_imm.val64);
+ break;
+
+ case MDS_4_BITS_SIGNED:
+ result = snprintf(value, VMPA_MAX_SIZE, "%hhd", operand->signed_imm.val8);
+ break;
+
+ case MDS_8_BITS_SIGNED:
+ result = snprintf(value, VMPA_MAX_SIZE, "%hhd", operand->signed_imm.val8);
+ break;
+
+ case MDS_16_BITS_SIGNED:
+ result = snprintf(value, VMPA_MAX_SIZE, "%hd", operand->signed_imm.val16);
+ break;
+
+ case MDS_32_BITS_SIGNED:
+ result = snprintf(value, VMPA_MAX_SIZE, "%d", operand->signed_imm.val32);
+ break;
+
+ case MDS_64_BITS_SIGNED:
+ result = snprintf(value, VMPA_MAX_SIZE, "%lld", operand->signed_imm.val64);
+ break;
+ }
break;
}
@@ -706,10 +759,12 @@ static void g_imm_operand_add_text(const GImmOperand *operand, GRenderingOptions
static void g_imm_operand_to_buffer(const GImmOperand *operand, GBufferLine *buffer, GRenderingOptions *options)
{
+ AsmSyntax syntax; /* Choix de l'exportation */
char value[VMPA_MAX_SIZE]; /* Chaîne à imprimer */
size_t len; /* Taille de l'élément inséré */
- len = g_imm_operand_to_string(operand, g_rendering_options_get_syntax(options), value);
+ syntax = (options == NULL ? ASX_COUNT : g_rendering_options_get_syntax(options));
+ len = g_imm_operand_to_string(operand, syntax, value);
g_content_exporter_insert_into_buffer(G_CONTENT_EXPORTER(operand), buffer, BLC_ASSEMBLY,
value, len, RTT_IMMEDIATE);
@@ -720,6 +775,32 @@ static void g_imm_operand_to_buffer(const GImmOperand *operand, GBufferLine *buf
/******************************************************************************
* *
* Paramètres : operand = opérande à traiter. *
+* line = ligne tampon où imprimer l'opérande donné. *
+* syntax = type de représentation demandée. *
+* *
+* Description : Traduit un opérande en version humainement lisible. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_imm_operand_print(const GImmOperand *operand, GBufferLine *line, AsmSyntax syntax)
+{
+ char value[VMPA_MAX_SIZE]; /* Chaîne à imprimer */
+ size_t len; /* Taille de l'élément inséré */
+
+ len = g_imm_operand_to_string(operand, syntax, value);
+
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY, value, len, RTT_IMMEDIATE);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à traiter. *
* addr = valeur résultante. [OUT] *
* *
* Description : Convertit une valeur immédiate en adresse de type vmpa_t. *
diff --git a/src/arch/instruction-int.h b/src/arch/instruction-int.h
index 45a8b2d..2a92bad 100644
--- a/src/arch/instruction-int.h
+++ b/src/arch/instruction-int.h
@@ -1,6 +1,6 @@
/* OpenIDA - Outil d'analyse de fichiers binaires
- * instruction.h - prototypes pour la définition générique interne des instructions
+ * instruction-int.h - prototypes pour la définition générique interne des instructions
*
* Copyright (C) 2008 Cyrille Bagard
*
@@ -27,6 +27,7 @@
#include "archbase.h"
#include "instruction.h"
+#include "translate.h"
#include "../analysis/exporter-int.h"
#include "../common/dllist.h"
@@ -60,6 +61,7 @@ struct _GArchInstruction
get_instruction_text_fc get_text; /* Texte humain équivalent */
get_instruction_link_fc get_link; /* Référence à une instruction */
is_instruction_return_fc is_return; /* Retour de fonction ou pas ? */
+ decomp_instr_fc decomp; /* Procédure de décompilation */
};
diff --git a/src/arch/instruction.c b/src/arch/instruction.c
index b642219..dd43e14 100644
--- a/src/arch/instruction.c
+++ b/src/arch/instruction.c
@@ -306,9 +306,9 @@ size_t g_arch_instruction_count_operands(const GArchInstruction *instr)
* *
******************************************************************************/
-const GArchOperand *g_arch_instruction_get_operand(GArchInstruction *instr, size_t index)
+GArchOperand *g_arch_instruction_get_operand(const GArchInstruction *instr, size_t index)
{
- const GArchOperand *result; /* Opérande à retourner */
+ GArchOperand *result; /* Opérande à retourner */
if (index >= instr->operands_count) result = NULL;
else result = instr->operands[index];
@@ -463,6 +463,33 @@ bool g_arch_instruction_is_return(const GArchInstruction *instr)
}
+/******************************************************************************
+* *
+* Paramètres : instr = instruction d'origine à convertir. *
+* ctx = contexte de la phase de décompilation. *
+* *
+* Description : Décompile une instruction de façon générique. *
+* *
+* Retour : Instruction mise en place ou NULL. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDecInstruction *g_arch_instruction_decompile(const GArchInstruction *instr, GDecContext *ctx)
+{
+ GDecInstruction *result; /* Instruction à retourner */
+
+ if (instr->decomp != NULL)
+ result = instr->decomp(instr, ctx);
+
+ else
+ result = NULL;
+
+ return result;
+
+}
+
/* ---------------------------------------------------------------------------------- */
/* TRAITEMENT DES INSTRUCTIONS PAR ENSEMBLE */
diff --git a/src/arch/instruction.h b/src/arch/instruction.h
index a9e2bd2..4dcba44 100644
--- a/src/arch/instruction.h
+++ b/src/arch/instruction.h
@@ -32,6 +32,8 @@
#include "archbase.h"
#include "operand.h"
+#include "../decomp/context.h"
+#include "../decomp/instruction.h"
#include "../format/executable.h"
@@ -77,7 +79,7 @@ void g_arch_instruction_attach_extra_operand(GArchInstruction *, GArchOperand *)
size_t g_arch_instruction_count_operands(const GArchInstruction *);
/* Fournit un opérande donné d'une instruction. */
-const GArchOperand *g_arch_instruction_get_operand(GArchInstruction *, size_t);
+GArchOperand *g_arch_instruction_get_operand(const GArchInstruction *, size_t);
/* Remplace un opérande d'une instruction par un autre. */
void g_arch_instruction_replace_operand(GArchInstruction *, GArchOperand *, const GArchOperand *);
@@ -94,6 +96,9 @@ InstructionLinkType g_arch_instruction_get_link(const GArchInstruction *, vmpa_t
/* Indique si l'instruction correspond à un retour de fonction. */
bool g_arch_instruction_is_return(const GArchInstruction *instr);
+/* Décompile une instruction de façon générique. */
+GDecInstruction *g_arch_instruction_decompile(const GArchInstruction *, GDecContext *);
+
/* -------------------- TRAITEMENT DES INSTRUCTIONS PAR ENSEMBLE -------------------- */
diff --git a/src/arch/operand-int.h b/src/arch/operand-int.h
index 258a60e..f21b995 100644
--- a/src/arch/operand-int.h
+++ b/src/arch/operand-int.h
@@ -33,6 +33,8 @@
/* Traduit un opérande en version humainement lisible. */
typedef char * (* get_operand_text_fc) (const GArchOperand *, const GExeFormat *, AsmSyntax);
+/* Traduit un opérande en version humainement lisible. */
+typedef void (* operand_print_fc) (const GArchOperand *, GBufferLine *, AsmSyntax);
/* Définition générique d'un opérande d'architecture (instance) */
struct _GArchOperand
@@ -40,6 +42,7 @@ struct _GArchOperand
GContentExporter parent; /* A laisser en premier */
get_operand_text_fc get_text; /* Texte humain équivalent */
+ operand_print_fc print; /* Texte humain équivalent */
};
diff --git a/src/arch/operand.c b/src/arch/operand.c
index d4f6b56..16fc073 100644
--- a/src/arch/operand.c
+++ b/src/arch/operand.c
@@ -96,3 +96,24 @@ char *g_arch_operand_get_text(const GArchOperand *operand, const GExeFormat *for
return operand->get_text(operand, format, syntax);
}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à traiter. *
+* line = ligne tampon où imprimer l'opérande donné. *
+* syntax = type de représentation demandée. *
+* *
+* Description : Traduit un opérande en version humainement lisible. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_arch_operand_print(const GArchOperand *operand, GBufferLine *line, AsmSyntax syntax)
+{
+ return operand->print(operand, line, syntax);
+
+}
diff --git a/src/arch/operand.h b/src/arch/operand.h
index 6d0dc48..3745a80 100644
--- a/src/arch/operand.h
+++ b/src/arch/operand.h
@@ -28,7 +28,8 @@
#include <glib-object.h>
-#include "../format/executable.h"
+#include "../format/executable.h" /* FIXME : remme ! */
+#include "../glibext/gbufferline.h"
@@ -51,6 +52,9 @@ GType g_arch_operand_get_type(void);
/* Traduit un opérande en version humainement lisible. */
char *g_arch_operand_get_text(const GArchOperand *, const GExeFormat *, AsmSyntax);
+/* Traduit un opérande en version humainement lisible. */
+void g_arch_operand_print(const GArchOperand *, GBufferLine *, AsmSyntax);
+
#endif /* _ARCH_OPERAND_H */
diff --git a/src/arch/translate.h b/src/arch/translate.h
new file mode 100644
index 0000000..6811bc3
--- /dev/null
+++ b/src/arch/translate.h
@@ -0,0 +1,39 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * translate.h - prototypes pour les environnements de traduction d'instructions
+ *
+ * Copyright (C) 2010 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _ARCH_TRANSLATE_H
+#define _ARCH_TRANSLATE_H
+
+
+#include "instruction.h"
+#include "../decomp/context.h"
+#include "../decomp/instruction.h"
+
+
+
+/* Décompile une instruction quelconque. */
+typedef GDecInstruction * (* decomp_instr_fc) (const GArchInstruction *, GDecContext *);
+
+
+
+#endif /* _ANALYSIS_DECOMP_RTL_TRANSLATE_H */