summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog45
-rw-r--r--configure.ac1
-rw-r--r--src/arch/dalvik/Makefile.am1
-rw-r--r--src/arch/dalvik/dop_array.c2
-rw-r--r--src/arch/dalvik/dop_if.c95
-rw-r--r--src/arch/dalvik/instruction.c12
-rw-r--r--src/arch/dalvik/translate.h3
-rwxr-xr-xsrc/decomp/Makefile.am3
-rw-r--r--src/decomp/expr/Makefile.am1
-rw-r--r--src/decomp/expr/cond.c162
-rw-r--r--src/decomp/expr/cond.h60
-rw-r--r--src/decomp/instr/Makefile.am17
-rw-r--r--src/decomp/instr/ite.c182
-rw-r--r--src/decomp/instr/ite.h60
-rw-r--r--src/decomp/lang/java.c53
-rw-r--r--src/decomp/output-int.h5
-rw-r--r--src/decomp/output.c22
-rw-r--r--src/decomp/output.h19
18 files changed, 734 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index f94a726..742948e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,46 @@
+10-12-12 Cyrille Bagard <nocbos@gmail.com>
+
+ * configure.ac:
+ Add the new Makefile 'src/decomp/instr' directoriy to AC_CONFIG_FILES.
+
+ * src/arch/dalvik/dop_array.c:
+ Typo.
+
+ * src/arch/dalvik/dop_if.c:
+ New entry: decompile branch related instructions.
+
+ * src/arch/dalvik/instruction.c:
+ Update opcodes list for decompilation.
+
+ * src/arch/dalvik/Makefile.am:
+ Add dop_if.c to libarchdalvik_la_SOURCES.
+
+ * src/arch/dalvik/translate.h:
+ Update code.
+
+ * src/decomp/expr/cond.c:
+ * src/decomp/expr/cond.h:
+ New entries: create an expression for conditions.
+
+ * src/decomp/expr/Makefile.am:
+ Add cond.[ch] to libdecompexpr_la_SOURCES.
+
+ * src/decomp/instr/ite.c:
+ * src/decomp/instr/ite.h:
+ * src/decomp/instr/Makefile.am:
+ New entries: create an instruction for the 'If Then Else' blocks.
+
+ * src/decomp/lang/java.c:
+ Output condition signs.
+
+ * src/decomp/Makefile.am:
+ Add instr/libdecompinstr.la to libdecomp_la_LIBADD and instr to SUBDIRS.
+
+ * src/decomp/output.c:
+ * src/decomp/output.h:
+ * src/decomp/output-int.h:
+ Output condition signs.
+
10-12-09 Cyrille Bagard <nocbos@gmail.com>
* configure.ac:
@@ -39,7 +82,7 @@
Update code.
* src/arch/dalvik/Makefile.am:
- Add dop_ret to libarchdalvik_la_SOURCES.
+ Add dop_ret.c to libarchdalvik_la_SOURCES.
* src/arch/dalvik/translate.h:
Extend the list of translation routines.
diff --git a/configure.ac b/configure.ac
index 4259d55..f456684 100644
--- a/configure.ac
+++ b/configure.ac
@@ -255,6 +255,7 @@ AC_CONFIG_FILES([Makefile
src/decomp/Makefile
src/decomp/expr/Makefile
src/decomp/expr/dalvik/Makefile
+ src/decomp/instr/Makefile
src/decomp/lang/Makefile
src/dialogs/Makefile
src/format/Makefile
diff --git a/src/arch/dalvik/Makefile.am b/src/arch/dalvik/Makefile.am
index 3c58a0e..fbd041d 100644
--- a/src/arch/dalvik/Makefile.am
+++ b/src/arch/dalvik/Makefile.am
@@ -8,6 +8,7 @@ libarchdalvik_la_SOURCES = \
dop_arithm.c \
dop_array.c \
dop_const.c \
+ dop_if.c \
dop_invoke.c \
dop_ret.c \
op_add.c \
diff --git a/src/arch/dalvik/dop_array.c b/src/arch/dalvik/dop_array.c
index fa9f94f..94ca09a 100644
--- a/src/arch/dalvik/dop_array.c
+++ b/src/arch/dalvik/dop_array.c
@@ -34,7 +34,7 @@
* Paramètres : instr = instruction d'origine à convertir. *
* ctx = contexte de la phase de décompilation. *
* *
-* Description : Décompile une instruction de type 'array-length'. *
+* Description : Décompile une instruction de type 'array-length'. *
* *
* Retour : Instruction mise en place ou NULL. *
* *
diff --git a/src/arch/dalvik/dop_if.c b/src/arch/dalvik/dop_if.c
new file mode 100644
index 0000000..3a9d8dd
--- /dev/null
+++ b/src/arch/dalvik/dop_if.c
@@ -0,0 +1,95 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * dop_array.c - décompilation des branchements conditionnels
+ *
+ * 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/cond.h"
+#include "../../decomp/instr/ite.h"
+
+
+
+/******************************************************************************
+* *
+* 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(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);
+
+ operand = g_arch_instruction_get_operand(instr, 1);
+ op2 = g_dec_context_convert_register(ctx, 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/instruction.c b/src/arch/dalvik/instruction.c
index d23bbe5..051bbe2 100644
--- a/src/arch/dalvik/instruction.c
+++ b/src/arch/dalvik/instruction.c
@@ -110,12 +110,12 @@ static dalvik_instruction _instructions[DOP_COUNT] = {
[DOP_CMPL_DOUBLE] = { 0x2f, "cmpl-double" },
[DOP_CMPG_DOUBLE] = { 0x30, "cmpg-double" },
[DOP_CMP_LONG] = { 0x31, "cmp-long" },
- [DOP_IF_EQ] = { 0x32, "if-eq" },
- [DOP_IF_NE] = { 0x33, "if-ne" },
- [DOP_IF_LT] = { 0x34, "if-lt" },
- [DOP_IF_GE] = { 0x35, "if-ge" },
- [DOP_IF_GT] = { 0x36, "if-gt" },
- [DOP_IF_LE] = { 0x37, "if-le" },
+ [DOP_IF_EQ] = { 0x32, "if-eq", dalvik_decomp_instr_if },
+ [DOP_IF_NE] = { 0x33, "if-ne", dalvik_decomp_instr_if },
+ [DOP_IF_LT] = { 0x34, "if-lt", dalvik_decomp_instr_if },
+ [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" },
diff --git a/src/arch/dalvik/translate.h b/src/arch/dalvik/translate.h
index 350dff8..c708aaf 100644
--- a/src/arch/dalvik/translate.h
+++ b/src/arch/dalvik/translate.h
@@ -60,6 +60,9 @@ GDecInstruction *dalvik_decomp_instr_arithm_2addr(const GArchInstruction *, GDec
/* Décompile une instruction de type 'opérations arithmétiques'. */
GDecInstruction *dalvik_decomp_instr_arithm_lit(const GArchInstruction *, GDecContext *);
+/* Décompile une instruction de comparaison d'opérandes. */
+GDecInstruction *dalvik_decomp_instr_if(const GArchInstruction *, GDecContext *);
+
#endif /* _ANALYSIS_DECOMP_RTL_DALVIK_TRANSLATE_H */
diff --git a/src/decomp/Makefile.am b/src/decomp/Makefile.am
index 20694d0..ccae8ad 100755
--- a/src/decomp/Makefile.am
+++ b/src/decomp/Makefile.am
@@ -12,6 +12,7 @@ libdecomp_la_SOURCES = \
libdecomp_la_LIBADD = \
expr/libdecompexpr.la \
+ instr/libdecompinstr.la \
lang/libdecomplang.la
libdecomp_la_LDFLAGS =
@@ -23,4 +24,4 @@ AM_CPPFLAGS =
AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
-SUBDIRS = expr lang
+SUBDIRS = expr instr lang
diff --git a/src/decomp/expr/Makefile.am b/src/decomp/expr/Makefile.am
index d6d6d04..7507593 100644
--- a/src/decomp/expr/Makefile.am
+++ b/src/decomp/expr/Makefile.am
@@ -7,6 +7,7 @@ libdecompexpr_la_SOURCES = \
assign.h assign.c \
block.h block.c \
call.h call.c \
+ cond.h cond.c \
immediate.h immediate.c \
pseudo.h pseudo.c \
return.h return.c
diff --git a/src/decomp/expr/cond.c b/src/decomp/expr/cond.c
new file mode 100644
index 0000000..51309ca
--- /dev/null
+++ b/src/decomp/expr/cond.c
@@ -0,0 +1,162 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * cond.c - représentation des conditions
+ *
+ * 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 "cond.h"
+
+
+#include "../expression-int.h"
+
+
+
+/* Définition d'une condition binaire quelconque (instance) */
+struct _GCondExpression
+{
+ GDecExpression parent; /* A laisser en premier */
+
+ GDecExpression *a; /* Premier élément à comparer */
+ CompSignType sign; /* Méthode de comparaison */
+ GDecExpression *b; /* Second élément à comparer */
+
+};
+
+
+/* Définition d'une condition binaire quelconque (classe) */
+struct _GCondExpressionClass
+{
+ GDecExpressionClass parent; /* A laisser en premier */
+
+};
+
+
+
+/* Initialise la classe des conditions binaires quelconques. */
+static void g_cond_expression_class_init(GCondExpressionClass *);
+
+/* Initialise une instance de condition binaire quelconque. */
+static void g_cond_expression_init(GCondExpression *);
+
+/* Imprime pour l'écran un version humaine d'une expression. */
+static void g_cond_expression_print(const GCondExpression *, GCodeBuffer *, GBufferLine *, GLangOutput *);
+
+
+
+/* Indique le type défini pour une condition binaire quelconque. */
+G_DEFINE_TYPE(GCondExpression, g_cond_expression, G_TYPE_DEC_EXPRESSION);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des conditions binaires quelconques. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_cond_expression_class_init(GCondExpressionClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : expr = instance à initialiser. *
+* *
+* Description : Initialise une instance de condition binaire quelconque. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_cond_expression_init(GCondExpression *expr)
+{
+ GDecInstruction *instr; /* Autre version de l'objet */
+
+ instr = G_DEC_INSTRUCTION(expr);
+
+ instr->print = (dec_instr_print_fc)g_cond_expression_print;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : a = second élément à comparer. *
+* sign = choix de la méthode de comparaison. *
+* b = second élément à comparer. *
+* *
+* Description : Exprime une condition binaire quelconque. *
+* *
+* Retour : Expression mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDecInstruction *g_cond_expression_new(GDecExpression *a, CompSignType sign, GDecExpression *b)
+{
+ GCondExpression *result; /* Expression à retourner */
+
+ result = g_object_new(G_TYPE_COND_EXPRESSION, NULL);
+
+ result->a = a;
+ result->sign = sign;
+ result->b = b;
+
+ return G_DEC_INSTRUCTION(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : expr = expression à transcrire en version humaine. *
+* buffer = tampon où doit se réaliser l'insertion. *
+* line = ligne d'impression prête à emploi ou NULL. *
+* output = langage de programmation de sortie. *
+* *
+* Description : Imprime pour l'écran un version humaine d'une expression. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_cond_expression_print(const GCondExpression *expr, GCodeBuffer *buffer, GBufferLine *line, GLangOutput *output)
+{
+ g_dec_instruction_print(G_DEC_INSTRUCTION(expr->a),
+ buffer, line, output);
+
+ g_lang_output_write_comp_sign(output, line, expr->sign);
+
+ g_dec_instruction_print(G_DEC_INSTRUCTION(expr->b),
+ buffer, line, output);
+
+}
diff --git a/src/decomp/expr/cond.h b/src/decomp/expr/cond.h
new file mode 100644
index 0000000..b6fd073
--- /dev/null
+++ b/src/decomp/expr/cond.h
@@ -0,0 +1,60 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * cond.h - prototypes pour la représentation des conditions
+ *
+ * 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 _DECOMP_EXPR_COND_H
+#define _DECOMP_EXPR_COND_H
+
+
+#include <glib-object.h>
+
+
+#include "../expression.h"
+#include "../instruction.h"
+
+
+
+#define G_TYPE_COND_EXPRESSION g_cond_expression_get_type()
+#define G_COND_EXPRESSION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_cond_expression_get_type(), GCondExpression))
+#define G_IS_COND_EXPRESSION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_cond_expression_get_type()))
+#define G_COND_EXPRESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_COND_EXPRESSION, GCondExpressionClass))
+#define G_IS_COND_EXPRESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_COND_EXPRESSION))
+#define G_COND_EXPRESSION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_COND_EXPRESSION, GCondExpressionClass))
+
+
+
+/* Définition d'une condition binaire quelconque (instance) */
+typedef struct _GCondExpression GCondExpression;
+
+/* Définition d'une condition binaire quelconque (classe) */
+typedef struct _GCondExpressionClass GCondExpressionClass;
+
+
+/* Indique le type défini pour une condition binaire quelconque. */
+GType g_cond_expression_get_type(void);
+
+/* Exprime une condition binaire quelconque. */
+GDecInstruction *g_cond_expression_new(GDecExpression *, CompSignType, GDecExpression *);
+
+
+
+#endif /* _DECOMP_EXPR_COND_H */
diff --git a/src/decomp/instr/Makefile.am b/src/decomp/instr/Makefile.am
new file mode 100644
index 0000000..b4e16eb
--- /dev/null
+++ b/src/decomp/instr/Makefile.am
@@ -0,0 +1,17 @@
+
+noinst_LTLIBRARIES = libdecompinstr.la
+
+libdecompinstr_la_SOURCES = \
+ ite.h ite.c
+
+libdecompinstr_la_LDFLAGS =
+
+libdecompinstr_la_LIBADD =
+
+INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS)
+
+AM_CPPFLAGS =
+
+AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
+
+SUBDIRS =
diff --git a/src/decomp/instr/ite.c b/src/decomp/instr/ite.c
new file mode 100644
index 0000000..f08df1e
--- /dev/null
+++ b/src/decomp/instr/ite.c
@@ -0,0 +1,182 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * cond.c - représentation des conditions
+ *
+ * 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 "ite.h"
+
+
+#include "../instruction-int.h"
+
+
+
+/* Définition d'un aiguillage du flux d'exécution (instance) */
+struct _GITEInstruction
+{
+ GDecInstruction parent; /* A laisser en premier */
+
+ GDecExpression *cond; /* Condition prise en compte */
+
+ union
+ {
+ vmpa_t addr; /* Adresse de saut */
+ GDecExpression *expr; /* Expressions équivalentes */
+
+ } if_true;
+
+ union
+ {
+ vmpa_t addr; /* Adresse de saut */
+ GDecExpression *expr; /* Expressions équivalentes */
+
+ } if_false;
+
+};
+
+
+/* Définition d'un aiguillage du flux d'exécution (classe) */
+struct _GITEInstructionClass
+{
+ GDecInstructionClass parent; /* A laisser en premier */
+
+};
+
+
+
+/* Initialise la classe des aiguillages de flux d'exécution. */
+static void g_ite_instruction_class_init(GITEInstructionClass *);
+
+/* Initialise une instance d'aiguillage du flux d'exécution. */
+static void g_ite_instruction_init(GITEInstruction *);
+
+/* Imprime pour l'écran un version humaine d'une instruction. */
+static void g_ite_instruction_print(const GITEInstruction *, GCodeBuffer *, GBufferLine *, GLangOutput *);
+
+
+
+/* Indique le type défini pour un aiguillage du flux d'exécution. */
+G_DEFINE_TYPE(GITEInstruction, g_ite_instruction, G_TYPE_DEC_INSTRUCTION);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des aiguillages de flux d'exécution. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_ite_instruction_class_init(GITEInstructionClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : expr = instance à initialiser. *
+* *
+* Description : Initialise une instance d'aiguillage du flux d'exécution. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_ite_instruction_init(GITEInstruction *expr)
+{
+ GDecInstruction *instr; /* Autre version de l'objet */
+
+ instr = G_DEC_INSTRUCTION(expr);
+
+ instr->print = (dec_instr_print_fc)g_ite_instruction_print;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : cond = expression fixant le choix de l'aiguillage. *
+* if_true = adresse du saut si la condition est vérifiée. *
+* if_true = adresse du saut si la condition n'est pas vérifiée.*
+* *
+* Description : Exprime un aiguillage du flux en fonction d'une condition. *
+* *
+* Retour : Expression mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDecInstruction *g_ite_instruction_new(GDecExpression *cond, vmpa_t if_true, vmpa_t if_false)
+{
+ GITEInstruction *result; /* Expression à retourner */
+
+ result = g_object_new(G_TYPE_ITE_INSTRUCTION, NULL);
+
+ result->cond = cond;
+ result->if_true.addr = if_true;
+ result->if_false.addr = if_false;
+
+ return G_DEC_INSTRUCTION(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : expr = instruction à transcrire en version humaine. *
+* buffer = tampon où doit se réaliser l'insertion. *
+* line = ligne d'impression prête à emploi ou NULL. *
+* output = langage de programmation de sortie. *
+* *
+* Description : Imprime pour l'écran un version humaine d'une instruction. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_ite_instruction_print(const GITEInstruction *expr, GCodeBuffer *buffer, GBufferLine *line, GLangOutput *output)
+{
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, "if ", 3, RTT_KEY_WORD);
+
+ g_dec_instruction_print(G_DEC_INSTRUCTION(expr->cond),
+ buffer, line, output);
+
+ /*
+ g_dec_instruction_print(G_DEC_INSTRUCTION(expr->dest),
+ buffer, line, output);
+
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, " = ", 3, RTT_SIGNS);
+
+ g_dec_instruction_print(G_DEC_INSTRUCTION(expr->src),
+ buffer, line, output);
+ */
+
+
+}
diff --git a/src/decomp/instr/ite.h b/src/decomp/instr/ite.h
new file mode 100644
index 0000000..cff073a
--- /dev/null
+++ b/src/decomp/instr/ite.h
@@ -0,0 +1,60 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * ite.h - prototypes pour la représentation des conditions
+ *
+ * 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 _DECOMP_EXPR_ITE_H
+#define _DECOMP_EXPR_ITE_H
+
+
+#include <glib-object.h>
+
+
+#include "../expression.h"
+#include "../instruction.h"
+
+
+
+#define G_TYPE_ITE_INSTRUCTION g_ite_instruction_get_type()
+#define G_ITE_INSTRUCTION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_ite_instruction_get_type(), GITEInstruction))
+#define G_IS_ITE_INSTRUCTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_ite_instruction_get_type()))
+#define G_ITE_INSTRUCTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_ITE_INSTRUCTION, GITEInstructionClass))
+#define G_IS_ITE_INSTRUCTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_ITE_INSTRUCTION))
+#define G_ITE_INSTRUCTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_ITE_INSTRUCTION, GITEInstructionClass))
+
+
+
+/* Définition d'un aiguillage du flux d'exécution (instance) */
+typedef struct _GITEInstruction GITEInstruction;
+
+/* Définition d'un aiguillage du flux d'exécution (classe) */
+typedef struct _GITEInstructionClass GITEInstructionClass;
+
+
+/* Indique le type défini pour un aiguillage du flux d'exécution. */
+GType g_ite_instruction_get_type(void);
+
+/* Exprime un aiguillage du flux en fonction d'une condition. */
+GDecInstruction *g_ite_instruction_new(GDecExpression *, vmpa_t, vmpa_t);
+
+
+
+#endif /* _DECOMP_EXPR_ITE_H */
diff --git a/src/decomp/lang/java.c b/src/decomp/lang/java.c
index b934a62..90a0ddc 100644
--- a/src/decomp/lang/java.c
+++ b/src/decomp/lang/java.c
@@ -53,6 +53,9 @@ static void g_java_output_init(GJavaOutput *);
/* Ajoute un commentaire à un tampon donné. */
static GBufferLine *g_java_output_write_comments(GJavaOutput *, GCodeBuffer *, const char *, size_t);
+/* Imprime dans un tampon donné une méthode de comparaison. */
+static void g_java_output_write_comp_sign(GJavaOutput *, GBufferLine *, CompSignType);
+
/* Débute la définition d'une classe. */
static GBufferLine *g_java_output_start_class(GJavaOutput *, GCodeBuffer *, const GOpenidaType *);
@@ -115,6 +118,8 @@ static void g_java_output_init(GJavaOutput *output)
lang->write_comments = (write_comments_fc)g_java_output_write_comments;
+ lang->comp_sign = (write_comp_sign_fc)g_java_output_write_comp_sign;
+
lang->start_class = (rlgbuftp_fc)g_java_output_start_class;
lang->end_class = (lgbuf_fc)g_java_output_end_class;
@@ -184,6 +189,54 @@ static GBufferLine *g_java_output_write_comments(GJavaOutput *output, GCodeBuffe
/******************************************************************************
* *
* Paramètres : output = encadrant de l'impression en langage de prog. *
+* line = tampon de sortie à disposition. *
+* sign = méthode de comparaison à imprimer. *
+* *
+* Description : Imprime dans un tampon donné une méthode de comparaison. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_java_output_write_comp_sign(GJavaOutput *output, GBufferLine *line, CompSignType sign)
+{
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, " ", 1, RTT_RAW);
+
+ switch (sign)
+ {
+ case CST_EQ:
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, "==", 2, RTT_SIGNS);
+ break;
+ case CST_NE:
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, "!=", 2, RTT_SIGNS);
+ break;
+ case CST_LT:
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, "<", 1, RTT_SIGNS);
+ break;
+ case CST_GE:
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, ">=", 2, RTT_SIGNS);
+ break;
+ case CST_GT:
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, ">", 1, RTT_SIGNS);
+ break;
+ case CST_LE:
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, "<=", 2, RTT_SIGNS);
+ break;
+ default:
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, "?", 1, RTT_SIGNS);
+ break;
+ }
+
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, " ", 1, RTT_RAW);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : output = encadrant de l'impression en langage de prog. *
* buffer = tampon de sortie à disposition. *
* type = désignation de la classe à définir. *
* *
diff --git a/src/decomp/output-int.h b/src/decomp/output-int.h
index 0d22aa5..8aae974 100644
--- a/src/decomp/output-int.h
+++ b/src/decomp/output-int.h
@@ -32,6 +32,9 @@
/* Ajoute un commentaire à un tampon donné. */
typedef GBufferLine * (* write_comments_fc) (GLangOutput *, GCodeBuffer *, const char *, size_t);
+/* Imprime dans un tampon donné une méthode de comparaison. */
+typedef void (* write_comp_sign_fc) (GLangOutput *, GBufferLine *, CompSignType);
+
/* Xxx. */
typedef GBufferLine * (* rlgbuftp_fc) (GLangOutput *, GCodeBuffer *, const GOpenidaType *);
@@ -50,6 +53,8 @@ struct _GLangOutput
write_comments_fc write_comments; /* Commentaires sur une ligne */
+ write_comp_sign_fc comp_sign; /* Méthde de comparaison */
+
rlgbuftp_fc start_class; /* Début de définition */
lgbuf_fc end_class; /* Fin de définition de classe */
diff --git a/src/decomp/output.c b/src/decomp/output.c
index 066096e..16cab19 100644
--- a/src/decomp/output.c
+++ b/src/decomp/output.c
@@ -101,6 +101,28 @@ GBufferLine *g_lang_output_write_comments(GLangOutput *output, GCodeBuffer *buff
/******************************************************************************
* *
* Paramètres : output = encadrant de l'impression en langage de prog. *
+* line = tampon de sortie à disposition. *
+* sign = méthode de comparaison à imprimer. *
+* *
+* Description : Imprime dans un tampon donné une méthode de comparaison. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_lang_output_write_comp_sign(GLangOutput *output, GBufferLine *line, CompSignType sign)
+{
+ if (output->comp_sign != NULL)
+ output->comp_sign(output, line, sign);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : output = encadrant de l'impression en langage de prog. *
* buffer = tampon de sortie à disposition. *
* type = désignation de la classe à définir. *
* *
diff --git a/src/decomp/output.h b/src/decomp/output.h
index a4f72b2..73e1e76 100644
--- a/src/decomp/output.h
+++ b/src/decomp/output.h
@@ -51,6 +51,25 @@ GType g_lang_output_get_type(void);
/* Ajoute un commentaire à un tampon donné. */
GBufferLine *g_lang_output_write_comments(GLangOutput *, GCodeBuffer *, const char *, size_t);
+
+/* Liste des signes binaires de comparaison */
+typedef enum _CompSignType
+{
+ CST_EQ, /* == */
+ CST_NE, /* != */
+ CST_LT, /* < */
+ CST_GE, /* >= */
+ CST_GT, /* > */
+ CST_LE, /* <= */
+
+ CST_COUNT
+
+} CompSignType;
+
+/* Imprime dans un tampon donné une méthode de comparaison. */
+void g_lang_output_write_comp_sign(GLangOutput *, GBufferLine *, CompSignType);
+
+
/* Débute la définition d'une classe. */
GBufferLine *g_lang_output_start_class(GLangOutput *, GCodeBuffer *, const GOpenidaType *);