summaryrefslogtreecommitdiff
path: root/src/decomp
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2012-07-23 19:07:29 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2012-07-23 19:07:29 (GMT)
commit8b35a66464636d0c46237af7490a6ca6866ecc4d (patch)
tree92199b36e3af00eb4c175a80c20b9b14511a6a45 /src/decomp
parent8b2189a819c7a761cfdb97d9e3382ea963f225fb (diff)
Improved decompilation of Dalvik bytecode.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@252 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/decomp')
-rw-r--r--src/decomp/context.c43
-rw-r--r--src/decomp/context.h6
-rw-r--r--src/decomp/expr/Makefile.am4
-rw-r--r--src/decomp/expr/access.c159
-rw-r--r--src/decomp/expr/access.h60
-rw-r--r--src/decomp/expr/assign.c38
-rw-r--r--src/decomp/expr/assign.h6
-rw-r--r--src/decomp/expr/call.c60
-rw-r--r--src/decomp/expr/call.h5
-rw-r--r--src/decomp/expr/pseudo.c39
-rw-r--r--src/decomp/expr/pseudo.h4
-rw-r--r--src/decomp/expr/text.c157
-rw-r--r--src/decomp/expr/text.h60
-rw-r--r--src/decomp/instruction-int.h13
-rw-r--r--src/decomp/instruction.c105
-rw-r--r--src/decomp/instruction.h20
-rw-r--r--src/decomp/lang/asm.c4
17 files changed, 765 insertions, 18 deletions
diff --git a/src/decomp/context.c b/src/decomp/context.c
index 6440c56..15215eb 100644
--- a/src/decomp/context.c
+++ b/src/decomp/context.c
@@ -27,6 +27,7 @@
#include <malloc.h>
+#include "instruction-int.h"
#include "expr/pseudo.h"
#include "../arch/operand.h"
#include "../glibext/gnhash.h"
@@ -40,6 +41,8 @@ struct _GDecContext
vmpa_t max; /* Première adresse à écarter */
+ GDecInstruction *list; /* Chaîne décompilée */
+
GHashTable *machine; /* Correspondance reg./pseudo */
GHashTable *ssa; /* Remplacement des pseudos */
@@ -171,6 +174,46 @@ void g_dec_context_set_max_address(GDecContext *ctx, vmpa_t max)
/******************************************************************************
* *
+* Paramètres : ctx = instance à consulter. *
+* *
+* Description : Fournit le premier élément de la liste des instructions. *
+* *
+* Retour : Première instruction décompilée pour le contexte. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDecInstruction *g_dec_context_get_decomp_instrs(const GDecContext *ctx)
+{
+ return ctx->list;
+
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : ctx = instance à mettre à jour. *
+* instr = première instruction décompilée pour le contexte. *
+* *
+* Description : Met à jour le premier élément de la liste des instructions. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_dec_context_set_decomp_instrs(GDecContext *ctx, GDecInstruction *instr)
+{
+ ctx->list = instr;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : ctx = instance à consulter, voire mettre à jour. *
* operand = opérande représentant un registre quelconque. *
* *
diff --git a/src/decomp/context.h b/src/decomp/context.h
index 926a372..b7dd445 100644
--- a/src/decomp/context.h
+++ b/src/decomp/context.h
@@ -61,6 +61,12 @@ vmpa_t g_dec_context_get_max_address(const GDecContext *);
/* Définit l'adresse où la décompilation n'est plus souhaitée. */
void g_dec_context_set_max_address(GDecContext *, vmpa_t);
+/* Fournit le premier élément de la liste des instructions. */
+GDecInstruction *g_dec_context_get_decomp_instrs(const GDecContext *tx);
+
+/* Met à jour le premier élément de la liste des instructions. */
+void g_dec_context_set_decomp_instrs(GDecContext *, GDecInstruction *);
+
/* Convertit un registre machine en un pseudo-registre. */
GDecInstruction *g_dec_context_convert_register(GDecContext *, gpointer);
diff --git a/src/decomp/expr/Makefile.am b/src/decomp/expr/Makefile.am
index 7507593..483a1f3 100644
--- a/src/decomp/expr/Makefile.am
+++ b/src/decomp/expr/Makefile.am
@@ -2,6 +2,7 @@
noinst_LTLIBRARIES = libdecompexpr.la
libdecompexpr_la_SOURCES = \
+ access.h access.c \
arithm.h arithm.c \
array.h array.c \
assign.h assign.c \
@@ -10,7 +11,8 @@ libdecompexpr_la_SOURCES = \
cond.h cond.c \
immediate.h immediate.c \
pseudo.h pseudo.c \
- return.h return.c
+ return.h return.c \
+ text.h text.c
libdecompexpr_la_LDFLAGS =
diff --git a/src/decomp/expr/access.c b/src/decomp/expr/access.c
new file mode 100644
index 0000000..e2cbf19
--- /dev/null
+++ b/src/decomp/expr/access.c
@@ -0,0 +1,159 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * access.c - représentation des accès à des éléments d'entités
+ *
+ * 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 "access.h"
+
+
+#include "../expression-int.h"
+
+
+
+/* Définition d'un accès quelconque (instance) */
+struct _GAccessExpression
+{
+ GDecExpression parent; /* A laisser en premier */
+
+ GDecExpression *owner; /* Destination de l'accessat° */
+ GDecExpression *target; /* Source de l'accessation */
+
+};
+
+
+/* Définition d'un accès quelconque (classe) */
+struct _GAccessExpressionClass
+{
+ GDecExpressionClass parent; /* A laisser en premier */
+
+};
+
+
+
+/* Initialise la classe des accessations quelconques. */
+static void g_access_expression_class_init(GAccessExpressionClass *);
+
+/* Initialise une instance d'accessation quelconque. */
+static void g_access_expression_init(GAccessExpression *);
+
+/* Imprime pour l'écran un version humaine d'une expression. */
+static void g_access_expression_print(const GAccessExpression *, GCodeBuffer *, GBufferLine *, GLangOutput *);
+
+
+
+/* Indique le type défini pour un accès quelconque. */
+G_DEFINE_TYPE(GAccessExpression, g_access_expression, G_TYPE_DEC_EXPRESSION);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des accessations quelconques. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_access_expression_class_init(GAccessExpressionClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : expr = instance à initialiser. *
+* *
+* Description : Initialise une instance d'accessation quelconque. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_access_expression_init(GAccessExpression *expr)
+{
+ GDecInstruction *instr; /* Autre version de l'objet */
+
+ instr = G_DEC_INSTRUCTION(expr);
+
+ instr->print = (dec_instr_print_fc)g_access_expression_print;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : owner = entité qui accueille la cible accédée. *
+* target = élément du propriétaire auquel on accède. *
+* *
+* Description : Représente l'accès à un élément d'une entité. *
+* *
+* Retour : Expression mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDecInstruction *g_access_expression_new(GDecExpression *owner, GDecExpression *target)
+{
+ GAccessExpression *result; /* Expression à retourner */
+
+ result = g_object_new(G_TYPE_ACCESS_EXPRESSION, NULL);
+
+ result->owner = owner;
+ result->target = target;
+
+ 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_access_expression_print(const GAccessExpression *expr, GCodeBuffer *buffer, GBufferLine *line, GLangOutput *output)
+{
+ g_dec_instruction_print(G_DEC_INSTRUCTION(expr->owner),
+ buffer, line, output);
+
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, ".", 3, RTT_PUNCT);
+
+ g_dec_instruction_print(G_DEC_INSTRUCTION(expr->target),
+ buffer, line, output);
+
+}
diff --git a/src/decomp/expr/access.h b/src/decomp/expr/access.h
new file mode 100644
index 0000000..9b4561f
--- /dev/null
+++ b/src/decomp/expr/access.h
@@ -0,0 +1,60 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * access.h - prototypes pour la représentation des accès à des éléments d'entités
+ *
+ * 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_ACCESS_H
+#define _DECOMP_EXPR_ACCESS_H
+
+
+#include <glib-object.h>
+
+
+#include "../expression.h"
+#include "../instruction.h"
+
+
+
+#define G_TYPE_ACCESS_EXPRESSION g_access_expression_get_type()
+#define G_ACCESS_EXPRESSION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_access_expression_get_type(), GAccessExpression))
+#define G_IS_ACCESS_EXPRESSION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_access_expression_get_type()))
+#define G_ACCESS_EXPRESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_ACCESS_EXPRESSION, GAccessExpressionClass))
+#define G_IS_ACCESS_EXPRESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_ACCESS_EXPRESSION))
+#define G_ACCESS_EXPRESSION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_ACCESS_EXPRESSION, GAccessExpressionClass))
+
+
+
+/* Définition d'un accès quelconque (instance) */
+typedef struct _GAccessExpression GAccessExpression;
+
+/* Définition d'un accès quelconque (classe) */
+typedef struct _GAccessExpressionClass GAccessExpressionClass;
+
+
+/* Indique le type défini pour un accès quelconque. */
+GType g_access_expression_get_type(void);
+
+/* Représente l'accès à un élément d'une entité. */
+GDecInstruction *g_access_expression_new(GDecExpression *, GDecExpression *);
+
+
+
+#endif /* _DECOMP_EXPR_ACCESS_H */
diff --git a/src/decomp/expr/assign.c b/src/decomp/expr/assign.c
index 29eb0f8..0843776 100644
--- a/src/decomp/expr/assign.c
+++ b/src/decomp/expr/assign.c
@@ -157,3 +157,41 @@ static void g_assign_expression_print(const GAssignExpression *expr, GCodeBuffer
buffer, line, output);
}
+
+
+/******************************************************************************
+* *
+* Paramètres : assign = expression à consulter. *
+* *
+* Description : Indique la destination d'une assignation. *
+* *
+* Retour : Expression mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDecInstruction *g_assign_expression_get_dest(const GAssignExpression *assign)
+{
+ return assign->dest;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : assign = expression à consulter. *
+* *
+* Description : Indique la source d'une assignation. *
+* *
+* Retour : Expression mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDecInstruction *g_assign_expression_get_src(const GAssignExpression *assign)
+{
+ return assign->src;
+
+}
diff --git a/src/decomp/expr/assign.h b/src/decomp/expr/assign.h
index 87d167e..ce441f6 100644
--- a/src/decomp/expr/assign.h
+++ b/src/decomp/expr/assign.h
@@ -55,6 +55,12 @@ GType g_assign_expression_get_type(void);
/* Assigne le contenu d'une expression dans une autre. */
GDecInstruction *g_assign_expression_new(GDecExpression *, GDecExpression *);
+/* Indique la destination d'une assignation. */
+GDecInstruction *g_assign_expression_get_dest(const GAssignExpression *);
+
+/* Indique la source d'une assignation. */
+GDecInstruction *g_assign_expression_get_src(const GAssignExpression *);
+
#endif /* _DECOMP_EXPR_ASSIGN_H */
diff --git a/src/decomp/expr/call.c b/src/decomp/expr/call.c
index 05e596a..aaf9883 100644
--- a/src/decomp/expr/call.c
+++ b/src/decomp/expr/call.c
@@ -2,7 +2,7 @@
/* OpenIDA - Outil d'analyse de fichiers binaires
* call.c - encadrement des appels de routine
*
- * Copyright (C) 2010 Cyrille Bagard
+ * Copyright (C) 2010-2012 Cyrille Bagard
*
* This file is part of OpenIDA.
*
@@ -24,6 +24,7 @@
#include "call.h"
+#include <malloc.h>
#include <string.h>
@@ -37,7 +38,9 @@ struct _GRoutineCall
GDecExpression parent; /* A laisser en premier */
GBinRoutine *routine; /* Routine sollicitée */
- bool is_object; /* Nature de l'argument n°1 */
+
+ GDecInstruction **args; /* Arguments à associer */
+ size_t count; /* Nombre d'arguments présents */
};
@@ -109,8 +112,7 @@ static void g_routine_call_init(GRoutineCall *expr)
/******************************************************************************
* *
-* Paramètres : routine = routine dont il est fait appel. *
-* is_object = indique la nature du premier argument. *
+* Paramètres : routine = routine dont il est fait appel. *
* *
* Description : Exprime un appel à une routine quelconque. *
* *
@@ -120,14 +122,13 @@ static void g_routine_call_init(GRoutineCall *expr)
* *
******************************************************************************/
-GDecInstruction *g_routine_call_new(GBinRoutine *routine, bool is_object)
+GDecInstruction *g_routine_call_new(GBinRoutine *routine)
{
GRoutineCall *result; /* Expression à retourner */
result = g_object_new(G_TYPE_ROUTINE_CALL, NULL);
result->routine = routine;
- result->is_object = is_object;
return G_DEC_INSTRUCTION(result);
@@ -136,7 +137,7 @@ GDecInstruction *g_routine_call_new(GBinRoutine *routine, bool is_object)
/******************************************************************************
* *
-* Paramètres : expr = expression à transcrire en version humaine. *
+* Paramètres : call = 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. *
@@ -149,15 +150,56 @@ GDecInstruction *g_routine_call_new(GBinRoutine *routine, bool is_object)
* *
******************************************************************************/
-static void g_routine_call_print(const GRoutineCall *expr, GCodeBuffer *buffer, GBufferLine *line, GLangOutput *output)
+static void g_routine_call_print(const GRoutineCall *call, GCodeBuffer *buffer, GBufferLine *line, GLangOutput *output)
{
const char *name; /* Désignation de la routine */
+ size_t i; /* Boucle de parcours */
- name = g_binary_routine_get_name(expr->routine);
+ name = g_binary_routine_get_name(call->routine);
g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, name, strlen(name), RTT_RAW);
g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, "(", 1, RTT_PUNCT);
+ if (call->count > 0)
+ {
+ g_dec_instruction_print(call->args[0], buffer, line, output);
+
+ for (i = 1; i < call->count; i++)
+ {
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, ",", 1, RTT_PUNCT);
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, " ", 1, RTT_RAW);
+
+ g_dec_instruction_print(call->args[i], buffer, line, output);
+
+ }
+
+ }
+
g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, ")", 1, RTT_PUNCT);
}
+
+
+/******************************************************************************
+* *
+* Paramètres : call = expression d'appel à mettre à jour. *
+* arg = nouvel argument à associer à l'appel. *
+* *
+* Description : Enregistre un nouvel argument pour l'appel de routine. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_routine_call_add_arg(GRoutineCall *call, GDecInstruction *arg)
+{
+ call->args = (GDecInstruction **)realloc(call->args,
+ ++call->count * sizeof(GDecInstruction *));
+
+ call->args[call->count - 1] = arg;
+
+ /* TODO : synchroniser avec la routine (cf. constructeurs construits à la volée) */
+
+}
diff --git a/src/decomp/expr/call.h b/src/decomp/expr/call.h
index 7515261..8856166 100644
--- a/src/decomp/expr/call.h
+++ b/src/decomp/expr/call.h
@@ -54,7 +54,10 @@ typedef struct _GRoutineCallClass GRoutineCallClass;
GType g_routine_call_get_type(void);
/* Exprime un appel à une routine quelconque. */
-GDecInstruction *g_routine_call_new(GBinRoutine *, bool);
+GDecInstruction *g_routine_call_new(GBinRoutine *);
+
+/* Enregistre un nouvel argument pour l'appel de routine. */
+void g_routine_call_add_arg(GRoutineCall *, GDecInstruction *);
diff --git a/src/decomp/expr/pseudo.c b/src/decomp/expr/pseudo.c
index 06ba184..bb5861d 100644
--- a/src/decomp/expr/pseudo.c
+++ b/src/decomp/expr/pseudo.c
@@ -24,6 +24,7 @@
#include "pseudo.h"
+#include <malloc.h>
#include <stdio.h>
#include <string.h>
@@ -38,6 +39,7 @@ struct _GPseudoRegister
GDecExpression parent; /* A laisser en premier */
size_t index; /* Position dans l'ensemble */
+ GBinVariable *var; /* Variable plus précise */
};
@@ -148,10 +150,19 @@ GDecInstruction *g_pseudo_register_new(void)
static void g_pseudo_register_print(const GPseudoRegister *reg, GCodeBuffer *buffer, GBufferLine *line, GLangOutput *output)
{
char label[32];
-
- snprintf(label, 32, "var%d", reg->index);
-
- g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, label, strlen(label), RTT_RAW);
+ char *name;
+
+ if (reg->var != NULL)
+ {
+ name = g_binary_variable_to_string(reg->var, true);
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, name, strlen(name), RTT_RAW);
+ free(name);
+ }
+ else
+ {
+ snprintf(label, 32, "var%zu", reg->index);
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, label, strlen(label), RTT_RAW);
+ }
}
@@ -174,3 +185,23 @@ void g_pseudo_register_set_index(GPseudoRegister *reg, size_t index)
reg->index = index;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : reg = expression représentant un pseudo-registre à traiter. *
+* var = indications supplémentaire quant à la variable. *
+* *
+* Description : Précise le nom et le type de la variable. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_pseudo_register_set_variable(GPseudoRegister *reg, GBinVariable *var)
+{
+ reg->var = var;
+
+}
diff --git a/src/decomp/expr/pseudo.h b/src/decomp/expr/pseudo.h
index 95612a9..dce6337 100644
--- a/src/decomp/expr/pseudo.h
+++ b/src/decomp/expr/pseudo.h
@@ -29,6 +29,7 @@
#include "../instruction.h"
+#include "../../analysis/variable.h"
@@ -57,6 +58,9 @@ GDecInstruction *g_pseudo_register_new(void);
/* Définit un indice unique pour un pseudo-registre donné. */
void g_pseudo_register_set_index(GPseudoRegister *, size_t);
+/* Précise le nom et le type de la variable. */
+void g_pseudo_register_set_variable(GPseudoRegister *, GBinVariable *);
+
#endif /* _DECOMP_EXPR_PSEUDO_H */
diff --git a/src/decomp/expr/text.c b/src/decomp/expr/text.c
new file mode 100644
index 0000000..d62e689
--- /dev/null
+++ b/src/decomp/expr/text.c
@@ -0,0 +1,157 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * text.c - raccord avec les opérandes de chaînes de caractères
+ *
+ * Copyright (C) 2012 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 "text.h"
+
+
+#include <string.h>
+
+
+#include "../expression-int.h"
+
+
+
+/* Définition d'une expression de valeur immédiate (instance) */
+struct _GStrExpression
+{
+ GDecExpression parent; /* A laisser en premier */
+
+ char *value; /* Chaîne représentée */
+ size_t len; /* Taille du texte */
+
+};
+
+
+/* Définition d'une expression de valeur immédiate (classe) */
+struct _GStrExpressionClass
+{
+ GDecExpressionClass parent; /* A laisser en premier */
+
+};
+
+
+
+/* Initialise la classe des expressions de valeur immédiate. */
+static void g_str_expression_class_init(GStrExpressionClass *);
+
+/* Initialise une instance d'expression de valeur immédiate. */
+static void g_str_expression_init(GStrExpression *);
+
+/* Imprime pour l'écran un version humaine d'une expression. */
+static void g_str_expression_print(const GStrExpression *, GCodeBuffer *, GBufferLine *, GLangOutput *);
+
+
+
+/* Indique le type défini pour une expression de valeur immédiate. */
+G_DEFINE_TYPE(GStrExpression, g_str_expression, G_TYPE_DEC_EXPRESSION);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des expressions de valeur immédiate. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_str_expression_class_init(GStrExpressionClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : expr = instance à initialiser. *
+* *
+* Description : Initialise une instance d'expression de valeur immédiate. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_str_expression_init(GStrExpression *expr)
+{
+ GDecInstruction *instr; /* Autre version de l'objet */
+
+ instr = G_DEC_INSTRUCTION(expr);
+
+ instr->print = (dec_instr_print_fc)g_str_expression_print;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : value = chaîne de caractères à représenter. *
+* *
+* Description : Construit une expression à partir d'une valeur immédiate. *
+* *
+* Retour : Expression mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDecInstruction *g_str_expression_new(const char *value)
+{
+ GStrExpression *result; /* Expression à retourner */
+
+ result = g_object_new(G_TYPE_STR_EXPRESSION, NULL);
+
+ result->value = strdup(value);
+ result->len = strlen(value);
+
+ 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_str_expression_print(const GStrExpression *expr, GCodeBuffer *buffer, GBufferLine *line, GLangOutput *output)
+{
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, "\"", 1, RTT_STRING);
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, expr->value, expr->len, RTT_STRING);
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, "\"", 1, RTT_STRING);
+
+}
diff --git a/src/decomp/expr/text.h b/src/decomp/expr/text.h
new file mode 100644
index 0000000..9e6df28
--- /dev/null
+++ b/src/decomp/expr/text.h
@@ -0,0 +1,60 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * text.h - prototypes pour le raccord avec les opérandes de chaînes de caractères
+ *
+ * Copyright (C) 2012 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_TEXT_H
+#define _DECOMP_EXPR_TEXT_H
+
+
+#include <glib-object.h>
+
+
+#include "../instruction.h"
+
+
+
+#define G_TYPE_STR_EXPRESSION g_str_expression_get_type()
+#define G_STR_EXPRESSION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_str_expression_get_type(), GStrExpression))
+#define G_IS_STR_EXPRESSION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_str_expression_get_type()))
+#define G_STR_EXPRESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_STR_EXPRESSION, GStrExpressionClass))
+#define G_IS_STR_EXPRESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_STR_EXPRESSION))
+#define G_STR_EXPRESSION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_STR_EXPRESSION, GStrExpressionClass))
+
+
+
+/* Définition d'une expression de valeur immédiate (instance) */
+typedef struct _GStrExpression GStrExpression;
+
+/* Définition d'une expression de valeur immédiate (classe) */
+typedef struct _GStrExpressionClass GStrExpressionClass;
+
+
+
+/* Indique le type défini pour une expression de valeur immédiate. */
+GType g_str_expression_get_type(void);
+
+/*Construit une expression à partir d'une valeur immédiate. */
+GDecInstruction *g_str_expression_new(const char *);
+
+
+
+#endif /* _DECOMP_EXPR_TEXT_H */
diff --git a/src/decomp/instruction-int.h b/src/decomp/instruction-int.h
index 49a68fc..2721b7f 100644
--- a/src/decomp/instruction-int.h
+++ b/src/decomp/instruction-int.h
@@ -2,7 +2,7 @@
/* OpenIDA - Outil d'analyse de fichiers binaires
* instruction-int.h - prototypes pour la définition interne des instructions décompilées
*
- * Copyright (C) 2010 Cyrille Bagard
+ * Copyright (C) 2010-2012 Cyrille Bagard
*
* This file is part of OpenIDA.
*
@@ -27,6 +27,7 @@
#include "instruction.h"
#include "../arch/archbase.h"
+#include "../common/dllist.h"
@@ -39,6 +40,8 @@ struct _GDecInstruction
{
GObject parent; /* A laisser en premier */
+ DL_LIST_ITEM(flow); /* Maillon de liste chaînée */
+
vmpa_t address; /* Position associée */
dec_instr_print_fc print; /* Impression pour à l'écran */
@@ -54,5 +57,13 @@ struct _GDecInstructionClass
};
+#define dinstr_list_last(head) dl_list_last(head, GDecInstruction, flow)
+#define dinstr_list_add_tail(new, head) dl_list_add_tail(new, head, GDecInstruction, flow)
+#define dinstr_list_del(item, head) dl_list_del(item, head, GDecInstruction, flow)
+#define dinstr_list_next_iter(iter, head) dl_list_next_iter(iter, head, GDecInstruction, flow)
+#define dinstr_list_prev_iter(iter, head) dl_list_prev_iter(iter, head, GDecInstruction, flow)
+#define dinstr_list_for_each(pos, head) dl_list_for_each(pos, head, GDecInstruction, flow)
+
+
#endif /* _DECOMP_INSTRUCTION_INT_H */
diff --git a/src/decomp/instruction.c b/src/decomp/instruction.c
index c1afa44..c48ac7b 100644
--- a/src/decomp/instruction.c
+++ b/src/decomp/instruction.c
@@ -72,6 +72,7 @@ static void g_dec_instruction_class_init(GDecInstructionClass *klass)
static void g_dec_instruction_init(GDecInstruction *instr)
{
+ DL_LIST_ITEM_INIT(&instr->flow);
}
@@ -99,3 +100,107 @@ void g_dec_instruction_print(const GDecInstruction *instr, GCodeBuffer *buffer,
instr->print(instr, buffer, line, output);
}
+
+
+/* ---------------------------------------------------------------------------------- */
+/* TRAITEMENT DES INSTRUCTIONS PAR ENSEMBLE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : list = liste d'instructions à consulter. *
+* *
+* Description : Fournit la dernière instruction décompilée de l'ensemble. *
+* *
+* Retour : Instruction en queue de liste. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDecInstruction *g_dec_instruction_get_last(GDecInstruction *list)
+{
+ return dinstr_list_last(list);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : list = liste d'instructions à compléter, ou NULL. *
+* instr = nouvelle instruction à intégrer à l'ensemble. *
+* *
+* Description : Ajoute une instruction à un ensemble existant. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_dec_instruction_add_to_list(GDecInstruction **list, GDecInstruction *instr)
+{
+ dinstr_list_add_tail(instr, list);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : list = liste d'instructions à modifier. *
+* instr = instruction à faire disparaître. *
+* *
+* Description : Supprime une instruction de l'ensemble décompilé. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_dec_instruction_delete(GDecInstruction **list, GDecInstruction *instr)
+{
+ dinstr_list_del(instr, list);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : list = liste d'instructions à consulter. *
+* : iter = position actuelle dans la liste. *
+* *
+* Description : Fournit l'élement suivant un autre pour un parcours. *
+* *
+* Retour : Elément suivant ou NULL si aucun. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDecInstruction *g_dec_instruction_get_next_iter(const GDecInstruction *list, const GDecInstruction *iter)
+{
+ return dinstr_list_next_iter(iter, list);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : list = liste d'instructions à consulter. *
+* : iter = position actuelle dans la liste. *
+* *
+* Description : Fournit l'élement précédant un autre pour un parcours. *
+* *
+* Retour : Elément suivant ou NULL si aucun. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDecInstruction *g_dec_instruction_get_prev_iter(const GDecInstruction *list, const GDecInstruction *iter)
+{
+ return dinstr_list_prev_iter(iter, list);
+
+}
diff --git a/src/decomp/instruction.h b/src/decomp/instruction.h
index 9c8a935..d8fe46c 100644
--- a/src/decomp/instruction.h
+++ b/src/decomp/instruction.h
@@ -56,4 +56,24 @@ void g_dec_instruction_print(const GDecInstruction *, GCodeBuffer *, GBufferLine
+/* -------------------- TRAITEMENT DES INSTRUCTIONS PAR ENSEMBLE -------------------- */
+
+
+/* Fournit la dernière instruction décompilée de l'ensemble. */
+GDecInstruction *g_dec_instruction_get_last(GDecInstruction *);
+
+/* Ajoute une instruction à un ensemble existant. */
+void g_dec_instruction_add_to_list(GDecInstruction **, GDecInstruction *);
+
+/* Supprime une instruction de l'ensemble décompilé. */
+void g_dec_instruction_delete(GDecInstruction **, GDecInstruction *);
+
+/* Fournit l'élement suivant un autre pour un parcours. */
+GDecInstruction *g_dec_instruction_get_next_iter(const GDecInstruction *, const GDecInstruction *);
+
+/* Fournit l'élement précédant un autre pour un parcours. */
+GDecInstruction *g_dec_instruction_get_prev_iter(const GDecInstruction *, const GDecInstruction *);
+
+
+
#endif /* _DECOMP_INSTRUCTION_H */
diff --git a/src/decomp/lang/asm.c b/src/decomp/lang/asm.c
index 9ee8729..ab71cc0 100644
--- a/src/decomp/lang/asm.c
+++ b/src/decomp/lang/asm.c
@@ -238,7 +238,7 @@ static GBufferLine *g_asm_output_start_routine_prototype(GAsmOutput *output, GCo
result = g_code_buffer_append_new_line_fixme(buffer);
/* TODO */
- g_buffer_line_insert_text(result, BLC_ASSEMBLY_HEAD, "XXX", 3, RTT_RAW);
+ g_buffer_line_insert_text(result, BLC_ASSEMBLY_HEAD, "XXX", 3, RTT_COMMENT);
return result;
@@ -261,6 +261,6 @@ static GBufferLine *g_asm_output_start_routine_prototype(GAsmOutput *output, GCo
static void g_asm_output_end_routine_prototype(GAsmOutput *output, GCodeBuffer *buffer, GBufferLine *line)
{
- g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, ";", 1, RTT_PUNCT);
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, ";", 1, RTT_COMMENT);
}