summaryrefslogtreecommitdiff
path: root/src/analysis
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2012-08-12 23:32:21 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2012-08-12 23:32:21 (GMT)
commit9cfe738c2e9bb49eb2872e92bc4422c548edb517 (patch)
treeee8dbe5965b9d46394395b8beee87676e098a9f1 /src/analysis
parentfc49e98dc2b3e0ae08a5874ecacaef046a0f3ec1 (diff)
Cleaned the code and handled file binaries properly.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@259 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/analysis')
-rwxr-xr-xsrc/analysis/Makefile.am3
-rwxr-xr-xsrc/analysis/binaries/Makefile.am18
-rw-r--r--src/analysis/binaries/file.c328
-rw-r--r--src/analysis/binaries/file.h61
-rw-r--r--src/analysis/binary-int.h84
-rw-r--r--src/analysis/binary.c728
-rw-r--r--src/analysis/binary.h74
-rw-r--r--src/analysis/decomp/decompiler.c10
-rw-r--r--src/analysis/decomp/decompiler.h2
-rw-r--r--src/analysis/disass/disassembler.c14
-rw-r--r--src/analysis/disass/disassembler.h2
-rw-r--r--src/analysis/disass/fetch.c6
-rw-r--r--src/analysis/disass/fetch.h2
13 files changed, 689 insertions, 643 deletions
diff --git a/src/analysis/Makefile.am b/src/analysis/Makefile.am
index e59b648..b5b345f 100755
--- a/src/analysis/Makefile.am
+++ b/src/analysis/Makefile.am
@@ -16,6 +16,7 @@ libanalysis_la_SOURCES = \
variable.h variable.c
libanalysis_la_LIBADD = \
+ binaries/libanalysisbinaries.la \
decomp/libanalysisdecomp.la \
disass/libanalysisdisass.la
@@ -28,4 +29,4 @@ AM_CPPFLAGS =
AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
-SUBDIRS = decomp disass
+SUBDIRS = binaries decomp disass
diff --git a/src/analysis/binaries/Makefile.am b/src/analysis/binaries/Makefile.am
new file mode 100755
index 0000000..f065070
--- /dev/null
+++ b/src/analysis/binaries/Makefile.am
@@ -0,0 +1,18 @@
+
+noinst_LTLIBRARIES = libanalysisbinaries.la
+
+libanalysisbinaries_la_SOURCES = \
+ file.h file.c
+
+libanalysisbinaries_la_LIBADD =
+
+libanalysisbinaries_la_LDFLAGS =
+
+
+INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS)
+
+AM_CPPFLAGS =
+
+AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
+
+SUBDIRS =
diff --git a/src/analysis/binaries/file.c b/src/analysis/binaries/file.c
new file mode 100644
index 0000000..0be1fd7
--- /dev/null
+++ b/src/analysis/binaries/file.c
@@ -0,0 +1,328 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * file.h - prototypes pour la prise en charge des binaires sous forme de fichier
+ *
+ * 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 "file.h"
+
+
+#include <string.h>
+
+
+#include "../binary-int.h"
+#include "../../common/extstr.h"
+#include "../../gui/panels/log.h"
+
+
+
+/* Description de fichier binaire (instance) */
+struct _GFileBinary
+{
+ GLoadedBinary parent; /* A laisser en premier */
+
+ char *filename; /* Fichier chargé en mémoire */
+
+};
+
+/* Description de fichier binaire (classe) */
+struct _GFileBinaryClass
+{
+ GLoadedBinaryClass parent; /* A laisser en premier */
+
+};
+
+
+/* Initialise la classe des descriptions de fichier binaire. */
+static void g_file_binary_class_init(GFileBinaryClass *);
+
+/* Initialise une description de fichier binaire. */
+static void g_file_binary_init(GFileBinary *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_file_binary_finalize(GFileBinary *);
+
+/* Ecrit une sauvegarde du binaire dans un fichier XML. */
+static bool g_file_binary_save(const GFileBinary *, xmlDocPtr, xmlXPathContextPtr, const char *);
+
+/* Fournit le fichier correspondant à l'élément binaire. */
+static const char *g_file_binary_get_filename(const GFileBinary *, bool);
+
+
+
+/* Indique le type défini pour une description de fichier binaire. */
+G_DEFINE_TYPE(GFileBinary, g_file_binary, G_TYPE_LOADED_BINARY);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des descriptions de fichier binaire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_file_binary_class_init(GFileBinaryClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->finalize = (GObjectFinalizeFunc)g_file_binary_finalize;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = instance à initialiser. *
+* *
+* Description : Initialise une description de fichier binaire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_file_binary_init(GFileBinary *binary)
+{
+ GLoadedBinary *loaded; /* Version parente */
+
+ loaded = G_LOADED_BINARY(binary);
+
+ loaded->save = (save_binary_fc)g_file_binary_save;
+ loaded->get_filename = (get_binary_filename_fc)g_file_binary_get_filename;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_file_binary_finalize(GFileBinary *binary)
+{
+ gpointer obj_class; /* Classe parente */
+
+ free(binary->filename);
+
+ /* On passe le relai */
+
+ obj_class = g_type_class_peek_parent(G_FILE_BINARY_GET_CLASS(binary));
+
+ G_OBJECT_CLASS(obj_class)->finalize(G_OBJECT(binary));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : filename = nom du fichier à charger. *
+* *
+* Description : Charge en mémoire le contenu d'un fichier. *
+* *
+* Retour : Adresse de la représentation ou NULL en cas d'échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GLoadedBinary *g_file_binary_new_from_file(const char *filename)
+{
+ GFileBinary *result; /* Adresse à retourner */
+ GLoadedBinary *loaded; /* Version parente */
+ char *tmp; /* Nom de fichier modifiable */
+
+ result = g_object_new(G_TYPE_FILE_BINARY, NULL);
+ loaded = G_LOADED_BINARY(result);
+
+ log_variadic_message(LMT_PROCESS, _("Opening '%s' file..."), filename);
+
+ result->filename = strdup(filename);
+
+ tmp = strdup(filename);
+ loaded->format = G_EXE_FORMAT(load_new_format(FMT_EXEC, tmp,
+ &loaded->bin_data, &loaded->bin_length));
+ free(tmp);
+
+ if (loaded->format == NULL)
+ {
+ log_simple_message(LMT_INFO, _("Unknown binary format"));
+ goto lbf_error;
+ }
+
+ switch (g_exe_format_get_target_machine(loaded->format))
+ {
+ case FTM_ARM:
+ log_simple_message(LMT_INFO, _("Detected architecture: ARM"));
+ break;
+ case FTM_DALVIK:
+ log_simple_message(LMT_INFO, _("Detected architecture: Dalvik Virtual Machine"));
+ break;
+ case FTM_JVM:
+ log_simple_message(LMT_INFO, _("Detected architecture: Java Virtual Machine"));
+ break;
+ case FTM_MIPS:
+ log_simple_message(LMT_INFO, _("Detected architecture: Microprocessor without Interlocked Pipeline Stages"));
+ break;
+ case FTM_386:
+ log_simple_message(LMT_INFO, _("Detected architecture: i386"));
+ break;
+ default:
+ log_simple_message(LMT_INFO, _("Unknown architecture"));
+ goto lbf_error;
+ break;
+ }
+
+ loaded->proc = get_arch_processor_from_format(loaded->format);
+
+ return G_LOADED_BINARY(result);
+
+ lbf_error:
+
+ g_object_unref(G_OBJECT(result));
+
+ return NULL;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : context = contexte pour les recherches XPath. *
+* path = chemin d'accès au noeud XML à lire. *
+* *
+* Description : Charge en mémoire le contenu d'un fichier à partir d'XML. *
+* *
+* Retour : Adresse de la représentation ou NULL en cas d'échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GLoadedBinary *g_file_binary_new_from_xml(xmlXPathContextPtr context, const char *path)
+{
+ GLoadedBinary *result; /* Adresse à retourner */
+ char *access; /* Chemin pour une sous-config.*/
+ char *filename; /* Chemin du binaire à charger */
+
+ result = NULL;
+
+ /* Chemin du fichier à retrouver */
+
+ access = strdup(path);
+ access = stradd(access, "/Filename");
+
+ filename = get_node_text_value(context, access);
+
+ free(access);
+
+ /* Chargement */
+
+ if (filename != NULL)
+ {
+ result = g_file_binary_new_from_file(filename);
+ free(filename);
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = élément binaire à traiter. *
+* xdoc = structure XML en cours d'édition. *
+* context = contexte à utiliser pour les recherches. *
+* path = chemin d'accès réservé au binaire. *
+* *
+* Description : Ecrit une sauvegarde du binaire dans un fichier XML. *
+* *
+* Retour : true si l'opération a bien tourné, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_file_binary_save(const GFileBinary *binary, xmlDocPtr xdoc, xmlXPathContextPtr context, const char *path)
+{
+ bool result; /* Bilan à faire remonter */
+ char *access; /* Chemin d'accès à un élément */
+
+ result = true;
+
+ /* Type */
+
+ result &= add_string_attribute_to_node(xdoc, context, path, "type", "file");
+
+ /* Nom du fichier associé */
+
+ access = strdup(path);
+ access = stradd(access, "/Filename");
+
+ result &= add_content_to_node(xdoc, context, access, binary->filename);
+
+ free(access);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = élément binaire à consulter. *
+* full = précise s'il s'agit d'une version longue ou non. *
+* *
+* Description : Fournit le fichier correspondant à l'élément binaire. *
+* *
+* Retour : Nom de fichier avec chemin absolu. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static const char *g_file_binary_get_filename(const GFileBinary *binary, bool full)
+{
+ const char *result; /* Description à retourner */
+
+ if (full)
+ result = binary->filename;
+ else
+ result = strrchr(binary->filename, G_DIR_SEPARATOR) + 1;
+
+ return result;
+
+}
diff --git a/src/analysis/binaries/file.h b/src/analysis/binaries/file.h
new file mode 100644
index 0000000..3bff0a2
--- /dev/null
+++ b/src/analysis/binaries/file.h
@@ -0,0 +1,61 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * file.h - prototypes pour la prise en charge des binaires sous forme de fichier
+ *
+ * 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 _ANALYSIS_BINARIES_FILE_H
+#define _ANALYSIS_BINARIES_FILE_H
+
+
+#include <glib-object.h>
+
+
+#include "../binary.h"
+#include "../../common/xml.h"
+
+
+
+#define G_TYPE_FILE_BINARY g_file_binary_get_type()
+#define G_FILE_BINARY(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_file_binary_get_type(), GFileBinary))
+#define G_IS_FILE_BINARY(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_file_binary_get_type()))
+#define G_FILE_BINARY_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_file_binary_get_type(), GFileBinaryIface))
+#define G_FILE_BINARY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_FILE_BINARY, GFileBinaryClass))
+
+
+/* Description de fichier binaire (instance) */
+typedef struct _GFileBinary GFileBinary;
+
+/* Description de fichier binaire (classe) */
+typedef struct _GFileBinaryClass GFileBinaryClass;
+
+
+/* Indique le type défini pour une description de fichier binaire. */
+GType g_file_binary_get_type(void);
+
+/* Charge en mémoire le contenu d'un fichier. */
+GLoadedBinary *g_file_binary_new_from_file(const char *);
+
+/* Charge en mémoire le contenu d'un fichier à partir d'XML. */
+GLoadedBinary *g_file_binary_new_from_xml(xmlXPathContextPtr, const char *);
+
+
+
+#endif /* _ANALYSIS_BINARIES_FILE_H */
diff --git a/src/analysis/binary-int.h b/src/analysis/binary-int.h
new file mode 100644
index 0000000..c9be0bf
--- /dev/null
+++ b/src/analysis/binary-int.h
@@ -0,0 +1,84 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * binary-int.h - prototypes pour la définition interne des binaires
+ *
+ * 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 _ANALYSIS_BINARY_INT_H
+#define _ANALYSIS_BINARY_INT_H
+
+
+#include "binary.h"
+
+
+#include "../format/format.h"
+
+
+
+/* Ecrit une sauvegarde du binaire dans un fichier XML. */
+typedef bool (* save_binary_fc) (const GLoadedBinary *, xmlDocPtr, xmlXPathContextPtr, const char *);
+
+/* Fournit le fichier correspondant à l'élément binaire. */
+typedef const char * (* get_binary_filename_fc) (const GLoadedBinary *, bool);
+
+
+/* Description de fichier binaire (instance) */
+struct _GLoadedBinary
+{
+ GObject parent; /* A laisser en premier */
+
+ save_binary_fc save; /* Sauvegarde au format XML */
+ get_binary_filename_fc get_filename; /* Obtention d'une description */
+
+ off_t bin_length; /* Taille des données brutes */
+ bin_t *bin_data; /* Données binaires brutes */
+
+ GExeFormat *format; /* Format du binaire */
+ GArchProcessor *proc; /* Architecture du binaire */
+
+ BinaryPartModel model; /* Modèle de sélection */
+ GBinPart **parts[BPM_COUNT]; /* Parties binaires à analyser */
+ size_t parts_count[BPM_COUNT]; /* Quantité de ces parties */
+
+ GArchInstruction *instrs; /* Instructions d'assemblage */
+ GCodeBuffer *disass_buffer; /* Instructions lisibles */
+ GCodeBuffer **dec_buffers; /* Sources sous forme de texte */
+ size_t decbuf_count; /* Taille des tableaux */
+ size_t defsrc; /* Fichier source principal */
+
+ bool text_display[2]; /* Position et code binaire #1 */
+ bool lines_display; /* Affichage des lignes */
+
+};
+
+/* Description de fichier binaire (classe) */
+struct _GLoadedBinaryClass
+{
+ GObjectClass parent; /* A laisser en premier */
+
+ /* Signaux */
+
+ void (* disassembly_done) (GLoadedBinary *);
+
+};
+
+
+
+#endif /* _ANALYSIS_BINARY_INT_H */
diff --git a/src/analysis/binary.c b/src/analysis/binary.c
index 73070b1..fe8188b 100644
--- a/src/analysis/binary.c
+++ b/src/analysis/binary.c
@@ -24,118 +24,56 @@
#include "binary.h"
-#include <fcntl.h>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
#include <sys/types.h>
#include <i18n.h>
-#include "line_code.h" /* TODO : supprimer ? */
-#include "line_comment.h" /* TODO : supprimer ? */
-#include "line_prologue.h"
+#include "binary-int.h"
#include "routine.h"
+#include "binaries/file.h"
#include "decomp/decompiler.h"
#include "disass/disassembler.h"
-#include "../common/cpp.h"
#include "../common/extstr.h"
-#include "../debug/break.h"
-#include "../format/format.h"
-#include "../gui/panels/log.h"
-#include "../plugins/pglist.h" /* TODO : supprimer ? */
-
-
-#include "../format/dbg_format.h"
-
-
/* ------------------------ DESASSEMBLAGE DE BINAIRE DIFFERE ------------------------ */
-/* Description de fichier binaire (instance) */
-struct _GOpenidaBinary
-{
- GObject parent; /* A laisser en premier */
-
- char *filename; /* Fichier chargé en mémoire */
-
- off_t bin_length; /* Taille des données brutes */
- bin_t *bin_data; /* Données binaires brutes */
-
- GExeFormat *format; /* Format du binaire */
- GArchProcessor *proc; /* Architecture du binaire */
-
- BinaryPartModel model; /* Modèle de sélection */
- GBinPart **parts[BPM_COUNT]; /* Parties binaires à analyser */
- size_t parts_count[BPM_COUNT]; /* Quantité de ces parties */
-
- GRenderingLine *lines; /* Lignes de rendu en place */
- GRenderingOptions *options; /* Options de désassemblage */
-
- GArchInstruction *instrs; /* Instructions d'assemblage */
- GCodeBuffer *disass_buffer; /* Instructions lisibles */
- GCodeBuffer **dec_buffers; /* Sources sous forme de texte */
- size_t decbuf_count; /* Taille des tableaux */
- size_t defsrc; /* Fichier source principal */
-
- bool text_display[2]; /* Position et code binaire #1 */
- bool lines_display; /* Affichage des lignes */
-
- GBreakGroup **brk_groups; /* Groupes de points d'arrêt */
- size_t brk_count; /* Taille de cette liste */
- GBreakGroup *brk_default; /* Groupe par défaut */
-
-};
-
-/* Description de fichier binaire (classe) */
-struct _GOpenidaBinaryClass
-{
- GObjectClass parent; /* A laisser en premier */
-
- /* Signaux */
-
- void (* disassembly_done) (GOpenidaBinary *);
-
-};
-
/* Initialise la classe des descriptions de fichier binaire. */
-static void g_openida_binary_class_init(GOpenidaBinaryClass *);
+static void g_loaded_binary_class_init(GLoadedBinaryClass *);
/* Initialise une description de fichier binaire. */
-static void g_openida_binary_init(GOpenidaBinary *);
-
-/* Charge en mémoire le contenu d'un fichier. */
-bin_t *map_binary_file(const char *, off_t *);
-
-/* Acquitte la fin d'un désasemblage différé et complet. */
-void ack_completed_disassembly(void/*GDelayedDisassembly*/ *, GOpenidaBinary *);
+static void g_loaded_binary_init(GLoadedBinary *);
+/* Supprime toutes les références externes. */
+static void g_loaded_binary_dispose(GLoadedBinary *);
+/* Procède à la libération totale de la mémoire. */
+static void g_loaded_binary_finalize(GLoadedBinary *);
+/* Charge les parties intéressantes du binaire à partir d'XML. */
+static bool g_loaded_binary_load_parts_from_xml(GLoadedBinary *, xmlXPathContextPtr, const char *);
+/* Ecrit les parties de valeur du binaire dans un fichier XML. */
+static bool g_loaded_binary_save_parts(const GLoadedBinary *, xmlDocPtr, xmlXPathContextPtr, const char *);
-/* ------------------------------ ELEMENTS DE DEBOGAGE ------------------------------ */
+/* Acquitte la fin d'un désasemblage différé et complet. */
+void ack_completed_disassembly(void/*GDelayedDisassembly*/ *, GLoadedBinary *);
-/* Réagit à une nouvelle création de point d'arrêt. */
-static void g_openida_binary_breakpoint_added(GBreakGroup *, GBreakPoint *, GOpenidaBinary *);
-/* Réagit à une suppression de point d'arrêt. */
-static void g_openida_binary_breakpoint_removed(GBreakGroup *, GBreakPoint *, GOpenidaBinary *);
/* Indique le type défini pour une description de fichier binaire. */
-G_DEFINE_TYPE(GOpenidaBinary, g_openida_binary, G_TYPE_OBJECT);
+G_DEFINE_TYPE(GLoadedBinary, g_loaded_binary, G_TYPE_OBJECT);
/******************************************************************************
@@ -150,12 +88,19 @@ G_DEFINE_TYPE(GOpenidaBinary, g_openida_binary, G_TYPE_OBJECT);
* *
******************************************************************************/
-static void g_openida_binary_class_init(GOpenidaBinaryClass *klass)
+static void g_loaded_binary_class_init(GLoadedBinaryClass *klass)
{
+ GObjectClass *object; /* Autre version de la classe */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_loaded_binary_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_loaded_binary_finalize;
+
g_signal_new("disassembly-done",
- G_TYPE_OPENIDA_BINARY,
+ G_TYPE_LOADED_BINARY,
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET(GOpenidaBinaryClass, disassembly_done),
+ G_STRUCT_OFFSET(GLoadedBinaryClass, disassembly_done),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
@@ -175,133 +120,143 @@ static void g_openida_binary_class_init(GOpenidaBinaryClass *klass)
* *
******************************************************************************/
-static void g_openida_binary_init(GOpenidaBinary *binary)
+static void g_loaded_binary_init(GLoadedBinary *binary)
{
binary->text_display[0] = true;
binary->text_display[1] = true;
binary->lines_display = true;
- /* FIXME : à replacer ailleurs */
- g_openida_binary_add_break_group(binary, _("default"));
-
}
/******************************************************************************
* *
-* Paramètres : filename = nom du fichier à charger. *
+* Paramètres : binary = instance d'objet GLib à traiter. *
* *
-* Description : Charge en mémoire le contenu d'un fichier. *
+* Description : Supprime toutes les références externes. *
* *
-* Retour : Adresse de la représentation ou NULL en cas d'échec. *
+* Retour : - *
* *
* Remarques : - *
* *
******************************************************************************/
-GOpenidaBinary *g_openida_binary_new_from_file(const char *filename)
+static void g_loaded_binary_dispose(GLoadedBinary *binary)
{
- GOpenidaBinary *result; /* Adresse à retourner */
- GPluginModule **pglist; /* Liste de greffons */
- size_t pgcount; /* Taille de cette liste */
- size_t i; /* Boucle de parcours */
-
+ gpointer obj_class; /* Classe parente */
- char *file = strdup(filename);
+ g_object_unref(G_OBJECT(binary->format));
+ g_object_unref(G_OBJECT(binary->proc));
- result = g_object_new(G_TYPE_OPENIDA_BINARY, NULL);
+ /* TODO... */
+ /* On passe le relai */
+ obj_class = g_type_class_peek_parent(G_FILE_BINARY_GET_CLASS(binary));
+ G_OBJECT_CLASS(obj_class)->dispose(G_OBJECT(binary));
- printf("%s\n", filename);
+}
+/******************************************************************************
+* *
+* Paramètres : binary = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
- pglist = get_all_plugins_for_action(PGA_FORMAT_MATCHER, &pgcount);
+static void g_loaded_binary_finalize(GLoadedBinary *binary)
+{
+ gpointer obj_class; /* Classe parente */
- if (pgcount > 0)
- {
- printf("===>>>> FOUND :: %d\n", pgcount);
+ /* TODO */
+ /* On passe le relai */
- /*
- for (i = 0; i < pgcount; i++)
- g_plugin_module_execute_action_on_binary(pglist[i], binary, PGA_CODE_PROCESS);
- */
- free(pglist);
+ obj_class = g_type_class_peek_parent(G_FILE_BINARY_GET_CLASS(binary));
- }
+ G_OBJECT_CLASS(obj_class)->finalize(G_OBJECT(binary));
+}
+/******************************************************************************
+* *
+* Paramètres : context = contexte pour les recherches XPath. *
+* path = chemin d'accès au noeud XML à lire. *
+* *
+* Description : Charge en mémoire le contenu d'un fichier à partir d'XML. *
+* *
+* Retour : Adresse de la représentation ou NULL en cas d'échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+GLoadedBinary *g_loaded_binary_new_from_xml(xmlXPathContextPtr context, const char *path)
+{
+ GLoadedBinary *result; /* Adresse à retourner */
+ char *type; /* Tupe de binaire à charger */
+ result = NULL;
+ type = get_node_prop_value(context, path, "type");
+ if (strcmp(type, "file") == 0)
+ result = g_loaded_binary_new_from_xml(context, path);
+ free(type);
- log_variadic_message(LMT_PROCESS, _("Opening '%s' file..."), filename);
+ if (result == NULL)
+ return NULL;
- result->filename = strdup(filename);
+ if (!g_loaded_binary_load_parts_from_xml(result, context, path))
+ goto glbnfx_error;
- /*
- result->bin_data = map_binary_file(filename, &result->bin_length);
- if (result->bin_data == NULL) goto lbf_error;
- */
+ return result;
- result->format = G_EXE_FORMAT(load_new_format(FMT_EXEC, file,
- &result->bin_data, &result->bin_length));
- if (result->format == NULL)
- {
- log_simple_message(LMT_INFO, _("Unknown binary format"));
- goto lbf_error;
- }
+ glbnfx_error:
- /* FIXME : à déplacer dans arch/... */
- switch (g_exe_format_get_target_machine(result->format))
- {
- case FTM_ARM:
- log_simple_message(LMT_INFO, _("Detected architecture: ARM"));
- break;
- case FTM_DALVIK:
- log_simple_message(LMT_INFO, _("Detected architecture: Dalvik Virtual Machine"));
- break;
- case FTM_JVM:
- log_simple_message(LMT_INFO, _("Detected architecture: Java Virtual Machine"));
- break;
- case FTM_MIPS:
- log_simple_message(LMT_INFO, _("Detected architecture: Microprocessor without Interlocked Pipeline Stages"));
- break;
- case FTM_386:
- log_simple_message(LMT_INFO, _("Detected architecture: i386"));
- break;
- default:
- log_simple_message(LMT_INFO, _("Unknown architecture"));
- goto lbf_error;
- break;
- }
+ g_object_unref(G_OBJECT(result));
- result->lines = NULL;
+ return NULL;
- result->proc = get_arch_processor_from_format(result->format);
+}
- result->options = g_rendering_options_new(result->format);
- g_rendering_options_show_address(result->options, MRD_BLOCK, true);
- g_rendering_options_show_code(result->options, MRD_BLOCK, true);
+/******************************************************************************
+* *
+* Paramètres : binary = élément binaire à traiter. *
+* xdoc = structure XML en cours d'édition. *
+* context = contexte à utiliser pour les recherches. *
+* path = chemin d'accès réservé au binaire. *
+* *
+* Description : Ecrit une sauvegarde du binaire dans un fichier XML. *
+* *
+* Retour : true si l'opération a bien tourné, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
- g_rendering_options_show_address(result->options, MRD_GRAPH, true);
- g_rendering_options_show_code(result->options, MRD_GRAPH, false);
+bool g_loaded_binary_save(const GLoadedBinary *binary, xmlDocPtr xdoc, xmlXPathContextPtr context, const char *path)
+{
+ bool result; /* Bilan à faire remonter */
- return result;
+ result = binary->save(binary, xdoc, context, path);
- lbf_error:
+ /* Parties à désassembler */
- //unload_binary_file(result);
+ result = g_loaded_binary_save_parts(binary, xdoc, context, path);
- return NULL;
+ return result;
}
@@ -311,21 +266,18 @@ GOpenidaBinary *g_openida_binary_new_from_file(const char *filename)
* Paramètres : context = contexte pour les recherches XPath. *
* path = chemin d'accès au noeud XML à lire. *
* *
-* Description : Charge en mémoire le contenu d'un fichier à partir d'XML. *
+* Description : Charge les parties intéressantes du binaire à partir d'XML. *
* *
-* Retour : Adresse de la représentation ou NULL en cas d'échec. *
+* Retour : Bilan de l'opération. *
* *
* Remarques : - *
* *
******************************************************************************/
-GOpenidaBinary *g_openida_binary_new_from_xml(xmlXPathContextPtr context, const char *path)
+static bool g_loaded_binary_load_parts_from_xml(GLoadedBinary *binary, xmlXPathContextPtr context, const char *path)
{
- GOpenidaBinary *result; /* Adresse à retourner */
- char *type; /* Tupe de binaire à charger */
- size_t access_len; /* Taille d'un chemin interne */
+ bool result; /* Bilan à retourner */
char *access; /* Chemin pour une sous-config.*/
- char *filename; /* Chemin du binaire à charger */
xmlXPathObjectPtr xobjects; /* Cible d'une recherche */
int i; /* Boucle de parcours */
GBinPart *part; /* Partie binaire à traiter */
@@ -334,33 +286,6 @@ GOpenidaBinary *g_openida_binary_new_from_xml(xmlXPathContextPtr context, const
result = NULL;
- /* Type */
-
- type = get_node_prop_value(context, path, "type");
-
- printf("###type### %s\n", type);
-
- free(type);
-
- /* Chemin du fichier à retrouver */
-
- access = strdup(path);
- access = stradd(access, "/Filename");
-
- filename = get_node_text_value(context, access);
-
- free(access);
-
- /* Chargement */
-
- if (filename != NULL)
- {
- result = g_openida_binary_new_from_file(filename);
- free(filename);
- }
-
- if (result == NULL) return NULL;
-
/* Parties à désassembler : default */
access = strdup(path);
@@ -376,29 +301,29 @@ GOpenidaBinary *g_openida_binary_new_from_xml(xmlXPathContextPtr context, const
{
g_binary_part_get_values(part, &offset, NULL, NULL);
- if (!g_exe_format_translate_offset_into_address(G_EXE_FORMAT(result->format), offset, &addr))
+ if (!g_exe_format_translate_offset_into_address(G_EXE_FORMAT(binary->format), offset, &addr))
{
g_object_unref(G_OBJECT(part));
continue;
}
- result->parts_count[BPM_DEFAULT]++;
- result->parts[BPM_DEFAULT] = (GBinPart **)realloc(result->parts[BPM_DEFAULT],
- result->parts_count[BPM_DEFAULT] * sizeof(GBinPart *));
+ binary->parts_count[BPM_DEFAULT]++;
+ binary->parts[BPM_DEFAULT] = (GBinPart **)realloc(binary->parts[BPM_DEFAULT],
+ binary->parts_count[BPM_DEFAULT] * sizeof(GBinPart *));
- result->parts[BPM_DEFAULT][result->parts_count[BPM_DEFAULT] - 1] = part;
+ binary->parts[BPM_DEFAULT][binary->parts_count[BPM_DEFAULT] - 1] = part;
}
}
- if(xobjects != NULL) /* FIXME */
+ if(xobjects != NULL)
xmlXPathFreeObject(xobjects);
free(access);
- qsort(result->parts[BPM_DEFAULT], result->parts_count[BPM_DEFAULT],
- sizeof(GBinPart *), g_binary_part_compare);
+ qsort(binary->parts[BPM_DEFAULT], binary->parts_count[BPM_DEFAULT],
+ sizeof(GBinPart *), (__compar_fn_t)g_binary_part_compare);
/* Parties à désassembler : routines */
@@ -415,30 +340,30 @@ GOpenidaBinary *g_openida_binary_new_from_xml(xmlXPathContextPtr context, const
{
g_binary_part_get_values(part, &offset, NULL, NULL);
- if (!g_exe_format_translate_offset_into_address(G_EXE_FORMAT(result->format), offset, &addr))
+ if (!g_exe_format_translate_offset_into_address(G_EXE_FORMAT(binary->format), offset, &addr))
{
g_object_unref(G_OBJECT(part));
continue;
}
else g_binary_part_set_address(part, addr);
- result->parts_count[BPM_ROUTINES]++;
- result->parts[BPM_ROUTINES] = (GBinPart **)realloc(result->parts[BPM_ROUTINES],
- result->parts_count[BPM_ROUTINES] * sizeof(GBinPart *));
+ binary->parts_count[BPM_ROUTINES]++;
+ binary->parts[BPM_ROUTINES] = (GBinPart **)realloc(binary->parts[BPM_ROUTINES],
+ binary->parts_count[BPM_ROUTINES] * sizeof(GBinPart *));
- result->parts[BPM_ROUTINES][result->parts_count[BPM_ROUTINES] - 1] = part;
+ binary->parts[BPM_ROUTINES][binary->parts_count[BPM_ROUTINES] - 1] = part;
}
}
- if(xobjects != NULL) /* FIXME */
+ if(xobjects != NULL)
xmlXPathFreeObject(xobjects);
free(access);
- qsort(result->parts[BPM_ROUTINES], result->parts_count[BPM_ROUTINES],
- sizeof(GBinPart *), g_binary_part_compare);
+ qsort(binary->parts[BPM_ROUTINES], binary->parts_count[BPM_ROUTINES],
+ sizeof(GBinPart *), (__compar_fn_t)g_binary_part_compare);
/* Parties à désassembler : utilisateur */
@@ -455,34 +380,29 @@ GOpenidaBinary *g_openida_binary_new_from_xml(xmlXPathContextPtr context, const
{
g_binary_part_get_values(part, &offset, NULL, NULL);
- if (!g_exe_format_translate_offset_into_address(G_EXE_FORMAT(result->format), offset, &addr))
+ if (!g_exe_format_translate_offset_into_address(G_EXE_FORMAT(binary->format), offset, &addr))
{
g_object_unref(G_OBJECT(part));
continue;
}
- result->parts_count[BPM_USER]++;
- result->parts[BPM_USER] = (GBinPart **)realloc(result->parts[BPM_USER],
- result->parts_count[BPM_USER] * sizeof(GBinPart *));
+ binary->parts_count[BPM_USER]++;
+ binary->parts[BPM_USER] = (GBinPart **)realloc(binary->parts[BPM_USER],
+ binary->parts_count[BPM_USER] * sizeof(GBinPart *));
- result->parts[BPM_USER][result->parts_count[BPM_USER] - 1] = part;
+ binary->parts[BPM_USER][binary->parts_count[BPM_USER] - 1] = part;
}
}
- if(xobjects != NULL) /* FIXME */
+ if(xobjects != NULL)
xmlXPathFreeObject(xobjects);
free(access);
- qsort(result->parts[BPM_USER], result->parts_count[BPM_USER],
- sizeof(GBinPart *), g_binary_part_compare);
-
-
-
-
-
+ qsort(binary->parts[BPM_USER], binary->parts_count[BPM_USER],
+ sizeof(GBinPart *), (__compar_fn_t)g_binary_part_compare);
return result;
@@ -496,7 +416,7 @@ GOpenidaBinary *g_openida_binary_new_from_xml(xmlXPathContextPtr context, const
* context = contexte à utiliser pour les recherches. *
* path = chemin d'accès réservé au binaire. *
* *
-* Description : Ecrit une sauvegarde du binaire dans un fichier XML. *
+* Description : Ecrit les parties de valeur du binaire dans un fichier XML. *
* *
* Retour : true si l'opération a bien tourné, false sinon. *
* *
@@ -504,7 +424,7 @@ GOpenidaBinary *g_openida_binary_new_from_xml(xmlXPathContextPtr context, const
* *
******************************************************************************/
-bool g_openida_binary_save(const GOpenidaBinary *binary, xmlDocPtr xdoc, xmlXPathContextPtr context, const char *path)
+static bool g_loaded_binary_save_parts(const GLoadedBinary *binary, xmlDocPtr xdoc, xmlXPathContextPtr context, const char *path)
{
bool result; /* Bilan à faire remonter */
char *access; /* Chemin d'accès à un élément */
@@ -513,21 +433,6 @@ bool g_openida_binary_save(const GOpenidaBinary *binary, xmlDocPtr xdoc, xmlXPat
result = true;
- /* Type */
-
- result &= add_string_attribute_to_node(xdoc, context, path, "type", "file");
-
- /* Nom du fichier associé */
-
- access = strdup(path);
- access = stradd(access, "/Filename");
-
- result &= add_content_to_node(xdoc, context, access, binary->filename);
-
- free(access);
-
- /* Parties à désassembler */
-
if (binary->parts_count[BPM_DEFAULT] > 0)
{
access = strdup(path);
@@ -590,9 +495,9 @@ bool g_openida_binary_save(const GOpenidaBinary *binary, xmlDocPtr xdoc, xmlXPat
* *
******************************************************************************/
-void g_openida_binary_set_parts(GOpenidaBinary *binary, BinaryPartModel model, GBinPart **parts, size_t count)
+void g_loaded_binary_set_parts(GLoadedBinary *binary, BinaryPartModel model, GBinPart **parts, size_t count)
{
- qsort(parts, count, sizeof(GBinPart *), g_binary_part_compare);
+ qsort(parts, count, sizeof(GBinPart *), (__compar_fn_t)g_binary_part_compare);
binary->parts[model] = parts;
binary->parts_count[model] = count;
@@ -614,7 +519,7 @@ void g_openida_binary_set_parts(GOpenidaBinary *binary, BinaryPartModel model, G
* *
******************************************************************************/
-GBinPart ***g_openida_binary_get_parts(const GOpenidaBinary *binary, BinaryPartModel *model, size_t **count)
+GBinPart ***g_loaded_binary_get_parts(const GLoadedBinary *binary, BinaryPartModel *model, size_t **count)
{
*model = binary->model;
*count = binary->parts_count;
@@ -636,7 +541,7 @@ GBinPart ***g_openida_binary_get_parts(const GOpenidaBinary *binary, BinaryPartM
* *
******************************************************************************/
-void g_openida_binary_analyse(GOpenidaBinary *binary)
+void g_loaded_binary_analyse(GLoadedBinary *binary)
{
GBinPart **parts; /* Parties d'élément binaire */
size_t parts_count; /* Nombre de ces parties */
@@ -660,7 +565,7 @@ void g_openida_binary_analyse(GOpenidaBinary *binary)
else
{
parts = g_exe_format_get_parts(binary->format, &parts_count);
- qsort(parts, parts_count, sizeof(GBinPart *), g_binary_part_compare);
+ qsort(parts, parts_count, sizeof(GBinPart *), (__compar_fn_t)g_binary_part_compare);
}
}
@@ -676,25 +581,7 @@ void g_openida_binary_analyse(GOpenidaBinary *binary)
/******************************************************************************
* *
* Paramètres : binary = élément binaire à consulter. *
-* *
-* Description : Fournit une description humaine d'un élément binaire. *
-* *
-* Retour : Chaîne de caractères humainenement lisible de représentation.*
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-const char *g_openida_binary_to_string(const GOpenidaBinary *binary)
-{
- return binary->filename;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : binary = élément binaire à consulter. *
+* full = précise s'il s'agit d'une version longue ou non. *
* *
* Description : Fournit le fichier correspondant à l'élément binaire. *
* *
@@ -704,9 +591,9 @@ const char *g_openida_binary_to_string(const GOpenidaBinary *binary)
* *
******************************************************************************/
-const char *g_openida_binary_get_filename(const GOpenidaBinary *binary)
+const char *g_loaded_binary_get_filename(const GLoadedBinary *binary, bool full)
{
- return binary->filename;
+ return binary->get_filename(binary, full);
}
@@ -724,7 +611,7 @@ const char *g_openida_binary_get_filename(const GOpenidaBinary *binary)
* *
******************************************************************************/
-bin_t *g_openida_binary_get_data(const GOpenidaBinary *binary, off_t *length)
+bin_t *g_loaded_binary_get_data(const GLoadedBinary *binary, off_t *length)
{
if (length != NULL)
*length = binary->bin_length;
@@ -746,7 +633,7 @@ bin_t *g_openida_binary_get_data(const GOpenidaBinary *binary, off_t *length)
* *
******************************************************************************/
-GExeFormat *g_openida_binary_get_format(const GOpenidaBinary *binary)
+GExeFormat *g_loaded_binary_get_format(const GLoadedBinary *binary)
{
return binary->format;
@@ -757,63 +644,6 @@ GExeFormat *g_openida_binary_get_format(const GOpenidaBinary *binary)
* *
* Paramètres : binary = élément binaire à consulter. *
* *
-* Description : Fournit les options d'affichage définies pour le binaire. *
-* *
-* Retour : Adresse des options d'affichage. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-GRenderingOptions *g_openida_binary_get_options(const GOpenidaBinary *binary)
-{
- return binary->options;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : binary = élément binaire à consulter. *
-* *
-* Description : Donne la racine des lignes de rendu issues du désassemblage. *
-* *
-* Retour : Lieu d'enregistrement des lignes issues du désassemblage. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-GRenderingLine **g_openida_binary_get_lines_root(const GOpenidaBinary *binary)
-{
- return &binary->lines;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : binary = élément binaire à consulter. *
-* *
-* Description : Fournit les lignes de rendu issues du désassemblage. *
-* *
-* Retour : Lignes issues du désassemblage. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-GRenderingLine *g_openida_binary_get_lines(const GOpenidaBinary *binary)
-{
- return binary->lines;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : binary = élément binaire à consulter. *
-* *
* Description : Fournit les instructions issues du désassemblage. *
* *
* Retour : Instructions issues du désassemblage. *
@@ -822,7 +652,7 @@ GRenderingLine *g_openida_binary_get_lines(const GOpenidaBinary *binary)
* *
******************************************************************************/
-GArchInstruction *g_openida_binary_get_instructions(const GOpenidaBinary *binary)
+GArchInstruction *g_loaded_binary_get_instructions(const GLoadedBinary *binary)
{
return binary->instrs;
@@ -841,7 +671,7 @@ GArchInstruction *g_openida_binary_get_instructions(const GOpenidaBinary *binary
* *
******************************************************************************/
-GCodeBuffer *g_openida_binary_get_disassembled_buffer(const GOpenidaBinary *binary)
+GCodeBuffer *g_loaded_binary_get_disassembled_buffer(const GLoadedBinary *binary)
{
return binary->disass_buffer;
@@ -860,7 +690,7 @@ GCodeBuffer *g_openida_binary_get_disassembled_buffer(const GOpenidaBinary *bina
* *
******************************************************************************/
-bool *g_openida_binary_display_addresses_in_text(const GOpenidaBinary *binary)
+bool *g_loaded_binary_display_addresses_in_text(GLoadedBinary *binary)
{
return &binary->text_display[0];
@@ -879,7 +709,7 @@ bool *g_openida_binary_display_addresses_in_text(const GOpenidaBinary *binary)
* *
******************************************************************************/
-bool *g_openida_binary_display_code_in_text(const GOpenidaBinary *binary)
+bool *g_loaded_binary_display_code_in_text(GLoadedBinary *binary)
{
return &binary->text_display[1];
@@ -899,7 +729,7 @@ bool *g_openida_binary_display_code_in_text(const GOpenidaBinary *binary)
* *
******************************************************************************/
-GCodeBuffer *g_openida_binary_get_decompiled_buffer(const GOpenidaBinary *binary, size_t index)
+GCodeBuffer *g_loaded_binary_get_decompiled_buffer(const GLoadedBinary *binary, size_t index)
{
GCodeBuffer *result; /* Tampon à retourner */
@@ -926,7 +756,7 @@ GCodeBuffer *g_openida_binary_get_decompiled_buffer(const GOpenidaBinary *binary
* *
******************************************************************************/
-bool *g_openida_binary_display_decomp_lines(const GOpenidaBinary *binary)
+bool *g_loaded_binary_display_decomp_lines(GLoadedBinary *binary)
{
return &binary->lines_display;
@@ -935,59 +765,6 @@ bool *g_openida_binary_display_decomp_lines(const GOpenidaBinary *binary)
/******************************************************************************
* *
-* Paramètres : filename = nom du fichier à charger. *
-* length = taille des données mises en mémoire. [OUT] *
-* *
-* Description : Charge en mémoire le contenu d'un fichier. *
-* *
-* Retour : Adresse du contenu binaire ou NULL en cas d'échec. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bin_t *map_binary_file(const char *filename, off_t *length)
-{
- uint8_t *result; /* Données à retourner */
- int fd; /* Fichier ouvert en lecture */
- struct stat info; /* Informations sur le fichier */
- int ret; /* Bilan d'un appel */
-
- fd = open(filename, 0, O_RDONLY);
- if (fd == -1)
- {
- perror("open()");
- return NULL;
- }
-
- ret = fstat(fd, &info);
- if (ret == -1)
- {
- perror("fstat()");
- close(fd);
- return NULL;
- }
-
- *length = info.st_size;
-
- result = (uint8_t *)mmap(NULL, *length, PROT_READ, MAP_PRIVATE, fd, 0);
- if (result == MAP_FAILED)
- {
- perror("mmap()");
- result = NULL;
- }
-
- ret = close(fd);
- if (ret == -1)
- perror("close()");
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
* Paramètres : disass = travail de désassemblage mené à bien. *
* binary = représentation de binaire à l'origine de l'opérat°. *
* *
@@ -999,9 +776,9 @@ bin_t *map_binary_file(const char *filename, off_t *length)
* *
******************************************************************************/
-void ack_completed_disassembly(void/*GDelayedDisassembly*/ *disass, GOpenidaBinary *binary)
+void ack_completed_disassembly(void/*GDelayedDisassembly*/ *disass, GLoadedBinary *binary)
{
- GRenderingLine *line; /* "Première" ligne de rendu */
+ //GRenderingLine *line; /* "Première" ligne de rendu */
size_t i; /* Boucle de parcours */
@@ -1040,196 +817,3 @@ void ack_completed_disassembly(void/*GDelayedDisassembly*/ *disass, GOpenidaBina
g_signal_emit_by_name(binary, "disassembly-done");
}
-
-
-
-/* ---------------------------------------------------------------------------------- */
-/* ELEMENTS DE DEBOGAGE */
-/* ---------------------------------------------------------------------------------- */
-
-
-/******************************************************************************
-* *
-* Paramètres : binary = représentation de binaire à modifier. *
-* name = éventuel nom à associer au groupe. *
-* *
-* Description : Ajoute un nouveau groupe de points d'arrêt au binaire. *
-* *
-* Retour : true si l'opération s'est bien effectuée, false sinon. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool g_openida_binary_add_break_group(GOpenidaBinary *binary, const char *name)
-{
- bool result; /* Bilan à faire remonter */
- const char *used; /* Désignation à utiliser */
- size_t tmp_len; /* Longeur maximale à gérer */
- char *tmp; /* Construction temporaire */
- size_t i; /* Boucle de parcours */
- const char *test; /* Nom existant à tester */
-
- result = true;
-
- /* Préparation du nom de scène */
-
- if (name != NULL) used = name;
- else
- {
- tmp_len = strlen(_("Group")) + 1 + SIZE_T_MAXLEN + 1;
- tmp = (char *)calloc(tmp_len, sizeof(char));
-
- snprintf(tmp, tmp_len, "%s %lu", _("Group"), binary->brk_count);
-
- used = tmp;
-
- }
-
- /* Vérification d'unicité */
-
- for (i = 0; i < binary->brk_count && result; i++)
- {
- test = g_break_group_get_name(binary->brk_groups[i]);
-
- if (test != NULL)
- result = (strcmp(used, test) != 0);
-
- }
-
- /* Mise en place finale */
-
- if (result)
- {
- binary->brk_count++;
- binary->brk_groups = (GBreakGroup **)realloc(binary->brk_groups,
- binary->brk_count * sizeof(GBreakGroup *));
-
- binary->brk_groups[i] = g_break_group_new();
-
- g_break_group_set_name(binary->brk_groups[i], used);
-
- if (binary->brk_default == NULL)
- binary->brk_default = binary->brk_groups[i];
-
- g_signal_connect(binary->brk_groups[i], "added",
- G_CALLBACK(g_openida_binary_breakpoint_added), binary);
-
- g_signal_connect(binary->brk_groups[i], "removed",
- G_CALLBACK(g_openida_binary_breakpoint_removed), binary);
-
- }
-
- if (name == NULL) free(tmp);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : group = ensemble de points d'arrêt intervenant. *
-* point = point d'arrêt à l'origine de la procédure. *
-* binary = représentation de binaire à modifier. *
-* *
-* Description : Réagit à une nouvelle création de point d'arrêt. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static void g_openida_binary_breakpoint_added(GBreakGroup *group, GBreakPoint *point, GOpenidaBinary *binary)
-{
- GRenderingLine *line; /* Ligne à retrouver */
-
- line = g_rendering_line_find_by_address(binary->lines, NULL,
- g_break_point_get_address(point));
-
- if (line != NULL)
- g_rendering_line_toggle_flag(line, RLF_BREAK_POINT);
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : group = ensemble de points d'arrêt intervenant. *
-* point = point d'arrêt à l'origine de la procédure. *
-* binary = représentation de binaire à modifier. *
-* *
-* Description : Réagit à une suppression de point d'arrêt. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static void g_openida_binary_breakpoint_removed(GBreakGroup *group, GBreakPoint *point, GOpenidaBinary *binary)
-{
- GRenderingLine *line; /* Ligne à retrouver */
-
- line = g_rendering_line_find_by_address(binary->lines, NULL,
- g_break_point_get_address(point));
-
- if (line != NULL)
- g_rendering_line_toggle_flag(line, RLF_BREAK_POINT);
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : binary = représentation de binaire à mettre à jour. *
-* addr = adresse mémoire à faire basculer. *
-* *
-* Description : Ajoute ou supprime un point d'arrêt dans un binaire. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-void g_openida_binary_toggle_breakpoint(GOpenidaBinary *binary, vmpa_t addr)
-{
- size_t i; /* Boucle de parcours */
-
- for (i = 0; i < binary->brk_count; i++)
- if (g_break_group_has_address(binary->brk_groups[i], addr))
- {
- g_break_group_toggle_breakpoint(binary->brk_groups[i], addr);
- break;
- }
-
- if (i == binary->brk_count)
- g_break_group_toggle_breakpoint(binary->brk_default, addr);
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : binary = représentation de binaire à parcourir. *
-* func = fonction à appeler à chaque point trouvé. *
-* data = éventuelle donnée de l'utilisateur à joindre. *
-* *
-* Description : Parcourt l'ensemble des groupes de points d'arrêt du binaire.*
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-void g_openida_binary_for_each_bp_group(GOpenidaBinary *binary, GExtFunc func, gpointer data)
-{
- size_t i; /* Boucle de parcours */
-
- for (i = 0; i < binary->brk_count; i++)
- func(binary, binary->brk_groups[i], data);
-
-}
diff --git a/src/analysis/binary.h b/src/analysis/binary.h
index 63a9e61..7ff9080 100644
--- a/src/analysis/binary.h
+++ b/src/analysis/binary.h
@@ -32,24 +32,23 @@
#include "line.h"
#include "../arch/processor.h"
#include "../common/xml.h"
-#include "../debug/break.h"
#include "../format/executable.h"
#include "../glibext/gcodebuffer.h"
-#define G_TYPE_OPENIDA_BINARY g_openida_binary_get_type()
-#define G_OPENIDA_BINARY(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_openida_binary_get_type(), GOpenidaBinary))
-#define G_IS_OPENIDA_BINARY(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_openida_binary_get_type()))
-#define G_OPENIDA_BINARY_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_openida_binary_get_type(), GOpenidaBinaryIface))
-#define G_OPENIDA_BINARY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_OPENIDA_BINARY, GOpenidaBinaryClass))
+#define G_TYPE_LOADED_BINARY g_loaded_binary_get_type()
+#define G_LOADED_BINARY(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_loaded_binary_get_type(), GLoadedBinary))
+#define G_IS_LOADED_BINARY(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_loaded_binary_get_type()))
+#define G_LOADED_BINARY_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_loaded_binary_get_type(), GLoadedBinaryIface))
+#define G_LOADED_BINARY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_LOADED_BINARY, GLoadedBinaryClass))
/* Description de fichier binaire (instance) */
-typedef struct _GOpenidaBinary GOpenidaBinary;
+typedef struct _GLoadedBinary GLoadedBinary;
/* Description de fichier binaire (classe) */
-typedef struct _GOpenidaBinaryClass GOpenidaBinaryClass;
+typedef struct _GLoadedBinaryClass GLoadedBinaryClass;
/* Modèle de sélection des parties */
@@ -65,78 +64,49 @@ typedef enum _BinaryPartModel
/* Indique le type défini pour une description de fichier binaire. */
-GType g_openida_binary_get_type(void);
-
-/* Charge en mémoire le contenu d'un fichier. */
-GOpenidaBinary *g_openida_binary_new_from_file(const char *);
+GType g_loaded_binary_get_type(void);
/* Charge en mémoire le contenu d'un fichier à partir d'XML. */
-GOpenidaBinary *g_openida_binary_new_from_xml(xmlXPathContextPtr, const char *);
+GLoadedBinary *g_loaded_binary_new_from_xml(xmlXPathContextPtr, const char *);
/* Ecrit une sauvegarde du binaire dans un fichier XML. */
-bool g_openida_binary_save(const GOpenidaBinary *, xmlDocPtr, xmlXPathContextPtr, const char *);
+bool g_loaded_binary_save(const GLoadedBinary *, xmlDocPtr, xmlXPathContextPtr, const char *);
/* Définit les parties de binaire à analyser. */
-void g_openida_binary_set_parts(GOpenidaBinary *, BinaryPartModel, GBinPart **, size_t);
+void g_loaded_binary_set_parts(GLoadedBinary *, BinaryPartModel, GBinPart **, size_t);
/* Fournit les parties de binaire analysées. */
-GBinPart ***g_openida_binary_get_parts(const GOpenidaBinary *, BinaryPartModel *, size_t **);
+GBinPart ***g_loaded_binary_get_parts(const GLoadedBinary *, BinaryPartModel *, size_t **);
/* Lance l'analyse d'un élément binaire chargé. */
-void g_openida_binary_analyse(GOpenidaBinary *);
-
-/* Fournit une description humaine d'un élément binaire. */
-const char *g_openida_binary_to_string(const GOpenidaBinary *);
+void g_loaded_binary_analyse(GLoadedBinary *);
/* Fournit le fichier correspondant à l'élément binaire. */
-const char *g_openida_binary_get_filename(const GOpenidaBinary *);
+const char *g_loaded_binary_get_filename(const GLoadedBinary *, bool);
/* Fournit les détails du contenu binaire chargé en mémoire. */
-bin_t *g_openida_binary_get_data(const GOpenidaBinary *, off_t *);
+bin_t *g_loaded_binary_get_data(const GLoadedBinary *, off_t *);
/* Fournit le format de fichier reconnu dans le contenu binaire. */
-GExeFormat *g_openida_binary_get_format(const GOpenidaBinary *);
-
-/* Fournit les options d'affichage définies pour le binaire. */
-GRenderingOptions *g_openida_binary_get_options(const GOpenidaBinary *);
-
-/* Donne la racine des lignes de rendu issues du désassemblage. */
-GRenderingLine **g_openida_binary_get_lines_root(const GOpenidaBinary *);
-
-/* Fournit les lignes de rendu issues du désassemblage. */
-GRenderingLine *g_openida_binary_get_lines(const GOpenidaBinary *);
+GExeFormat *g_loaded_binary_get_format(const GLoadedBinary *);
/* Fournit les instructions issues du désassemblage. */
-GArchInstruction *g_openida_binary_get_instructions(const GOpenidaBinary *);
+GArchInstruction *g_loaded_binary_get_instructions(const GLoadedBinary *);
/* Fournit le tampon associé au contenu assembleur d'un binaire. */
-GCodeBuffer *g_openida_binary_get_disassembled_buffer(const GOpenidaBinary *);
+GCodeBuffer *g_loaded_binary_get_disassembled_buffer(const GLoadedBinary *);
/* Indique si les adresses doivent apparaître dans le rendu. */
-bool *g_openida_binary_display_addresses_in_text(const GOpenidaBinary *);
+bool *g_loaded_binary_display_addresses_in_text(GLoadedBinary *);
/* Indique si le code doit apparaître dans le rendu. */
-bool *g_openida_binary_display_code_in_text(const GOpenidaBinary *);
+bool *g_loaded_binary_display_code_in_text(GLoadedBinary *);
/* Fournit le tampon associé au contenu d'un fichier source. */
-GCodeBuffer *g_openida_binary_get_decompiled_buffer(const GOpenidaBinary *, size_t);
+GCodeBuffer *g_loaded_binary_get_decompiled_buffer(const GLoadedBinary *, size_t);
/* Indique si les lignes doivent apparaître dans le rendu. */
-bool *g_openida_binary_display_decomp_lines(const GOpenidaBinary *);
-
-
-
-/* ------------------------------ ELEMENTS DE DEBOGAGE ------------------------------ */
-
-
-/* Ajoute un nouveau groupe de points d'arrêt au binaire. */
-bool g_openida_binary_add_break_group(GOpenidaBinary *, const char *);
-
-/* Ajoute ou supprime un point d'arrêt dans un binaire. */
-void g_openida_binary_toggle_breakpoint(GOpenidaBinary *, vmpa_t);
-
-/* Parcourt l'ensemble des groupes de points d'arrêt du binaire. */
-void g_openida_binary_for_each_bp_group(GOpenidaBinary *, GExtFunc, gpointer);
+bool *g_loaded_binary_display_decomp_lines(GLoadedBinary *);
diff --git a/src/analysis/decomp/decompiler.c b/src/analysis/decomp/decompiler.c
index 42dc1ff..8e574c0 100644
--- a/src/analysis/decomp/decompiler.c
+++ b/src/analysis/decomp/decompiler.c
@@ -42,7 +42,7 @@
static void build_decomp_prologue(GCodeBuffer *, const char *);
/* S'assure de la transcription de routines en expressions. */
-static void prepare_all_routines_for_decomp(const GOpenidaBinary *, const char *);
+static void prepare_all_routines_for_decomp(const GLoadedBinary *, const char *);
@@ -127,7 +127,7 @@ static void build_decomp_prologue(GCodeBuffer *buffer, const char *filename)
* *
******************************************************************************/
-static void prepare_all_routines_for_decomp(const GOpenidaBinary *binary, const char *filename)
+static void prepare_all_routines_for_decomp(const GLoadedBinary *binary, const char *filename)
{
GExeFormat *format; /* Format du binaire fourni */
GArchProcessor *proc; /* Architecture du binaire */
@@ -140,7 +140,7 @@ static void prepare_all_routines_for_decomp(const GOpenidaBinary *binary, const
GDecContext *context; /* Contexte pour la décompil. */
GDecInstruction *instr;
- format = g_openida_binary_get_format(binary);
+ format = g_loaded_binary_get_format(binary);
proc = get_arch_processor_from_format(G_EXE_FORMAT(format));
@@ -179,7 +179,7 @@ static void prepare_all_routines_for_decomp(const GOpenidaBinary *binary, const
* *
******************************************************************************/
-GCodeBuffer *decompile_all_from_file(const GOpenidaBinary *binary, const char *filename)
+GCodeBuffer *decompile_all_from_file(const GLoadedBinary *binary, const char *filename)
{
GCodeBuffer *result; /* Tampon constitué à renvoyer */
GExeFormat *format; /* Format du binaire fourni */
@@ -195,7 +195,7 @@ GCodeBuffer *decompile_all_from_file(const GOpenidaBinary *binary, const char *f
- format = g_openida_binary_get_format(binary);
+ format = g_loaded_binary_get_format(binary);
g_binary_format_decompile(G_BIN_FORMAT(format), result, filename);
return result;
diff --git a/src/analysis/decomp/decompiler.h b/src/analysis/decomp/decompiler.h
index 363ad27..5233b74 100644
--- a/src/analysis/decomp/decompiler.h
+++ b/src/analysis/decomp/decompiler.h
@@ -30,7 +30,7 @@
/* Procède à la décompilation des routines d'un fichier donné. */
-GCodeBuffer *decompile_all_from_file(const GOpenidaBinary *, const char *);
+GCodeBuffer *decompile_all_from_file(const GLoadedBinary *, const char *);
diff --git a/src/analysis/disass/disassembler.c b/src/analysis/disass/disassembler.c
index 872dc09..73d75cf 100644
--- a/src/analysis/disass/disassembler.c
+++ b/src/analysis/disass/disassembler.c
@@ -60,7 +60,7 @@ typedef struct _GDelayedDisassembly
{
GDelayedWork parent; /* A laisser en premier */
- const GOpenidaBinary *binary; /* Destinataire final */
+ const GLoadedBinary *binary; /* Destinataire final */
const GExeFormat *format; /* Format du binaire représenté*/
GBinPart **parts; /* Parties binaires à traiter */
@@ -89,7 +89,7 @@ static void g_delayed_disassembly_class_init(GDelayedDisassemblyClass *);
static void g_delayed_disassembly_init(GDelayedDisassembly *);
/* Crée une tâche de désassemblage différé. */
-static GDelayedDisassembly *g_delayed_disassembly_new(const GOpenidaBinary *, GBinPart **, size_t, GCodeBuffer *);
+static GDelayedDisassembly *g_delayed_disassembly_new(const GLoadedBinary *, GBinPart **, size_t, GCodeBuffer *);
/* Assure le désassemblage en différé. */
static void g_delayed_disassembly_process(GDelayedDisassembly *, GtkExtStatusBar *);
@@ -165,14 +165,14 @@ static void g_delayed_disassembly_init(GDelayedDisassembly *disass)
* *
******************************************************************************/
-static GDelayedDisassembly *g_delayed_disassembly_new(const GOpenidaBinary *binary, GBinPart **parts, size_t count, GCodeBuffer *buffer)
+static GDelayedDisassembly *g_delayed_disassembly_new(const GLoadedBinary *binary, GBinPart **parts, size_t count, GCodeBuffer *buffer)
{
GDelayedDisassembly *result; /* Tâche à retourner */
result = g_object_new(G_TYPE_DELAYED_DISASSEMBLY, NULL);
result->binary = binary;
- result->format = g_openida_binary_get_format(binary);
+ result->format = g_loaded_binary_get_format(binary);
result->parts = parts;
result->count = count;
@@ -381,7 +381,7 @@ static void build_disass_prologue(GCodeBuffer *buffer, const char *filename, con
* *
******************************************************************************/
-void disassemble_binary(GOpenidaBinary *binary, GBinPart **parts, size_t parts_count, GArchInstruction **instrs, GCodeBuffer **buffer)
+void disassemble_binary(GLoadedBinary *binary, GBinPart **parts, size_t parts_count, GArchInstruction **instrs, GCodeBuffer **buffer)
{
const uint8_t *data; /* Données binaires brutes */
off_t length; /* Quantité de ces données */
@@ -395,8 +395,8 @@ void disassemble_binary(GOpenidaBinary *binary, GBinPart **parts, size_t parts_c
*buffer = g_code_buffer_new();
- data = g_openida_binary_get_data(binary, &length);
- build_disass_prologue(*buffer, g_openida_binary_get_filename(binary), data, length);
+ data = g_loaded_binary_get_data(binary, &length);
+ build_disass_prologue(*buffer, g_loaded_binary_get_filename(binary, true), data, length);
disass = g_delayed_disassembly_new(binary, parts, parts_count, *buffer);
diff --git a/src/analysis/disass/disassembler.h b/src/analysis/disass/disassembler.h
index 2c5adef..8cca194 100644
--- a/src/analysis/disass/disassembler.h
+++ b/src/analysis/disass/disassembler.h
@@ -31,7 +31,7 @@
/* Procède à la décompilation des routines d'un fichier donné. */
-void disassemble_binary(GOpenidaBinary *, GBinPart **parts, size_t parts_count, GArchInstruction **, GCodeBuffer **);
+void disassemble_binary(GLoadedBinary *, GBinPart **parts, size_t parts_count, GArchInstruction **, GCodeBuffer **);
diff --git a/src/analysis/disass/fetch.c b/src/analysis/disass/fetch.c
index 6bd9795..a1df5e3 100644
--- a/src/analysis/disass/fetch.c
+++ b/src/analysis/disass/fetch.c
@@ -45,7 +45,7 @@
* *
******************************************************************************/
-GArchInstruction *disassemble_binary_parts(const GOpenidaBinary *binary, GBinPart **parts, size_t count, GtkExtStatusBar *statusbar, guint id)
+GArchInstruction *disassemble_binary_parts(const GLoadedBinary *binary, GBinPart **parts, size_t count, GtkExtStatusBar *statusbar, guint id)
{
GArchInstruction *result; /* Liste d'instr. à renvoyer */
GBinFormat *format; /* Format du fichier binaire */
@@ -69,9 +69,9 @@ GArchInstruction *disassemble_binary_parts(const GOpenidaBinary *binary, GBinPar
result = NULL;
- format = G_BIN_FORMAT(g_openida_binary_get_format(binary));
+ format = G_BIN_FORMAT(g_loaded_binary_get_format(binary));
proc = get_arch_processor_from_format(G_EXE_FORMAT(format));
- bin_data = g_openida_binary_get_data(binary, &bin_length);
+ bin_data = g_loaded_binary_get_data(binary, &bin_length);
/* Préparation du suivi de la progression */
diff --git a/src/analysis/disass/fetch.h b/src/analysis/disass/fetch.h
index 09bb584..89c3226 100644
--- a/src/analysis/disass/fetch.h
+++ b/src/analysis/disass/fetch.h
@@ -31,7 +31,7 @@
/* Procède au désassemblage basique d'un contenu binaire. */
-GArchInstruction *disassemble_binary_parts(const GOpenidaBinary *, GBinPart **, size_t, GtkExtStatusBar *, guint);
+GArchInstruction *disassemble_binary_parts(const GLoadedBinary *, GBinPart **, size_t, GtkExtStatusBar *, guint);