summaryrefslogtreecommitdiff
path: root/src/decomp
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2010-12-20 00:28:36 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2010-12-20 00:28:36 (GMT)
commit56deaf395c65658102ef0111cfc072d65335331a (patch)
treeba6d6fd0dbc781e9ad3b3cf6b2eb529a7d7a6aa3 /src/decomp
parentd9fdfcf887a7a596a68db2500bb5e4d0b692abb6 (diff)
Begun to clean the code by moving the disassembling process into disass/.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@202 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/decomp')
-rwxr-xr-xsrc/decomp/lang/Makefile.am1
-rw-r--r--src/decomp/lang/asm.c266
-rw-r--r--src/decomp/lang/asm.h55
-rw-r--r--src/decomp/lang/java.c97
-rw-r--r--src/decomp/output-int.h6
-rw-r--r--src/decomp/output.c84
-rw-r--r--src/decomp/output.h9
7 files changed, 516 insertions, 2 deletions
diff --git a/src/decomp/lang/Makefile.am b/src/decomp/lang/Makefile.am
index 2523bbf..6f5fd59 100755
--- a/src/decomp/lang/Makefile.am
+++ b/src/decomp/lang/Makefile.am
@@ -2,6 +2,7 @@
noinst_LTLIBRARIES = libdecomplang.la
libdecomplang_la_SOURCES = \
+ asm.h asm.c \
java.h java.c
libdecomplang_la_LDFLAGS =
diff --git a/src/decomp/lang/asm.c b/src/decomp/lang/asm.c
new file mode 100644
index 0000000..276d323
--- /dev/null
+++ b/src/decomp/lang/asm.c
@@ -0,0 +1,266 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * asm.c - sorties en langage d'assemblage
+ *
+ * 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 "asm.h"
+
+
+#include "../output-int.h"
+
+
+
+/* Sortie selon le langage d'assemblage (instance) */
+struct _GAsmOutput
+{
+ GLangOutput parent; /* A laisser en premier */
+
+};
+
+
+/* Sortie selon le langage d'assemblage (classe) */
+struct _GAsmOutputClass
+{
+ GLangOutputClass parent; /* A laisser en premier */
+
+};
+
+
+/* Initialise la classe des sorties en langage d'assemblage. */
+static void g_asm_output_class_init(GAsmOutputClass *);
+
+/* Initialise une instance de sortie en langage d'assemblage. */
+static void g_asm_output_init(GAsmOutput *);
+
+/* Ajoute un commentaire à un tampon donné. */
+static GBufferLine *g_asm_output_write_comments(GAsmOutput *, GCodeBuffer *, const char *, size_t);
+
+/* Imprime dans un tampon donné une méthode de comparaison. */
+static void g_asm_output_write_comp_sign(GAsmOutput *, GBufferLine *, CompSignType);
+
+/* Débute la définition d'une routine. */
+static GBufferLine *g_asm_output_start_routine_prototype(GAsmOutput *, GCodeBuffer *, const GOpenidaType *);
+
+/* Termine la définition d'une routine. */
+static void g_asm_output_end_routine_prototype(GAsmOutput *, GCodeBuffer *, GBufferLine *);
+
+
+
+/* Indique le type défini pour une sortie en langage d'assemblage. */
+G_DEFINE_TYPE(GAsmOutput, g_asm_output, G_TYPE_LANG_OUTPUT);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des sorties en langage d'assemblage. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_asm_output_class_init(GAsmOutputClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : output = instance à initialiser. *
+* *
+* Description : Initialise une instance de sortie en langage d'assemblage. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_asm_output_init(GAsmOutput *output)
+{
+ GLangOutput *lang; /* Autre version de l'objet */
+
+ lang = G_LANG_OUTPUT(output);
+
+ lang->cont_comments = (write_comments_fc)g_asm_output_write_comments;
+ lang->write_comments = (write_comments_fc)g_asm_output_write_comments;
+
+ lang->comp_sign = (write_comp_sign_fc)g_asm_output_write_comp_sign;
+
+ lang->start_routine_proto = (rlgbuftp_fc)g_asm_output_start_routine_prototype;
+ lang->end_routine_proto = (lgbufln_fc)g_asm_output_end_routine_prototype;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Crée une nouvelle sortie en langage d'assemblage. *
+* *
+* Retour : Imprimeur créé. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GLangOutput *g_asm_output_new(void)
+{
+ GBufferLine *result; /* Composant à retourner */
+
+ result = g_object_new(G_TYPE_ASM_OUTPUT, NULL);
+
+ return G_LANG_OUTPUT(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : output = encadrant de l'impression en langage de prog. *
+* buffer = tampon de sortie à disposition. *
+* text = texte à insérer dans l'existant. *
+* length = taille du texte à traiter. *
+* *
+* Description : Ajoute un commentaire à un tampon donné. *
+* *
+* Retour : Ligne nouvellement créée. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GBufferLine *g_asm_output_write_comments(GAsmOutput *output, GCodeBuffer *buffer, const char *text, size_t length)
+{
+ GBufferLine *result; /* Adresse nouvelle à remonter */
+
+ result = g_code_buffer_append_new_line(buffer);
+
+ g_buffer_line_insert_text(result, BLC_COMMENTS, "; ", 2, RTT_COMMENT);
+
+ if (length > 0)
+ g_buffer_line_insert_text(result, BLC_COMMENTS, text, length, RTT_COMMENT);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* 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_asm_output_write_comp_sign(GAsmOutput *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. *
+* ret = type de retour de la routine traitée. *
+* *
+* Description : Débute la définition d'une routine. *
+* *
+* Retour : Ligne nouvellement créée. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GBufferLine *g_asm_output_start_routine_prototype(GAsmOutput *output, GCodeBuffer *buffer, const GOpenidaType *ret)
+{
+ GBufferLine *result; /* Adresse nouvelle à remonter */
+
+ result = g_code_buffer_append_new_line(buffer);
+
+ /* TODO */
+ g_buffer_line_insert_text(result, BLC_ASSEMBLY_HEAD, "XXX", 3, RTT_RAW);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : output = encadrant de l'impression en langage de prog. *
+* buffer = tampon de sortie à disposition. *
+* line = ligne contenant le prototype de la routine traitée. *
+* *
+* Description : Termine la définition d'une routine. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+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);
+
+}
diff --git a/src/decomp/lang/asm.h b/src/decomp/lang/asm.h
new file mode 100644
index 0000000..af96a46
--- /dev/null
+++ b/src/decomp/lang/asm.h
@@ -0,0 +1,55 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * asm.h - prototypes pour les sorties en langage d'assemblage
+ *
+ * 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_LANG_ASM_H
+#define _DECOMP_LANG_ASM_H
+
+
+#include "../output.h"
+
+
+
+#define G_TYPE_ASM_OUTPUT g_asm_output_get_type()
+#define G_ASM_OUTPUT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_asm_output_get_type(), GAsmOutput))
+#define G_IS_ASM_OUTPUT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_asm_output_get_type()))
+#define G_ASM_OUTPUT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_ASM_OUTPUT, GAsmOutputClass))
+#define G_IS_ASM_OUTPUT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_ASM_OUTPUT))
+#define G_ASM_OUTPUT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_ASM_OUTPUT, GAsmOutputClass))
+
+
+/* Sortie selon le langage d'assemblage (instance) */
+typedef struct _GAsmOutput GAsmOutput;
+
+/* Sortie selon le langage d'assemblage (classe) */
+typedef struct _GAsmOutputClass GAsmOutputClass;
+
+
+/* Indique le type défini pour une sortie en langage d'assemblage. */
+GType g_asm_output_get_type(void);
+
+/* Crée une nouvelle sortie en langage d'assemblage. */
+GLangOutput *g_asm_output_new(void);
+
+
+
+#endif /* _DECOMP_LANG_ASM_H */
diff --git a/src/decomp/lang/java.c b/src/decomp/lang/java.c
index 90a0ddc..471b63c 100644
--- a/src/decomp/lang/java.c
+++ b/src/decomp/lang/java.c
@@ -50,6 +50,15 @@ static void g_java_output_class_init(GJavaOutputClass *);
/* Initialise une instance de sortie en langage Java. */
static void g_java_output_init(GJavaOutput *);
+/* Marque le début d'une série de commentaires. */
+static GBufferLine *g_java_output_start_comments(GJavaOutput *, GCodeBuffer *);
+
+/* Poursuit l'ajout d'une ligne de commentaires. */
+static GBufferLine *g_java_output_continue_comments(GJavaOutput *, GCodeBuffer *, const char *, size_t);
+
+/* Marque la fin d'une série de commentaires. */
+static GBufferLine *g_java_output_end_comments(GJavaOutput *, GCodeBuffer *);
+
/* Ajoute un commentaire à un tampon donné. */
static GBufferLine *g_java_output_write_comments(GJavaOutput *, GCodeBuffer *, const char *, size_t);
@@ -116,6 +125,10 @@ static void g_java_output_init(GJavaOutput *output)
lang = G_LANG_OUTPUT(output);
+
+ lang->start_comments = (rlgbuf_fc)g_java_output_start_comments;
+ lang->cont_comments = (write_comments_fc)g_java_output_continue_comments;
+ lang->end_comments = (rlgbuf_fc)g_java_output_end_comments;
lang->write_comments = (write_comments_fc)g_java_output_write_comments;
lang->comp_sign = (write_comp_sign_fc)g_java_output_write_comp_sign;
@@ -158,7 +171,89 @@ GLangOutput *g_java_output_new(void)
* *
* Paramètres : output = encadrant de l'impression en langage de prog. *
* buffer = tampon de sortie à disposition. *
-* column = colonne de la ligne visée par l'insertion. *
+* *
+* Description : Marque le début d'une série de commentaires. *
+* *
+* Retour : Nouvelle ligne constituée. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GBufferLine *g_java_output_start_comments(GJavaOutput *output, GCodeBuffer *buffer)
+{
+ GBufferLine *result; /* Nouvelle ligne à retourner */
+
+ result = g_code_buffer_append_new_line(buffer);
+
+ g_buffer_line_insert_text(result, BLC_COMMENTS, "/**", 3, RTT_COMMENT);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : output = encadrant de l'impression en langage de prog. *
+* buffer = tampon de sortie à disposition. *
+* text = texte à insérer dans l'existant. *
+* length = taille du texte à traiter. *
+* *
+* Description : Poursuit l'ajout d'une ligne de commentaires. *
+* *
+* Retour : Ligne nouvellement créée. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GBufferLine *g_java_output_continue_comments(GJavaOutput *output, GCodeBuffer *buffer, const char *text, size_t length)
+{
+ GBufferLine *result; /* Adresse nouvelle à remonter */
+
+ result = g_code_buffer_append_new_line(buffer);
+
+ g_buffer_line_insert_text(result, BLC_COMMENTS, " * ", 3, RTT_COMMENT);
+
+ if (length > 0)
+ g_buffer_line_insert_text(result, BLC_COMMENTS, text, length, RTT_COMMENT);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : output = encadrant de l'impression en langage de prog. *
+* buffer = tampon de sortie à disposition. *
+* *
+* Description : Marque la fin d'une série de commentaires. *
+* *
+* Retour : Nouvelle ligne constituée. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GBufferLine *g_java_output_end_comments(GJavaOutput *output, GCodeBuffer *buffer)
+{
+ GBufferLine *result; /* Nouvelle ligne à retourner */
+
+ result = g_code_buffer_append_new_line(buffer);
+
+ g_buffer_line_insert_text(result, BLC_COMMENTS, " */", 3, RTT_COMMENT);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : output = encadrant de l'impression en langage de prog. *
+* buffer = tampon de sortie à disposition. *
* text = texte à insérer dans l'existant. *
* length = taille du texte à traiter. *
* *
diff --git a/src/decomp/output-int.h b/src/decomp/output-int.h
index 8aae974..885d9ca 100644
--- a/src/decomp/output-int.h
+++ b/src/decomp/output-int.h
@@ -29,6 +29,9 @@
+/* Xxx. */
+typedef GBufferLine * (* rlgbuf_fc) (GLangOutput *, GCodeBuffer *);
+
/* Ajoute un commentaire à un tampon donné. */
typedef GBufferLine * (* write_comments_fc) (GLangOutput *, GCodeBuffer *, const char *, size_t);
@@ -51,6 +54,9 @@ struct _GLangOutput
{
GObject parent; /* A laisser en premier */
+ rlgbuf_fc start_comments; /* Plusieurs commentaires (#1) */
+ write_comments_fc cont_comments; /* Plusieurs commentaires (#2) */
+ rlgbuf_fc end_comments; /* Plusieurs commentaires (#3) */
write_comments_fc write_comments; /* Commentaires sur une ligne */
write_comp_sign_fc comp_sign; /* Méthde de comparaison */
diff --git a/src/decomp/output.c b/src/decomp/output.c
index 16cab19..99d1912 100644
--- a/src/decomp/output.c
+++ b/src/decomp/output.c
@@ -72,7 +72,89 @@ static void g_lang_output_init(GLangOutput *output)
* *
* Paramètres : output = encadrant de l'impression en langage de prog. *
* buffer = tampon de sortie à disposition. *
-* column = colonne de la ligne visée par l'insertion. *
+* *
+* Description : Marque le début d'une série de commentaires. *
+* *
+* Retour : Nouvelle ligne constituée. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GBufferLine *g_lang_output_start_comments(GLangOutput *output, GCodeBuffer *buffer)
+{
+ GBufferLine *result; /* Adresse nouvelle à remonter */
+
+ if (output->start_comments != NULL)
+ result = output->start_comments(output, buffer);
+
+ else result = NULL;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : output = encadrant de l'impression en langage de prog. *
+* buffer = tampon de sortie à disposition. *
+* text = texte à insérer dans l'existant. *
+* length = taille du texte à traiter. *
+* *
+* Description : Poursuit l'ajout d'une ligne de commentaires. *
+* *
+* Retour : Ligne nouvellement créée. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GBufferLine *g_lang_output_continue_comments(GLangOutput *output, GCodeBuffer *buffer, const char *text, size_t length)
+{
+ GBufferLine *result; /* Adresse nouvelle à remonter */
+
+ if (output->cont_comments != NULL)
+ result = output->cont_comments(output, buffer, text, length);
+
+ else result = NULL;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : output = encadrant de l'impression en langage de prog. *
+* buffer = tampon de sortie à disposition. *
+* *
+* Description : Marque la fin d'une série de commentaires. *
+* *
+* Retour : Nouvelle ligne constituée. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GBufferLine *g_lang_output_end_comments(GLangOutput *output, GCodeBuffer *buffer)
+{
+ GBufferLine *result; /* Adresse nouvelle à remonter */
+
+ if (output->end_comments != NULL)
+ result = output->end_comments(output, buffer);
+
+ else result = NULL;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : output = encadrant de l'impression en langage de prog. *
+* buffer = tampon de sortie à disposition. *
* text = texte à insérer dans l'existant. *
* length = taille du texte à traiter. *
* *
diff --git a/src/decomp/output.h b/src/decomp/output.h
index 73e1e76..6a1c4a1 100644
--- a/src/decomp/output.h
+++ b/src/decomp/output.h
@@ -48,6 +48,15 @@ typedef struct _GLangOutputClass GLangOutputClass;
/* Indique le type défini pour une sortie de langage de programmation. */
GType g_lang_output_get_type(void);
+/* Marque le début d'une série de commentaires. */
+GBufferLine *g_lang_output_start_comments(GLangOutput *, GCodeBuffer *);
+
+/* Poursuit l'ajout d'une ligne de commentaires. */
+GBufferLine *g_lang_output_continue_comments(GLangOutput *, GCodeBuffer *, const char *, size_t);
+
+/* Marque la fin d'une série de commentaires. */
+GBufferLine *g_lang_output_end_comments(GLangOutput *, GCodeBuffer *);
+
/* Ajoute un commentaire à un tampon donné. */
GBufferLine *g_lang_output_write_comments(GLangOutput *, GCodeBuffer *, const char *, size_t);