summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2014-10-06 20:52:21 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2014-10-06 20:52:21 (GMT)
commit1d5f7f28f92251dc4d3bff8d87b3e3052ab9cab2 (patch)
tree1ad4346a8cbcd8379850f68d04cb8757371c05e1
parentada6b756efd6ca109f6c46aa4d3eb11c17ad6b84 (diff)
Got prepared to disassemble some ARMv7 instructions.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@409 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
-rw-r--r--ChangeLog53
-rw-r--r--src/analysis/disass/fetch.c85
-rw-r--r--src/analysis/disass/fetch.h4
-rw-r--r--src/arch/arm/Makefile.am1
-rw-r--r--src/arch/arm/context.c325
-rw-r--r--src/arch/arm/context.h84
-rw-r--r--src/arch/arm/instruction-int.h1
-rw-r--r--src/arch/arm/instruction.c31
-rw-r--r--src/arch/arm/instruction.h4
-rw-r--r--src/arch/arm/v7/Makefile.am1
-rw-r--r--src/arch/arm/v7/arm.c414
-rw-r--r--src/arch/arm/v7/arm.h39
-rw-r--r--src/arch/arm/v7/instruction.c6
-rw-r--r--src/arch/arm/v7/instruction.h2
-rw-r--r--src/arch/arm/v7/processor.c77
-rw-r--r--src/arch/dalvik/context.c2
-rw-r--r--src/arch/processor-int.h4
-rw-r--r--src/arch/processor.c37
-rw-r--r--src/arch/processor.h5
-rwxr-xr-xsrc/common/Makefile.am1
-rw-r--r--src/common/bconst.h572
-rw-r--r--src/format/elf/symbols.c2
22 files changed, 1731 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog
index 700c8d4..8aa8068 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,56 @@
+14-10-06 Cyrille Bagard <nocbos@gmail.com>
+
+ * src/analysis/disass/fetch.c:
+ Disassemble executable code like raw code.
+
+ * src/analysis/disass/fetch.h:
+ Clean the code.
+
+ * src/arch/arm/context.c:
+ * src/arch/arm/context.h:
+ New entries: define a context for disassembling ARM code.
+
+ * src/arch/arm/instruction.c:
+ * src/arch/arm/instruction.h:
+ Typo (armv7 -> arm).
+
+ * src/arch/arm/instruction-int.h:
+ Store the name of an ARM instruction.
+
+ * src/arch/arm/Makefile.am:
+ Add the 'context.[ch]' files to libarcharm_la_SOURCES.
+
+ * src/arch/arm/v7/arm.c:
+ * src/arch/arm/v7/arm.h:
+ New entries: get prepared to disassemble some ARMv7 instructions.
+
+ * src/arch/arm/v7/instruction.c:
+ * src/arch/arm/v7/instruction.h:
+ Build an ARM instruction with a name.
+
+ * src/arch/arm/v7/Makefile.am:
+ Add the 'arm.[ch]' files to libarcharmv7_la_SOURCES.
+
+ * src/arch/arm/v7/processor.c:
+ Update code.
+
+ * src/arch/dalvik/context.c:
+ Typo.
+
+ * src/arch/processor.c:
+ * src/arch/processor.h:
+ * src/arch/processor-int.h:
+ Provide a new way to disassemble code.
+
+ * src/common/bconst.h:
+ New entry: create some macros for binary constants.
+
+ * src/common/Makefile.am:
+ Add the 'bconst.h' file to libcommon_la_SOURCES.
+
+ * src/format/elf/symbols.c:
+ Define a small size for symbols and debugging.
+
14-10-01 Cyrille Bagard <nocbos@gmail.com>
* configure.ac:
diff --git a/src/analysis/disass/fetch.c b/src/analysis/disass/fetch.c
index 763b37a..97cad33 100644
--- a/src/analysis/disass/fetch.c
+++ b/src/analysis/disass/fetch.c
@@ -36,7 +36,11 @@
+/* Procède au désassemblage basique d'un contenu binaire. */
+static GArchInstruction *load_raw_binary(const GLoadedBinary *, const vmpa2t *, off_t, GtkExtStatusBar *, bstatus_id_t);
+/* Procède au désassemblage d'un contenu binaire exécutable. */
+static GArchInstruction *load_code_binary(const GLoadedBinary *, const vmpa2t *, off_t, GtkExtStatusBar *, bstatus_id_t);
@@ -58,7 +62,7 @@
* *
******************************************************************************/
-GArchInstruction *load_raw_binary(const GLoadedBinary *binary, const vmpa2t *base, off_t end, GtkExtStatusBar *statusbar, bstatus_id_t id)
+static GArchInstruction *load_raw_binary(const GLoadedBinary *binary, const vmpa2t *base, off_t end, GtkExtStatusBar *statusbar, bstatus_id_t id)
{
GArchInstruction *result; /* Liste d'instr. à renvoyer */
GBinFormat *format; /* Format du fichier binaire */
@@ -110,6 +114,79 @@ GArchInstruction *load_raw_binary(const GLoadedBinary *binary, const vmpa2t *bas
}
+/******************************************************************************
+* *
+* Paramètres : binary = représentation de binaire chargé. *
+* parts = parties binaires à désassembler. *
+* count = nombre de parties à traiter. *
+* statusbar = barre de statut avec progression à mettre à jour.*
+* id = identifiant du message affiché à l'utilisateur. *
+* *
+* Description : Procède au désassemblage d'un contenu binaire exécutable. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GArchInstruction *load_code_binary(const GLoadedBinary *binary, const vmpa2t *base, off_t end, GtkExtStatusBar *statusbar, bstatus_id_t id)
+{
+ GArchInstruction *result; /* Liste d'instr. à renvoyer */
+ GBinFormat *format; /* Format du fichier binaire */
+ GArchProcessor *proc; /* Architecture du binaire */
+ off_t bin_length; /* Taille des données à lire */
+ bin_t *bin_data; /* Données binaires à lire */
+ vmpa2t pos; /* Boucle de parcours */
+ vmpa2t prev; /* Boucle de parcours */
+ off_t old_phy; /* Ancienne position physique */
+ GArchInstruction *instr; /* Instruction décodée */
+ off_t new_phy; /* Nouvelle position physique */
+ mrange_t range; /* Couverture de l'instruction */
+
+ result = NULL;
+
+ format = G_BIN_FORMAT(g_loaded_binary_get_format(binary));
+ proc = get_arch_processor_from_format(G_EXE_FORMAT(format));
+ bin_data = g_loaded_binary_get_data(binary, &bin_length);
+
+ copy_vmpa(&pos, base);
+ copy_vmpa(&prev, base);
+
+ old_phy = get_phy_addr(&prev);
+
+ while (old_phy < end)
+ {
+ instr = g_arch_processor_disassemble(proc, NULL, bin_data, &pos, end);
+
+ if (instr == NULL)
+ instr = g_raw_instruction_new_array(bin_data, MDS_32_BITS, 1, &pos, end,
+ g_arch_processor_get_endianness(proc));
+ if (instr == NULL) printf(" Break !!!\n");
+ if (instr == NULL) break;
+
+ new_phy = get_phy_addr(&pos);
+ init_mrange(&range, &prev, new_phy - old_phy);
+
+ g_arch_instruction_set_range(instr, &range);
+
+ g_arch_instruction_add_to_list(&result, instr);
+
+ copy_vmpa(&prev, &pos);
+ old_phy = get_phy_addr(&prev);
+
+ //done += (new_phy - old_phy);
+ //gtk_extended_status_bar_update_activity(statusbar, id, done * 1.0 / sum);
+
+ }
+
+ return result;
+
+}
+
+
+
+
@@ -203,9 +280,9 @@ GArchInstruction *disassemble_binary_content(const GLoadedBinary *binary, GtkExt
break;
case STP_ROUTINE:
- instr = load_raw_binary(binary, border,
- get_phy_addr(border) + length,
- statusbar, id);
+ instr = load_code_binary(binary, border,
+ get_phy_addr(border) + length,
+ statusbar, id);
break;
default:
diff --git a/src/analysis/disass/fetch.h b/src/analysis/disass/fetch.h
index b9b3bb4..96d04a2 100644
--- a/src/analysis/disass/fetch.h
+++ b/src/analysis/disass/fetch.h
@@ -32,10 +32,6 @@
-GArchInstruction *load_raw_binary(const GLoadedBinary *binary, const vmpa2t *base, off_t end, GtkExtStatusBar *statusbar, bstatus_id_t id);
-
-
-
/* Procède au désassemblage basique d'un contenu binaire. */
GArchInstruction *disassemble_binary_content(const GLoadedBinary *, GtkExtStatusBar *, bstatus_id_t);
diff --git a/src/arch/arm/Makefile.am b/src/arch/arm/Makefile.am
index 9bf0fe9..1c9ace8 100644
--- a/src/arch/arm/Makefile.am
+++ b/src/arch/arm/Makefile.am
@@ -3,6 +3,7 @@ noinst_LTLIBRARIES = libarcharm.la
libarcharm_la_SOURCES = \
cond.h \
+ context.h context.c \
instruction-int.h \
instruction.h instruction.c \
processor.h processor.c \
diff --git a/src/arch/arm/context.c b/src/arch/arm/context.c
new file mode 100644
index 0000000..c86b190
--- /dev/null
+++ b/src/arch/arm/context.c
@@ -0,0 +1,325 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * context.c - contexte lié à l'exécution d'un processeur
+ *
+ * Copyright (C) 2014 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * 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 "context.h"
+
+
+#include "../context-int.h"
+#include "../../decomp/context-int.h"
+
+
+
+/* ------------------------ MANIPULATION GLOBALE DU CONTEXTE ------------------------ */
+
+
+/* Définition d'un contexte pour processeur ARM (instance) */
+struct _GArmContext
+{
+ GProcContext parent; /* A laisser en premier */
+
+};
+
+
+/* Définition d'un contexte pour processeur ARM (classe) */
+struct _GArmContextClass
+{
+ GProcContextClass parent; /* A laisser en premier */
+
+};
+
+
+/* Initialise la classe des contextes de processeur ARM. */
+static void g_arm_context_class_init(GArmContextClass *);
+
+/* Initialise une instance de contexte de processeur ARM. */
+static void g_arm_context_init(GArmContext *);
+
+/* Supprime toutes les références externes. */
+static void g_arm_context_dispose(GArmContext *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_arm_context_finalize(GArmContext *);
+
+
+
+/* ------------------------- CONTEXTE POUR LA DECOMPILATION ------------------------- */
+
+
+/* Définition d'un contexte pour décompilation ARM (instance) */
+struct _GArmDContext
+{
+ GDecContext parent; /* A laisser en premier */
+
+ GDecInstruction *this; /* Représentation de la classe */
+ GHashTable *args; /* Correspondance arg./pseudo */
+ GHashTable *locals; /* Correspondance var./pseudo */
+ size_t locals_count; /* Quantité de var. locales */
+
+};
+
+
+/* Définition d'un contexte pour décompilation ARM (classe) */
+struct _GArmDContextClass
+{
+ GDecContextClass parent; /* A laisser en premier */
+
+};
+
+
+/* Initialise la classe des contextes de décompilation ARM. */
+static void g_arm_dcontext_class_init(GArmDContextClass *);
+
+/* Initialise une instance de contexte de décompilation ARM. */
+static void g_arm_dcontext_init(GArmDContext *);
+
+/* Supprime toutes les références externes. */
+static void g_arm_dcontext_dispose(GArmDContext *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_arm_dcontext_finalize(GArmDContext *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* MANIPULATION GLOBALE DU CONTEXTE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type définit par la GLib pour le contexte de processeur ARM. */
+G_DEFINE_TYPE(GArmContext, g_arm_context, G_TYPE_PROC_CONTEXT);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des contextes de processeur ARM. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_arm_context_class_init(GArmContextClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_arm_context_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_arm_context_finalize;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : ctx = instance à initialiser. *
+* *
+* Description : Initialise une instance de contexte de processeur ARM. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_arm_context_init(GArmContext *ctx)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : ctx = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_arm_context_dispose(GArmContext *ctx)
+{
+ G_OBJECT_CLASS(g_arm_context_parent_class)->dispose(G_OBJECT(ctx));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : ctx = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_arm_context_finalize(GArmContext *ctx)
+{
+ G_OBJECT_CLASS(g_arm_context_parent_class)->finalize(G_OBJECT(ctx));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Crée un contexte pour l'exécution du processeur ARM. *
+* *
+* Retour : Contexte mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArmContext *g_arm_context_new(void)
+{
+ GArmContext *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_ARM_CONTEXT, NULL);
+
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* CONTEXTE POUR LA DECOMPILATION */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type définit par la GLib pour le contexte de décompilation ARM. */
+G_DEFINE_TYPE(GArmDContext, g_arm_dcontext, G_TYPE_DEC_CONTEXT);
+
+
+/******************************************************************************
+* *
+* Paramètres : class = classe à initialiser. *
+* *
+* Description : Initialise la classe des contextes de décompilation ARM. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_arm_dcontext_class_init(GArmDContextClass *class)
+{
+ GObjectClass *object; /* Autre version de la classe */
+
+ object = G_OBJECT_CLASS(class);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_arm_dcontext_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_arm_dcontext_finalize;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : ctx = instance à initialiser. *
+* *
+* Description : Initialise une instance de contexte de décompilation ARM. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_arm_dcontext_init(GArmDContext *ctx)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : ctx = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_arm_dcontext_dispose(GArmDContext *ctx)
+{
+ G_OBJECT_CLASS(g_arm_dcontext_parent_class)->dispose(G_OBJECT(ctx));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : ctx = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_arm_dcontext_finalize(GArmDContext *ctx)
+{
+ G_OBJECT_CLASS(g_arm_dcontext_parent_class)->finalize(G_OBJECT(ctx));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Crée un contexte pour la décompilation ARM. *
+* *
+* Retour : Contexte mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArmDContext *g_arm_dcontext_new(void)
+{
+ GArmDContext *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_ARM_DCONTEXT, NULL);
+
+ return result;
+
+}
diff --git a/src/arch/arm/context.h b/src/arch/arm/context.h
new file mode 100644
index 0000000..5fc6fab
--- /dev/null
+++ b/src/arch/arm/context.h
@@ -0,0 +1,84 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * context.h - prototypes pour le contexte lié à l'exécution d'un processeur
+ *
+ * Copyright (C) 2014 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _ARCH_ARM_CONTEXT_H
+#define _ARCH_ARM_CONTEXT_H
+
+
+#include <glib-object.h>
+
+
+
+/* ------------------------ MANIPULATION GLOBALE DU CONTEXTE ------------------------ */
+
+
+#define G_TYPE_ARM_CONTEXT g_arm_context_get_type()
+#define G_ARM_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_arm_context_get_type(), GArmContext))
+#define G_IS_ARM_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_arm_context_get_type()))
+#define G_ARM_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_ARM_CONTEXT, GGArmContextClass))
+#define G_IS_ARM_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_ARM_CONTEXT))
+#define G_ARM_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_ARM_CONTEXT, GGArmContextClass))
+
+
+/* Définition d'un contexte pour processeur ARM (instance) */
+typedef struct _GArmContext GArmContext;
+
+/* Définition d'un contexte pour processeur ARM (classe) */
+typedef struct _GArmContextClass GArmContextClass;
+
+
+/* Indique le type définit par la GLib pour le contexte de processeur ARM. */
+GType g_arm_context_get_type(void);
+
+/* Crée un contexte pour l'exécution du processeur ARM. */
+GArmContext *g_arm_context_new(void);
+
+
+
+/* ------------------------- CONTEXTE POUR LA DECOMPILATION ------------------------- */
+
+
+#define G_TYPE_ARM_DCONTEXT g_arm_dcontext_get_type()
+#define G_ARM_DCONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_arm_dcontext_get_type(), GArmDContext))
+#define G_IS_ARM_DCONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_arm_dcontext_get_type()))
+#define G_ARM_DCONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_ARM_DCONTEXT, GGArmDContextClass))
+#define G_IS_ARM_DCONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_ARM_DCONTEXT))
+#define G_ARM_DCONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_ARM_DCONTEXT, GGArmDContextClass))
+
+
+/* Définition d'un contexte pour décompilation ARM (instance) */
+typedef struct _GArmDContext GArmDContext;
+
+/* Définition d'un contexte pour décompilation ARM (classe) */
+typedef struct _GArmDContextClass GArmDContextClass;
+
+
+/* Indique le type définit par la GLib pour le contexte de décompilation ARM. */
+GType g_arm_dcontext_get_type(void);
+
+/* Crée un contexte pour la décompilation ARM. */
+GArmDContext *g_arm_dcontext_new(void);
+
+
+
+#endif /* _ARCH_ARM_CONTEXT_H */
diff --git a/src/arch/arm/instruction-int.h b/src/arch/arm/instruction-int.h
index d87bcc4..0dc848d 100644
--- a/src/arch/arm/instruction-int.h
+++ b/src/arch/arm/instruction-int.h
@@ -35,6 +35,7 @@ struct _GArmInstruction
{
GArchInstruction parent; /* A laisser en premier */
+ const char *keyword; /* Nom clef de l'instruction */
ArmCondCode cond; /* Condition d'exécution */
};
diff --git a/src/arch/arm/instruction.c b/src/arch/arm/instruction.c
index 5ea3926..c315bae 100644
--- a/src/arch/arm/instruction.c
+++ b/src/arch/arm/instruction.c
@@ -40,6 +40,9 @@ static void g_arm_instruction_dispose(GArmInstruction *);
/* Procède à la libération totale de la mémoire. */
static void g_arm_instruction_finalize(GArmInstruction *);
+/* Fournit le nom humain de l'instruction manipulée. */
+static const char *g_arm_instruction_get_keyword(const GArmInstruction *, AsmSyntax);
+
/* Indique le type défini pour une représentation d'une instruction ARM. */
@@ -61,12 +64,16 @@ G_DEFINE_TYPE(GArmInstruction, g_arm_instruction, G_TYPE_ARM_INSTRUCTION);
static void g_arm_instruction_class_init(GArmInstructionClass *klass)
{
GObjectClass *object_class; /* Autre version de la classe */
+ GArchInstructionClass *instr; /* Encore une autre vision... */
object_class = G_OBJECT_CLASS(klass);
+ instr = G_ARCH_INSTRUCTION_CLASS(klass);
object_class->dispose = (GObjectFinalizeFunc/* ! */)g_arm_instruction_dispose;
object_class->finalize = (GObjectFinalizeFunc)g_arm_instruction_finalize;
+ instr->get_key = (get_instruction_keyword_fc)g_arm_instruction_get_keyword;
+
}
@@ -128,6 +135,26 @@ static void g_arm_instruction_finalize(GArmInstruction *instr)
/******************************************************************************
* *
+* Paramètres : instr = instruction à traiter. *
+* syntax = type de représentation demandée. *
+* *
+* Description : Fournit le nom humain de l'instruction manipulée. *
+* *
+* Retour : Mot clef de bas niveau. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static const char *g_arm_instruction_get_keyword(const GArmInstruction *instr, AsmSyntax syntax)
+{
+ return instr->keyword;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : instr = instruction ARM à mettre à jour. *
* cond = condition d'exécution de l'instruction. *
* *
@@ -139,7 +166,7 @@ static void g_arm_instruction_finalize(GArmInstruction *instr)
* *
******************************************************************************/
-void g_armv7_instruction_set_cond(GArmInstruction *instr, ArmCondCode cond)
+void g_arm_instruction_set_cond(GArmInstruction *instr, ArmCondCode cond)
{
instr->cond = cond;
@@ -158,7 +185,7 @@ void g_armv7_instruction_set_cond(GArmInstruction *instr, ArmCondCode cond)
* *
******************************************************************************/
-ArmCondCode g_armv7_instruction_get_cond(const GArmInstruction *instr)
+ArmCondCode g_arm_instruction_get_cond(const GArmInstruction *instr)
{
return instr->cond;
diff --git a/src/arch/arm/instruction.h b/src/arch/arm/instruction.h
index 0736015..ecd9919 100644
--- a/src/arch/arm/instruction.h
+++ b/src/arch/arm/instruction.h
@@ -52,10 +52,10 @@ typedef struct _GArmInstructionClass GArmInstructionClass;
GType g_arm_instruction_get_type(void);
/* Définit les conditions d'exécution d'une instruction ARM. */
-void g_armv7_instruction_set_cond(GArmInstruction *, ArmCondCode);
+void g_arm_instruction_set_cond(GArmInstruction *, ArmCondCode);
/* Indique les conditions d'exécution d'une instruction ARM. */
-ArmCondCode g_armv7_instruction_get_cond(const GArmInstruction *);
+ArmCondCode g_arm_instruction_get_cond(const GArmInstruction *);
diff --git a/src/arch/arm/v7/Makefile.am b/src/arch/arm/v7/Makefile.am
index 1ac1c76..dc095ed 100644
--- a/src/arch/arm/v7/Makefile.am
+++ b/src/arch/arm/v7/Makefile.am
@@ -2,6 +2,7 @@
noinst_LTLIBRARIES = libarcharmv7.la
libarcharmv7_la_SOURCES = \
+ arm.h arm.c \
instruction.h instruction.c \
processor.h processor.c \
register.h register.c
diff --git a/src/arch/arm/v7/arm.c b/src/arch/arm/v7/arm.c
new file mode 100644
index 0000000..4953b6b
--- /dev/null
+++ b/src/arch/arm/v7/arm.c
@@ -0,0 +1,414 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * arm.c - désassemblage des instructions ARMv7
+ *
+ * Copyright (C) 2014 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * 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 "arm.h"
+
+
+#include <stdint.h>
+
+
+#include "../../../common/bconst.h"
+
+
+
+
+/* Désassemble une instruction ARMv7 de données ou autre. */
+static GArchInstruction *process_armv7_data_processing_and_miscellaneous_instructions(uint32_t);
+
+/* Désassemble une instruction ARMv7 de données de registre. */
+static GArchInstruction *process_armv7_data_processing_register(uint32_t);
+
+
+
+
+// process_armv7_instruction_set_encoding
+
+#define process_armv7_load_store_word_and_unsigned_byte(raw) NULL
+#define process_armv7_load_store_word_and_unsigned_byte(raw) NULL
+#define process_armv7_media_instructions(raw) NULL
+#define process_armv7_branch_branch_with_link_and_block_data_transfer(raw) NULL
+#define process_armv7_coprocessor_instructions_and_Supervisor_call(raw) NULL
+#define process_armv7_unconditional_instructions(raw) NULL
+
+
+// process_armv7_data_processing_and_miscellaneous_instructions
+
+#define process_armv7_data_processing_register_shifted_register(raw) NULL
+#define process_armv7_extra_load_store_instructions(raw) NULL
+#define process_armv7_miscellaneous_instructions(raw) NULL
+#define process_armv7_halfword_multiply_and_multiply_accumulate(raw) NULL
+#define process_armv7_multiply_and_multiply_accumulate(raw) NULL
+#define process_armv7_synchronization_primitives(raw) NULL
+#define process_armv7_extra_load_store_instructions_unprivileged(raw) NULL
+#define process_armv7_extra_load_store_instructions(raw) NULL
+#define process_armv7_data_processing_immediate(raw) NULL
+#define armv7_read_instr_mov_immediate(raw) NULL
+#define armv7_read_instr_movt(raw) NULL
+#define process_armv7_msr_immediate_and_hints(raw) NULL
+
+
+// process_armv7_data_processing_register
+
+#define armv7_read_instr_and_register(raw) NULL
+#define armv7_read_instr_eor_register(raw) NULL
+#define armv7_read_instr_sub_register(raw) NULL
+#define armv7_read_instr_rsb_register(raw) NULL
+#define armv7_read_instr_add_register(raw) NULL
+#define armv7_read_instr_adc_register(raw) NULL
+#define armv7_read_instr_sbc_register(raw) NULL
+#define armv7_read_instr_rsc_register(raw) NULL
+#define armv7_read_instr_tst_register(raw) NULL
+#define armv7_read_instr_teq_register(raw) NULL
+#define armv7_read_instr_cmp_register(raw) NULL
+#define armv7_read_instr_cmn_register(raw) NULL
+#define armv7_read_instr_orr_register(raw) NULL
+#define armv7_read_instr_mov_register_arm(raw) NULL
+#define armv7_read_instr_lsl_immediate(raw) NULL
+#define armv7_read_instr_lsr_immediate(raw) NULL
+#define armv7_read_instr_asr_immediate(raw) NULL
+#define armv7_read_instr_rrx(raw) NULL
+#define armv7_read_instr_ror_immediate(raw) NULL
+#define armv7_read_instr_bic_register(raw) NULL
+#define armv7_read_instr_mvn_register(raw) NULL
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : raw = donnée brute de 32 bits à désassembler. *
+* *
+* Description : Désassemble une instruction ARMv7 classique. *
+* *
+* Retour : Instruction mise en place ou NULL en cas d'échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchInstruction *process_armv7_instruction_set_encoding(uint32_t raw)
+{
+ GArchInstruction *result; /* Instruction à renvoyer */
+ uint32_t cond; /* Champ 'cond' à retrouver */
+ uint32_t op1; /* Champ 'op1' à retrouver */
+ uint32_t op; /* Champ 'op' à retrouver */
+
+ /**
+ * Suit les directives de :
+ * § A5.1 ARM instruction set encoding
+ */
+
+ result = NULL;
+
+ cond = (raw >> 28) & 0xf;
+ op1 = (raw >> 25) & 0x7;
+ op = (raw >> 4) & 0x1;
+
+
+ if (cond != b1111)
+ {
+ if ((op1 & b110) == b000)
+ result = process_armv7_data_processing_and_miscellaneous_instructions(raw);
+
+ else if (op1 == b010)
+ result = process_armv7_load_store_word_and_unsigned_byte(raw);
+
+ else if (op1 == b011)
+ {
+ if (op == b0)
+ result = process_armv7_load_store_word_and_unsigned_byte(raw);
+
+ else
+ result = process_armv7_media_instructions(raw);
+
+ }
+
+ else if ((op1 & b110) == b100)
+ result = process_armv7_branch_branch_with_link_and_block_data_transfer(raw);
+
+ else if ((op1 & b110) == b110)
+ result = process_armv7_coprocessor_instructions_and_Supervisor_call(raw);
+
+ }
+
+ else /* if (cond == b1111) */
+ result = process_armv7_unconditional_instructions(raw);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : raw = donnée brute de 32 bits à désassembler. *
+* *
+* Description : Désassemble une instruction ARMv7 de données ou autre. *
+* *
+* Retour : Instruction mise en place ou NULL en cas d'échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GArchInstruction *process_armv7_data_processing_and_miscellaneous_instructions(uint32_t raw)
+{
+ GArchInstruction *result; /* Instruction à retourner */
+ uint32_t op; /* Champ 'op' à retrouver */
+ uint32_t op1; /* Champ 'op1' à retrouver */
+ uint32_t op2; /* Champ 'op2' à retrouver */
+
+ /**
+ * Suit les directives de :
+ * § A5.2 Data-processing and miscellaneous instructions
+ */
+
+ result = NULL;
+
+ if (raw == 0xe1a0000a)
+ printf(" ---> data proc & misc\n");
+
+ op = (raw >> 25) & 0x1;
+ op1 = (raw >> 20) & 0x1f;
+ op2 = (raw >> 4) & 0xf;
+
+ if (op == b0)
+ {
+ if ((op1 & b11001) != b10000)
+ {
+ if ((op2 & b0001) == b0000)
+ result = process_armv7_data_processing_register(raw);
+
+ else if ((op2 & b1001) == b0001)
+ result = process_armv7_data_processing_register_shifted_register(raw);
+
+ if (result != NULL) goto padpami_found;
+
+ }
+
+ else /* if ((op1 & b11001) == b10000) */
+ {
+ if ((op2 & b1000) == b0000)
+ result = process_armv7_miscellaneous_instructions(raw);
+
+ else if ((op2 & b1001) == b1000)
+ result = process_armv7_halfword_multiply_and_multiply_accumulate(raw);
+
+ if (result != NULL) goto padpami_found;
+
+ }
+
+ if ((op1 & b10000) == b00000)
+ {
+ if (op2 == b1001)
+ result = process_armv7_multiply_and_multiply_accumulate(raw);
+
+ if (result != NULL) goto padpami_found;
+
+ }
+
+ if ((op1 & b10000) == b10000)
+ {
+ if (op2 == b1001)
+ result = process_armv7_synchronization_primitives(raw);
+
+ if (result != NULL) goto padpami_found;
+
+ }
+
+ if ((op1 & b10010) != b00010)
+ {
+ if (op2 == b1011)
+ result = process_armv7_extra_load_store_instructions(raw);
+
+ else if ((op2 & b1101) == b1101)
+ result = process_armv7_extra_load_store_instructions(raw);
+
+ if (result != NULL) goto padpami_found;
+
+ }
+
+ else /* if ((op1 & b10010) != b00010) */
+ {
+ if (op2 == b1011)
+ result = process_armv7_extra_load_store_instructions_unprivileged(raw);
+
+ else if ((op2 & b1101) == b1101)
+ result = process_armv7_extra_load_store_instructions(raw);
+
+ if (result != NULL) goto padpami_found;
+
+ }
+
+ }
+
+ else
+ {
+ if ((op1 & b11001) != b10000)
+ result = process_armv7_data_processing_immediate(raw);
+
+ else if (op1 == b10000)
+ result = armv7_read_instr_mov_immediate(raw);
+
+ else if (op1 == b10100)
+ result = armv7_read_instr_movt(raw);
+
+ else if ((op1 & b11011) == b10010)
+ result = process_armv7_msr_immediate_and_hints(raw);
+
+ }
+
+ padpami_found:
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : raw = donnée brute de 32 bits à désassembler. *
+* *
+* Description : Désassemble une instruction ARMv7 de données de registre. *
+* *
+* Retour : Instruction mise en place ou NULL en cas d'échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GArchInstruction *process_armv7_data_processing_register(uint32_t raw)
+{
+ GArchInstruction *result; /* Instruction à retourner */
+ uint32_t op; /* Champ 'op' à retrouver */
+ uint32_t imm5; /* Champ 'imm5' à retrouver */
+ uint32_t op2; /* Champ 'op2' à retrouver */
+
+ /**
+ * Suit les directives de :
+ * § A5.2.1 Data-processing (register)
+ */
+
+ result = NULL;
+
+ if (raw == 0xe1a0000a)
+ printf(" ---> data proc register !\n");
+
+ op = (raw >> 20) & 0x1f;
+ imm5 = (raw >> 7) & 0x1f;
+ op2 = (raw >> 5) & 0x3;
+
+ if ((op & b11110) == b00000)
+ result = armv7_read_instr_and_register(raw);
+
+ else if ((op & b11110) == b00010)
+ result = armv7_read_instr_eor_register(raw);
+
+ else if ((op & b11110) == b00100)
+ result = armv7_read_instr_sub_register(raw);
+
+ else if ((op & b11110) == b00110)
+ result = armv7_read_instr_rsb_register(raw);
+
+ else if ((op & b11110) == b01000)
+ result = armv7_read_instr_add_register(raw);
+
+ else if ((op & b11110) == b01010)
+ result = armv7_read_instr_adc_register(raw);
+
+ else if ((op & b11110) == b01100)
+ result = armv7_read_instr_sbc_register(raw);
+
+ else if ((op & b11110) == b01110)
+ result = armv7_read_instr_rsc_register(raw);
+
+ /*
+ else if ((op & b11001) == b10000)
+ result = process_armv7_data_processing_and_miscellaneous_instructions(raw);
+ */
+
+ else if (op == b10001)
+ result = armv7_read_instr_tst_register(raw);
+
+ else if (op == b10011)
+ result = armv7_read_instr_teq_register(raw);
+
+ else if (op == b10101)
+ result = armv7_read_instr_cmp_register(raw);
+
+ else if (op == b10111)
+ result = armv7_read_instr_cmn_register(raw);
+
+ else if ((op & b11110) == b11000)
+ result = armv7_read_instr_orr_register(raw);
+
+ else if ((op & b11110) == b11010)
+ {
+ if (op2 == b00)
+ {
+ if (imm5 == b00000)
+ {
+ result = armv7_read_instr_mov_register_arm(raw);
+ if (raw == 0xe1a0000a)
+ printf(" ----> GOT IT :: %p\n", result);
+ }
+
+ else
+ result = armv7_read_instr_lsl_immediate(raw);
+
+ }
+
+ else if (op2 == b01)
+ result = armv7_read_instr_lsr_immediate(raw);
+
+ else if (op2 == b10)
+ result = armv7_read_instr_asr_immediate(raw);
+
+ else if (op2 == b11)
+ {
+ if (imm5 == b00000)
+ result = armv7_read_instr_rrx(raw);
+
+ else
+ result = armv7_read_instr_ror_immediate(raw);
+
+ }
+
+ }
+
+ else if ((op & b11110) == b11100)
+ result = armv7_read_instr_bic_register(raw);
+
+ else if ((op & b11110) == b11110)
+ result = armv7_read_instr_mvn_register(raw);
+
+ return result;
+
+}
+
+
+
+
+
diff --git a/src/arch/arm/v7/arm.h b/src/arch/arm/v7/arm.h
new file mode 100644
index 0000000..b9c2fe4
--- /dev/null
+++ b/src/arch/arm/v7/arm.h
@@ -0,0 +1,39 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * arm.h - prototypes pour le désassemblage des instructions ARMv7
+ *
+ * Copyright (C) 2014 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _ARCH_ARM_V7_ARM_H
+#define _ARCH_ARM_V7_ARM_H
+
+
+#include "processor.h"
+#include "../context.h"
+#include "../../instruction.h"
+
+
+
+/* Désassemble une instruction ARMv7 classique. */
+GArchInstruction *process_armv7_instruction_set_encoding(uint32_t raw);
+
+
+
+#endif /* _ARCH_ARM_V7_ARM_H */
diff --git a/src/arch/arm/v7/instruction.c b/src/arch/arm/v7/instruction.c
index 0fc95c9..24135f3 100644
--- a/src/arch/arm/v7/instruction.c
+++ b/src/arch/arm/v7/instruction.c
@@ -146,7 +146,7 @@ static void g_armv7_instruction_finalize(GArmV7Instruction *instr)
/******************************************************************************
* *
-* Paramètres : - *
+* Paramètres : keyword = définition du nom humaine de l'instruction. *
* *
* Description : Crée une instruction pour l'architecture ARMv7. *
* *
@@ -156,12 +156,14 @@ static void g_armv7_instruction_finalize(GArmV7Instruction *instr)
* *
******************************************************************************/
-GArmV7Instruction *g_armv7_instruction_new(void)
+GArmV7Instruction *g_armv7_instruction_new(const char *keyword)
{
GArmV7Instruction *result; /* Structure à retourner */
result = g_object_new(G_TYPE_ARMV7_INSTRUCTION, NULL);
+ G_ARM_INSTRUCTION(result)->keyword = keyword;
+
return result;
}
diff --git a/src/arch/arm/v7/instruction.h b/src/arch/arm/v7/instruction.h
index 0265911..97ee31a 100644
--- a/src/arch/arm/v7/instruction.h
+++ b/src/arch/arm/v7/instruction.h
@@ -50,7 +50,7 @@ typedef struct _GArmV7InstructionClass GArmV7InstructionClass;
GType g_armv7_instruction_get_type(void);
/* Crée une instruction pour l'architecture ARMv7. */
-GArmV7Instruction *g_armv7_instruction_new(void);
+GArmV7Instruction *g_armv7_instruction_new(const char *);
/* Définit si une instruction ARMv7 met à jour les drapeaux. */
void g_armv7_instruction_define_setflags(GArmV7Instruction *, bool);
diff --git a/src/arch/arm/v7/processor.c b/src/arch/arm/v7/processor.c
index bcd44e9..3ce1623 100644
--- a/src/arch/arm/v7/processor.c
+++ b/src/arch/arm/v7/processor.c
@@ -24,7 +24,10 @@
#include "processor.h"
+#include "arm.h"
+#include "../context.h"
#include "../processor-int.h"
+#include "../../raw.h"
@@ -56,6 +59,9 @@ static void g_armv7_processor_dispose(GArmV7Processor *);
/* Procède à la libération totale de la mémoire. */
static void g_armv7_processor_finalize(GArmV7Processor *);
+/* Décode une instruction dans un flux de données. */
+static GArchInstruction *g_armv7_processor_disassemble(const GArmV7Processor *, GArmContext *, const bin_t *, vmpa2t *, phys_t);
+
/* Indique le type défini par la GLib pour le processeur ARMv7. */
@@ -77,12 +83,16 @@ G_DEFINE_TYPE(GArmV7Processor, g_armv7_processor, G_TYPE_ARM_PROCESSOR);
static void g_armv7_processor_class_init(GArmV7ProcessorClass *klass)
{
GObjectClass *object_class; /* Autre version de la classe */
+ GArchProcessorClass *proc; /* Encore une autre vision... */
object_class = G_OBJECT_CLASS(klass);
+ proc = G_ARCH_PROCESSOR_CLASS(klass);
object_class->dispose = (GObjectFinalizeFunc/* ! */)g_armv7_processor_dispose;
object_class->finalize = (GObjectFinalizeFunc)g_armv7_processor_finalize;
+ proc->disassemble = (disass_instr_fc)g_armv7_processor_disassemble;
+
}
@@ -171,3 +181,70 @@ GArmV7Processor *g_armv7_processor_new(void)
return result;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : proc = architecture visée par la procédure. *
+* ctx = contexte lié à l'exécution du processeur. *
+* data = flux de données à analyser. *
+* pos = position courante dans ce flux. [OUT] *
+* end = limite des données à analyser. *
+* *
+* Description : Désassemble une instruction dans un flux de données. *
+* *
+* Retour : Instruction mise en place ou NULL en cas d'échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GArchInstruction *g_armv7_processor_disassemble(const GArmV7Processor *proc, GArmContext *ctx, const bin_t *data, vmpa2t *pos, phys_t end)
+{
+ GArchInstruction *result; /* Instruction à renvoyer */
+ phys_t start; /* Point de départ de lecture */
+ uint32_t raw; /* Donnée 32 bits à analyser */
+
+
+
+ //printf("Position :: 0x%x\n", (unsigned int)get_phy_addr(pos));
+
+ // @ 0xae6c
+ // 0xe1a0000a
+
+ // 1110 0001 1010 0000 0000 0000 0000 1010
+
+
+ //exit(1);
+
+
+ raw = 0xe1a0000a;
+
+
+ start = get_phy_addr(pos);
+
+ if (!read_u32(&raw, data, &start, end, G_ARCH_PROCESSOR(proc)->endianness))
+ return NULL;
+
+
+ if (raw == 0xe1a0000a)
+ printf("read !!!!!!!\n");
+
+
+ /* TODO : thumb... */
+
+
+ result = process_armv7_instruction_set_encoding(raw);
+
+ if (result != NULL)
+ advance_vmpa(pos, 4);
+
+ else
+ result = g_raw_instruction_new_array(data, MDS_32_BITS, 1, pos, end,
+ G_ARCH_PROCESSOR(proc)->endianness);
+
+
+
+ return result;
+
+}
diff --git a/src/arch/dalvik/context.c b/src/arch/dalvik/context.c
index 74885d0..0eb8b48 100644
--- a/src/arch/dalvik/context.c
+++ b/src/arch/dalvik/context.c
@@ -140,7 +140,6 @@ static GDecInstruction *g_dalvik_dcontext_convert_register(GDalvikDContext *, GD
G_DEFINE_TYPE(GDalvikContext, g_dalvik_context, G_TYPE_PROC_CONTEXT);
-
/******************************************************************************
* *
* Paramètres : klass = classe à initialiser. *
@@ -291,7 +290,6 @@ bool g_dalvik_context_have_to_skip(GDalvikContext *ctx, vmpa_t addr)
G_DEFINE_TYPE(GDalvikDContext, g_dalvik_dcontext, G_TYPE_DEC_CONTEXT);
-
/******************************************************************************
* *
* Paramètres : class = classe à initialiser. *
diff --git a/src/arch/processor-int.h b/src/arch/processor-int.h
index c8263f7..23a6d60 100644
--- a/src/arch/processor-int.h
+++ b/src/arch/processor-int.h
@@ -55,6 +55,9 @@ typedef GDecContext * (* get_decomp_context_fc) (const GArchProcessor *);
/* Décode une instruction dans un flux de données. */
typedef GArchInstruction * (* decode_instruction_fc) (const GArchProcessor *, GProcContext *, const bin_t *, off_t *, off_t, vmpa_t, GBinFormat *);
+/* Désassemble une instruction dans un flux de données. */
+typedef GArchInstruction * (* disass_instr_fc) (const GArchProcessor *, GProcContext *, const bin_t *, vmpa2t *, phys_t);
+
/* Définition générique d'un processeur d'architecture (instance) */
struct _GArchProcessor
@@ -82,6 +85,7 @@ struct _GArchProcessorClass
GObjectClass parent; /* A laisser en premier */
decode_instruction_fc decode; /* Traduction en instructions */
+ disass_instr_fc disassemble; /* Traduction en instructions */
};
diff --git a/src/arch/processor.c b/src/arch/processor.c
index 67457d2..f7c8d85 100644
--- a/src/arch/processor.c
+++ b/src/arch/processor.c
@@ -274,6 +274,43 @@ GArchInstruction *g_arch_processor_decode_instruction(const GArchProcessor *proc
}
+/******************************************************************************
+* *
+* Paramètres : proc = architecture visée par la procédure. *
+* ctx = contexte lié à l'exécution du processeur. *
+* data = flux de données à analyser. *
+* pos = position courante dans ce flux. [OUT] *
+* end = limite des données à analyser. *
+* *
+* Description : Désassemble une instruction dans un flux de données. *
+* *
+* Retour : Instruction mise en place ou NULL en cas d'échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchInstruction *g_arch_processor_disassemble(const GArchProcessor *proc, GProcContext *ctx, const bin_t *data, vmpa2t *pos, phys_t end)
+{
+ GArchInstruction *result; /* Instruction à renvoyer */
+ vmpa2t back; /* Position sauvegardée */
+
+ copy_vmpa(&back, pos);
+
+ result = G_ARCH_PROCESSOR_GET_CLASS(proc)->disassemble(proc, ctx, data, pos, end);
+
+ if (result == NULL)
+ copy_vmpa(pos, &back);
+
+ return result;
+
+}
+
+
+
+
+
+
/* ---------------------------------------------------------------------------------- */
/* ARCHITECTURES DANS LEUR ENSEMBLE */
diff --git a/src/arch/processor.h b/src/arch/processor.h
index 32dfbdb..ac5d811 100644
--- a/src/arch/processor.h
+++ b/src/arch/processor.h
@@ -71,7 +71,10 @@ MemoryDataSize g_arch_processor_get_memory_size(const GArchProcessor *);
MemoryDataSize g_arch_processor_get_instruction_size(const GArchProcessor *);
/* Décode une instruction dans un flux de données. */
-GArchInstruction *g_arch_processor_decode_instruction(const GArchProcessor *, GProcContext *, const bin_t *, off_t *, off_t, vmpa_t, GBinFormat *);
+GArchInstruction *g_arch_processor_decode_instruction(const GArchProcessor *, GProcContext *, const bin_t *, off_t *, off_t, vmpa_t, GBinFormat *) __attribute__ ((deprecated));
+
+/* Désassemble une instruction dans un flux de données. */
+GArchInstruction *g_arch_processor_disassemble(const GArchProcessor *, GProcContext *, const bin_t *, vmpa2t *, phys_t);
diff --git a/src/common/Makefile.am b/src/common/Makefile.am
index da4f98e..7ec85ab 100755
--- a/src/common/Makefile.am
+++ b/src/common/Makefile.am
@@ -2,6 +2,7 @@
lib_LTLIBRARIES = libcommon.la
libcommon_la_SOURCES = \
+ bconst.h \
cpp.h \
dllist.h dllist.c \
endianness.h endianness.c \
diff --git a/src/common/bconst.h b/src/common/bconst.h
new file mode 100644
index 0000000..ac7b9ff
--- /dev/null
+++ b/src/common/bconst.h
@@ -0,0 +1,572 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * bconst.h - prototypes pour la capacité à disposer d'un format binaire pour constantes
+ *
+ * Copyright (C) 2014 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * 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 _COMMON_BCONST_H
+#define _COMMON_BCONST_H
+
+
+
+/**
+ * Constantes générée automatiquemet avec le script Python suivant :
+ *
+ * for l in range(1, 9):
+ *
+ * print('')
+ *
+ * for v in range(1 << l):
+ *
+ * print('#define b%s %d' % (format(v, '0{}b'.format(l)), v))
+ *
+ * print('')
+ *
+ */
+
+
+#define b0 0
+#define b1 1
+
+
+#define b00 0
+#define b01 1
+#define b10 2
+#define b11 3
+
+
+#define b000 0
+#define b001 1
+#define b010 2
+#define b011 3
+#define b100 4
+#define b101 5
+#define b110 6
+#define b111 7
+
+
+#define b0000 0
+#define b0001 1
+#define b0010 2
+#define b0011 3
+#define b0100 4
+#define b0101 5
+#define b0110 6
+#define b0111 7
+#define b1000 8
+#define b1001 9
+#define b1010 10
+#define b1011 11
+#define b1100 12
+#define b1101 13
+#define b1110 14
+#define b1111 15
+
+
+#define b00000 0
+#define b00001 1
+#define b00010 2
+#define b00011 3
+#define b00100 4
+#define b00101 5
+#define b00110 6
+#define b00111 7
+#define b01000 8
+#define b01001 9
+#define b01010 10
+#define b01011 11
+#define b01100 12
+#define b01101 13
+#define b01110 14
+#define b01111 15
+#define b10000 16
+#define b10001 17
+#define b10010 18
+#define b10011 19
+#define b10100 20
+#define b10101 21
+#define b10110 22
+#define b10111 23
+#define b11000 24
+#define b11001 25
+#define b11010 26
+#define b11011 27
+#define b11100 28
+#define b11101 29
+#define b11110 30
+#define b11111 31
+
+
+#define b000000 0
+#define b000001 1
+#define b000010 2
+#define b000011 3
+#define b000100 4
+#define b000101 5
+#define b000110 6
+#define b000111 7
+#define b001000 8
+#define b001001 9
+#define b001010 10
+#define b001011 11
+#define b001100 12
+#define b001101 13
+#define b001110 14
+#define b001111 15
+#define b010000 16
+#define b010001 17
+#define b010010 18
+#define b010011 19
+#define b010100 20
+#define b010101 21
+#define b010110 22
+#define b010111 23
+#define b011000 24
+#define b011001 25
+#define b011010 26
+#define b011011 27
+#define b011100 28
+#define b011101 29
+#define b011110 30
+#define b011111 31
+#define b100000 32
+#define b100001 33
+#define b100010 34
+#define b100011 35
+#define b100100 36
+#define b100101 37
+#define b100110 38
+#define b100111 39
+#define b101000 40
+#define b101001 41
+#define b101010 42
+#define b101011 43
+#define b101100 44
+#define b101101 45
+#define b101110 46
+#define b101111 47
+#define b110000 48
+#define b110001 49
+#define b110010 50
+#define b110011 51
+#define b110100 52
+#define b110101 53
+#define b110110 54
+#define b110111 55
+#define b111000 56
+#define b111001 57
+#define b111010 58
+#define b111011 59
+#define b111100 60
+#define b111101 61
+#define b111110 62
+#define b111111 63
+
+
+#define b0000000 0
+#define b0000001 1
+#define b0000010 2
+#define b0000011 3
+#define b0000100 4
+#define b0000101 5
+#define b0000110 6
+#define b0000111 7
+#define b0001000 8
+#define b0001001 9
+#define b0001010 10
+#define b0001011 11
+#define b0001100 12
+#define b0001101 13
+#define b0001110 14
+#define b0001111 15
+#define b0010000 16
+#define b0010001 17
+#define b0010010 18
+#define b0010011 19
+#define b0010100 20
+#define b0010101 21
+#define b0010110 22
+#define b0010111 23
+#define b0011000 24
+#define b0011001 25
+#define b0011010 26
+#define b0011011 27
+#define b0011100 28
+#define b0011101 29
+#define b0011110 30
+#define b0011111 31
+#define b0100000 32
+#define b0100001 33
+#define b0100010 34
+#define b0100011 35
+#define b0100100 36
+#define b0100101 37
+#define b0100110 38
+#define b0100111 39
+#define b0101000 40
+#define b0101001 41
+#define b0101010 42
+#define b0101011 43
+#define b0101100 44
+#define b0101101 45
+#define b0101110 46
+#define b0101111 47
+#define b0110000 48
+#define b0110001 49
+#define b0110010 50
+#define b0110011 51
+#define b0110100 52
+#define b0110101 53
+#define b0110110 54
+#define b0110111 55
+#define b0111000 56
+#define b0111001 57
+#define b0111010 58
+#define b0111011 59
+#define b0111100 60
+#define b0111101 61
+#define b0111110 62
+#define b0111111 63
+#define b1000000 64
+#define b1000001 65
+#define b1000010 66
+#define b1000011 67
+#define b1000100 68
+#define b1000101 69
+#define b1000110 70
+#define b1000111 71
+#define b1001000 72
+#define b1001001 73
+#define b1001010 74
+#define b1001011 75
+#define b1001100 76
+#define b1001101 77
+#define b1001110 78
+#define b1001111 79
+#define b1010000 80
+#define b1010001 81
+#define b1010010 82
+#define b1010011 83
+#define b1010100 84
+#define b1010101 85
+#define b1010110 86
+#define b1010111 87
+#define b1011000 88
+#define b1011001 89
+#define b1011010 90
+#define b1011011 91
+#define b1011100 92
+#define b1011101 93
+#define b1011110 94
+#define b1011111 95
+#define b1100000 96
+#define b1100001 97
+#define b1100010 98
+#define b1100011 99
+#define b1100100 100
+#define b1100101 101
+#define b1100110 102
+#define b1100111 103
+#define b1101000 104
+#define b1101001 105
+#define b1101010 106
+#define b1101011 107
+#define b1101100 108
+#define b1101101 109
+#define b1101110 110
+#define b1101111 111
+#define b1110000 112
+#define b1110001 113
+#define b1110010 114
+#define b1110011 115
+#define b1110100 116
+#define b1110101 117
+#define b1110110 118
+#define b1110111 119
+#define b1111000 120
+#define b1111001 121
+#define b1111010 122
+#define b1111011 123
+#define b1111100 124
+#define b1111101 125
+#define b1111110 126
+#define b1111111 127
+
+
+#define b00000000 0
+#define b00000001 1
+#define b00000010 2
+#define b00000011 3
+#define b00000100 4
+#define b00000101 5
+#define b00000110 6
+#define b00000111 7
+#define b00001000 8
+#define b00001001 9
+#define b00001010 10
+#define b00001011 11
+#define b00001100 12
+#define b00001101 13
+#define b00001110 14
+#define b00001111 15
+#define b00010000 16
+#define b00010001 17
+#define b00010010 18
+#define b00010011 19
+#define b00010100 20
+#define b00010101 21
+#define b00010110 22
+#define b00010111 23
+#define b00011000 24
+#define b00011001 25
+#define b00011010 26
+#define b00011011 27
+#define b00011100 28
+#define b00011101 29
+#define b00011110 30
+#define b00011111 31
+#define b00100000 32
+#define b00100001 33
+#define b00100010 34
+#define b00100011 35
+#define b00100100 36
+#define b00100101 37
+#define b00100110 38
+#define b00100111 39
+#define b00101000 40
+#define b00101001 41
+#define b00101010 42
+#define b00101011 43
+#define b00101100 44
+#define b00101101 45
+#define b00101110 46
+#define b00101111 47
+#define b00110000 48
+#define b00110001 49
+#define b00110010 50
+#define b00110011 51
+#define b00110100 52
+#define b00110101 53
+#define b00110110 54
+#define b00110111 55
+#define b00111000 56
+#define b00111001 57
+#define b00111010 58
+#define b00111011 59
+#define b00111100 60
+#define b00111101 61
+#define b00111110 62
+#define b00111111 63
+#define b01000000 64
+#define b01000001 65
+#define b01000010 66
+#define b01000011 67
+#define b01000100 68
+#define b01000101 69
+#define b01000110 70
+#define b01000111 71
+#define b01001000 72
+#define b01001001 73
+#define b01001010 74
+#define b01001011 75
+#define b01001100 76
+#define b01001101 77
+#define b01001110 78
+#define b01001111 79
+#define b01010000 80
+#define b01010001 81
+#define b01010010 82
+#define b01010011 83
+#define b01010100 84
+#define b01010101 85
+#define b01010110 86
+#define b01010111 87
+#define b01011000 88
+#define b01011001 89
+#define b01011010 90
+#define b01011011 91
+#define b01011100 92
+#define b01011101 93
+#define b01011110 94
+#define b01011111 95
+#define b01100000 96
+#define b01100001 97
+#define b01100010 98
+#define b01100011 99
+#define b01100100 100
+#define b01100101 101
+#define b01100110 102
+#define b01100111 103
+#define b01101000 104
+#define b01101001 105
+#define b01101010 106
+#define b01101011 107
+#define b01101100 108
+#define b01101101 109
+#define b01101110 110
+#define b01101111 111
+#define b01110000 112
+#define b01110001 113
+#define b01110010 114
+#define b01110011 115
+#define b01110100 116
+#define b01110101 117
+#define b01110110 118
+#define b01110111 119
+#define b01111000 120
+#define b01111001 121
+#define b01111010 122
+#define b01111011 123
+#define b01111100 124
+#define b01111101 125
+#define b01111110 126
+#define b01111111 127
+#define b10000000 128
+#define b10000001 129
+#define b10000010 130
+#define b10000011 131
+#define b10000100 132
+#define b10000101 133
+#define b10000110 134
+#define b10000111 135
+#define b10001000 136
+#define b10001001 137
+#define b10001010 138
+#define b10001011 139
+#define b10001100 140
+#define b10001101 141
+#define b10001110 142
+#define b10001111 143
+#define b10010000 144
+#define b10010001 145
+#define b10010010 146
+#define b10010011 147
+#define b10010100 148
+#define b10010101 149
+#define b10010110 150
+#define b10010111 151
+#define b10011000 152
+#define b10011001 153
+#define b10011010 154
+#define b10011011 155
+#define b10011100 156
+#define b10011101 157
+#define b10011110 158
+#define b10011111 159
+#define b10100000 160
+#define b10100001 161
+#define b10100010 162
+#define b10100011 163
+#define b10100100 164
+#define b10100101 165
+#define b10100110 166
+#define b10100111 167
+#define b10101000 168
+#define b10101001 169
+#define b10101010 170
+#define b10101011 171
+#define b10101100 172
+#define b10101101 173
+#define b10101110 174
+#define b10101111 175
+#define b10110000 176
+#define b10110001 177
+#define b10110010 178
+#define b10110011 179
+#define b10110100 180
+#define b10110101 181
+#define b10110110 182
+#define b10110111 183
+#define b10111000 184
+#define b10111001 185
+#define b10111010 186
+#define b10111011 187
+#define b10111100 188
+#define b10111101 189
+#define b10111110 190
+#define b10111111 191
+#define b11000000 192
+#define b11000001 193
+#define b11000010 194
+#define b11000011 195
+#define b11000100 196
+#define b11000101 197
+#define b11000110 198
+#define b11000111 199
+#define b11001000 200
+#define b11001001 201
+#define b11001010 202
+#define b11001011 203
+#define b11001100 204
+#define b11001101 205
+#define b11001110 206
+#define b11001111 207
+#define b11010000 208
+#define b11010001 209
+#define b11010010 210
+#define b11010011 211
+#define b11010100 212
+#define b11010101 213
+#define b11010110 214
+#define b11010111 215
+#define b11011000 216
+#define b11011001 217
+#define b11011010 218
+#define b11011011 219
+#define b11011100 220
+#define b11011101 221
+#define b11011110 222
+#define b11011111 223
+#define b11100000 224
+#define b11100001 225
+#define b11100010 226
+#define b11100011 227
+#define b11100100 228
+#define b11100101 229
+#define b11100110 230
+#define b11100111 231
+#define b11101000 232
+#define b11101001 233
+#define b11101010 234
+#define b11101011 235
+#define b11101100 236
+#define b11101101 237
+#define b11101110 238
+#define b11101111 239
+#define b11110000 240
+#define b11110001 241
+#define b11110010 242
+#define b11110011 243
+#define b11110100 244
+#define b11110101 245
+#define b11110110 246
+#define b11110111 247
+#define b11111000 248
+#define b11111001 249
+#define b11111010 250
+#define b11111011 251
+#define b11111100 252
+#define b11111101 253
+#define b11111110 254
+#define b11111111 255
+
+
+
+#endif /* _COMMON_BCONST_H */
diff --git a/src/format/elf/symbols.c b/src/format/elf/symbols.c
index 15c3a6b..84bf9b7 100644
--- a/src/format/elf/symbols.c
+++ b/src/format/elf/symbols.c
@@ -1321,7 +1321,7 @@ static bool load_elf_internal_symbols(GElfFormat *format)
init_vmpa(&addr, ELF_SYM(format, sym, st_value), VMPA_NO_VIRTUAL);
- init_mrange(&range, &addr, ELF_SYM(format, sym, st_size));
+ init_mrange(&range, &addr, 4/*ELF_SYM(format, sym, st_size) FIXME !!! */);
/* Première ébauche de nom */