summaryrefslogtreecommitdiff
path: root/src/arch/x86/operands
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2012-10-18 00:28:06 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2012-10-18 00:28:06 (GMT)
commitf7d126acb7718d4a13ac64c0d71c7d019cc8c18c (patch)
treeb4b32237b99344beba8c03333972efb8f108a5cf /src/arch/x86/operands
parent2cfb66fcd5e8293d1dd689691bdc8c3517dd183a (diff)
Reorganized the code for the x86 architecture support.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@274 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/arch/x86/operands')
-rw-r--r--src/arch/x86/operands/Makefile.am21
-rw-r--r--src/arch/x86/operands/data.c207
-rw-r--r--src/arch/x86/operands/data.h60
-rw-r--r--src/arch/x86/operands/modrm.c436
-rw-r--r--src/arch/x86/operands/modrm.h70
-rw-r--r--src/arch/x86/operands/moffs.c189
-rw-r--r--src/arch/x86/operands/moffs.h59
-rw-r--r--src/arch/x86/operands/register.c265
-rw-r--r--src/arch/x86/operands/register.h66
-rw-r--r--src/arch/x86/operands/relative.c221
-rw-r--r--src/arch/x86/operands/relative.h63
11 files changed, 1657 insertions, 0 deletions
diff --git a/src/arch/x86/operands/Makefile.am b/src/arch/x86/operands/Makefile.am
new file mode 100644
index 0000000..ac48667
--- /dev/null
+++ b/src/arch/x86/operands/Makefile.am
@@ -0,0 +1,21 @@
+
+noinst_LTLIBRARIES = libarchx86operands.la
+
+libarchx86operands_la_SOURCES = \
+ data.h data.c \
+ modrm.h modrm.c \
+ moffs.h moffs.c \
+ register.h register.c \
+ relative.h relative.c
+
+libarchx86_la_CFLAGS = $(AM_CFLAGS)
+
+
+INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS)
+
+AM_CPPFLAGS =
+
+AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
+
+
+SUBDIRS =
diff --git a/src/arch/x86/operands/data.c b/src/arch/x86/operands/data.c
new file mode 100644
index 0000000..22f16b7
--- /dev/null
+++ b/src/arch/x86/operands/data.c
@@ -0,0 +1,207 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * data.c - opérandes de manipulation de données
+ *
+ * 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 "data.h"
+
+
+#include "../registers.h"
+#include "../../operand-int.h"
+
+
+
+/* Définition d'un opérande x86 de manipulation de données (instance) */
+struct _GX86DataOperand
+{
+ GArchOperand parent; /* Instance parente */
+
+ GX86Register *reg; /* Registre représenté */
+ bool dest; /* Déduction du type de segment*/
+
+};
+
+/* Définition d'un opérande x86 de manipulation de données (classe) */
+struct _GX86DataOperandClass
+{
+ GArchOperandClass parent; /* Classe parente */
+
+};
+
+
+/* Initialise la classe des opérandes x86 pointant des données. */
+static void g_x86_data_operand_class_init(GX86DataOperandClass *);
+
+/* Initialise une instance d'opérande x86 pointant des données. */
+static void g_x86_data_operand_init(GX86DataOperand *);
+
+/* Ajoute du texte simple à un fichier ouvert en écriture. */
+static void g_x86_data_operand_add_text(const GX86DataOperand *, GRenderingOptions *, MainRendering, FILE *);
+
+/* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */
+static void g_x86_data_operand_to_buffer(const GX86DataOperand *, GBufferLine *, GRenderingOptions *);
+
+
+
+/* Indique le type défini par la GLib pour un opérande x86 de manipulation de données. */
+G_DEFINE_TYPE(GX86DataOperand, g_x86_data_operand, G_TYPE_ARCH_OPERAND);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des opérandes x86 pointant des données. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_x86_data_operand_class_init(GX86DataOperandClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = instance à initialiser. *
+* *
+* Description : Initialise une instance d'opérande pointant des données. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_x86_data_operand_init(GX86DataOperand *operand)
+{
+ GContentExporter *parent; /* Instance parente */
+
+ parent = G_CONTENT_EXPORTER(operand);
+
+ parent->add_text = (add_text_fc)g_x86_data_operand_add_text;
+ parent->export_buffer = (export_buffer_fc)g_x86_data_operand_to_buffer;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : size = taille de l'opérande, et donc du registre. *
+* dest = indique si la cible est une destination ou une source.*
+* *
+* Description : Crée un opérande x86 de manipulation de données. *
+* *
+* Retour : Opérande mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchOperand *g_x86_data_operand_new(MemoryDataSize size, bool dest)
+{
+ GX86DataOperand *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_X86_DATA_OPERAND, NULL);
+
+ result->reg = g_x86_register_new(MDS_32_BITS/* FIXME size*/, dest ? 0x07 : 0x06);
+ result->dest = dest;
+
+ return G_ARCH_OPERAND(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à transcrire. *
+* options = options de rendu. *
+* rendering = support effectif final des lignes de code. *
+* stream = flux ouvert en écriture. *
+* *
+* Description : Ajoute du texte simple à un fichier ouvert en écriture. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_x86_data_operand_add_text(const GX86DataOperand *operand, GRenderingOptions *options, MainRendering rendering, FILE *stream)
+{
+ GContentExporter *exporter; /* Autre vision de l'opérande */
+
+ exporter = G_CONTENT_EXPORTER(operand);
+
+ if (operand->dest)
+ g_content_exporter_insert_text(exporter, stream, "es:", 3, RTT_SEGMENT);
+ else
+ g_content_exporter_insert_text(exporter, stream, "ds:", 3, RTT_SEGMENT);
+
+ g_content_exporter_insert_text(exporter, stream, "[", 1, RTT_HOOK);
+
+ g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->reg), options, rendering, stream);
+
+ g_content_exporter_insert_text(exporter, stream, "]", 1, RTT_HOOK);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à transcrire. *
+* buffer = espace où placer ledit contenu. *
+* options = options de rendu. *
+* *
+* Description : Ajoute à un tampon GLib le contenu de l'instance spécifiée. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_x86_data_operand_to_buffer(const GX86DataOperand *operand, GBufferLine *buffer, GRenderingOptions *options)
+{
+ GContentExporter *exporter; /* Autre vision de l'opérande */
+
+ exporter = G_CONTENT_EXPORTER(operand);
+
+ if (operand->dest)
+ g_content_exporter_insert_into_buffer(G_CONTENT_EXPORTER(operand), buffer, BLC_ASSEMBLY,
+ "es:", 3, RTT_SEGMENT);
+ else
+ g_content_exporter_insert_into_buffer(G_CONTENT_EXPORTER(operand), buffer, BLC_ASSEMBLY,
+ "ds:", 3, RTT_SEGMENT);
+
+ g_content_exporter_insert_into_buffer(G_CONTENT_EXPORTER(operand), buffer, BLC_ASSEMBLY,
+ "[", 1, RTT_HOOK);
+
+ g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->reg), buffer, options);
+
+ g_content_exporter_insert_into_buffer(G_CONTENT_EXPORTER(operand), buffer, BLC_ASSEMBLY,
+ "]", 1, RTT_HOOK);
+
+}
diff --git a/src/arch/x86/operands/data.h b/src/arch/x86/operands/data.h
new file mode 100644
index 0000000..406698e
--- /dev/null
+++ b/src/arch/x86/operands/data.h
@@ -0,0 +1,60 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * data.h - prototypes pour les opérandes de manipulation de données
+ *
+ * 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 _ARCH_X86_OPERANDS_DATA_H
+#define _ARCH_X86_OPERANDS_DATA_H
+
+
+#include <glib-object.h>
+
+
+#include "../../operand.h"
+#include "../../../common/endianness.h"
+
+
+
+#define G_TYPE_X86_DATA_OPERAND g_x86_data_operand_get_type()
+#define G_X86_DATA_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_x86_data_operand_get_type(), GX86DataOperand))
+#define G_IS_X86_DATA_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_x86_data_operand_get_type()))
+#define G_X86_DATA_OPERAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_X86_DATA_OPERAND, GX86DataOperandClass))
+#define G_IS_X86_DATA_OPERAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_X86_DATA_OPERAND))
+#define G_X86_DATA_OPERAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_X86_DATA_OPERAND, GX86DataOperandClass))
+
+
+
+/* Définition d'un opérande x86 de manipulation de données (instance) */
+typedef struct _GX86DataOperand GX86DataOperand;
+
+/* Définition d'un opérande x86 de manipulation de données (classe) */
+typedef struct _GX86DataOperandClass GX86DataOperandClass;
+
+
+/* Indique le type défini par la GLib pour un opérande x86 de manipulation de données. */
+GType g_x86_data_operand_get_type(void);
+
+/* Crée un opérande x86 de manipulation de données. */
+GArchOperand *g_x86_data_operand_new(MemoryDataSize, bool);
+
+
+
+#endif /* _ARCH_X86_OPERANDS_DATA_H */
diff --git a/src/arch/x86/operands/modrm.c b/src/arch/x86/operands/modrm.c
new file mode 100644
index 0000000..892d5dc
--- /dev/null
+++ b/src/arch/x86/operands/modrm.c
@@ -0,0 +1,436 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * modrm.c - opérandes de type mod/rm
+ *
+ * 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 "modrm.h"
+
+
+#include <math.h>
+
+
+#include "register.h"
+#include "../../operand-int.h"
+
+
+
+/* Définition d'un opérande x86 de type ModRM (instance) */
+struct _GX86ModRMOperand
+{
+ GArchOperand parent; /* Instance parente */
+
+ uint8_t scale; /* Puissance de deux */
+ GX86Register *index; /* Registre servant d'indice */
+ GX86Register *base; /* Registre de base */
+ GImmOperand *displacement; /* Décallage supplémentaire */
+
+};
+
+
+/* Définition d'un opérande x86 de type ModRM (classe) */
+struct _GX86ModRMOperandClass
+{
+ GArchOperandClass parent; /* Classe parente */
+
+};
+
+
+/* Initialise la classe des opérandes x86 de type ModRM. */
+static void g_x86_mod_rm_operand_class_init(GX86ModRMOperandClass *);
+
+/* Initialise une instance d'opérande x86 de type ModRM. */
+static void g_x86_mod_rm_operand_init(GX86ModRMOperand *);
+
+/* Ajoute du texte simple à un fichier ouvert en écriture. */
+static void g_x86_mod_rm_operand_add_text(const GX86ModRMOperand *, GRenderingOptions *, MainRendering, FILE *);
+
+/* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */
+static void g_x86_mod_rm_operand_to_buffer(const GX86ModRMOperand *, GBufferLine *, GRenderingOptions *);
+
+
+
+/* Indique le type défini par la GLib pour un opérande x86 de type ModRM. */
+G_DEFINE_TYPE(GX86ModRMOperand, g_x86_mod_rm_operand, G_TYPE_ARCH_OPERAND);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des opérandes x86 de type ModRM. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_x86_mod_rm_operand_class_init(GX86ModRMOperandClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = instance à initialiser. *
+* *
+* Description : Initialise une instance d'opérande x86 de type ModRM. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_x86_mod_rm_operand_init(GX86ModRMOperand *operand)
+{
+ GContentExporter *parent; /* Instance parente */
+
+ parent = G_CONTENT_EXPORTER(operand);
+
+ parent->add_text = (add_text_fc)g_x86_mod_rm_operand_add_text;
+ parent->export_buffer = (export_buffer_fc)g_x86_mod_rm_operand_to_buffer;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : data = flux de données à analyser. *
+* pos = position courante dans ce flux. [OUT] *
+* len = taille totale des données à analyser. *
+* size = taille de l'opérande, et donc du registre. *
+* *
+* Description : Crée un opérande x86 de type ModRM. *
+* *
+* Retour : Opérande mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchOperand *g_x86_mod_rm_operand_new(const bin_t *data, off_t *pos, off_t len, MemoryDataSize size)
+{
+ GX86ModRMOperand *result; /* Structure à retourner */
+ uint8_t mod; /* Modificateur présent */
+ GX86Register *reg; /* Registre lu */
+
+ mod = (data[*pos] & 0xc0);
+
+ if (mod == 0xc0)
+ return g_x86_register_operand_new_from_mod_rm(data, pos, len, size, true);
+
+ reg = g_x86_register_new(size, data[*pos] & 0x07);
+ if (reg == NULL) return NULL;
+
+ (*pos)++;
+
+ /* Vieille astuce de l'emplacement mémoire fixe ? */
+ if (g_x86_register_is_base_pointer(reg) && mod == 0x00)
+ {
+ /* FIXME *///free_x86_register(reg);
+ return g_imm_operand_new_from_data(MDS_32_BITS/* FIXME */, data, pos, len, SRE_LITTLE /*FIXME*/);
+ }
+
+ result = g_object_new(G_TYPE_X86_MOD_RM_OPERAND, NULL);
+
+ /* A la recherche d'un SIB */
+ if (g_x86_register_is_stack_pointer(reg))
+ {
+ /* FIXME *///free_x86_register(reg);
+
+ result->base = g_x86_register_new(size, data[*pos] & 0x07);
+ if (result->base == NULL) goto gxmron_error;
+
+ result->index = g_x86_register_new(size, (data[*pos] & 0x38) >> 3);
+ if (result->index == NULL) goto gxmron_error;
+
+ result->scale = ((data[*pos] & 0xc0) >> 6);
+
+ if (g_x86_register_is_stack_pointer(result->index))
+ {
+ /* FIXME *///free_x86_register(result->index);
+ result->index = result->base;
+ result->base = NULL;
+ }
+
+ (*pos)++;
+
+ }
+
+ else result->index = reg;
+
+ /* Décallage supplémentaire ? */
+ switch (mod)
+ {
+ case 0x00:
+ if (result->base != NULL && g_x86_register_is_base_pointer(result->base))
+ {
+ /* FIXME *///free_x86_register(result->base);
+ result->base = NULL;
+
+ result->displacement = g_imm_operand_new_from_data(size/* FIXME : !convert mds/aos */, data, pos, len, SRE_LITTLE /* FIXME */);
+ if (result->displacement == NULL) goto gxmron_error;
+
+ }
+ break;
+
+ case 0x40:
+ result->displacement = g_imm_operand_new_from_data(MDS_8_BITS_SIGNED, data, pos, len, SRE_LITTLE /* FIXME */);
+ if (result->displacement == NULL) goto gxmron_error;
+ break;
+
+ case 0x80:
+ result->displacement = g_imm_operand_new_from_data(MDS_32_BITS_SIGNED/* FIXME ! 16/32 */, data, pos, len, SRE_LITTLE /* FIXME */);
+ if (result->displacement == NULL) goto gxmron_error;
+ break;
+
+ }
+
+ return G_ARCH_OPERAND(result);
+
+ gxmron_error:
+
+ /* FIXME free(result);*/
+ return NULL;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à transcrire. *
+* options = options de rendu. *
+* rendering = support effectif final des lignes de code. *
+* stream = flux ouvert en écriture. *
+* *
+* Description : Ajoute du texte simple à un fichier ouvert en écriture. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_x86_mod_rm_operand_add_text(const GX86ModRMOperand *operand, GRenderingOptions *options, MainRendering rendering, FILE *stream)
+{
+ GContentExporter *exporter; /* Autre vision de l'opérande */
+ char tmp[2]; /* Echelle en puissance de 2 */
+
+ exporter = G_CONTENT_EXPORTER(operand);
+
+ switch (g_rendering_options_get_syntax(options))
+ {
+ case ASX_INTEL:
+
+ g_content_exporter_insert_text(exporter, stream, "[", 1, RTT_HOOK);
+
+ if (operand->scale > 0)
+ {
+ snprintf(tmp, 2, "%d", (int)pow(2, operand->scale));
+
+ g_content_exporter_insert_text(exporter, stream, tmp, 1, RTT_IMMEDIATE);
+
+ g_content_exporter_insert_text(exporter, stream, "*", 1, RTT_SIGNS);
+
+ }
+
+ g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->index),
+ options, rendering, stream);
+
+ if (operand->base != NULL)
+ {
+ g_content_exporter_insert_text(exporter, stream, "+", 1, RTT_SIGNS);
+
+ g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->base),
+ options, rendering, stream);
+
+ }
+
+ if (operand->displacement != NULL)
+ {
+ if (g_imm_operand_is_negative(operand->displacement))
+ g_content_exporter_insert_text(exporter, stream, "-", 1, RTT_SIGNS);
+ else
+ g_content_exporter_insert_text(exporter, stream, "+", 1, RTT_SIGNS);
+
+ g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->displacement),
+ options, rendering, stream);
+
+ }
+
+ g_content_exporter_insert_text(exporter, stream, "]", 1, RTT_HOOK);
+
+ break;
+
+ case ASX_ATT:
+
+ /* TODO */
+ g_content_exporter_insert_text(exporter, stream, "[ModRM]", 7, RTT_HOOK);
+
+ break;
+
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à transcrire. *
+* buffer = espace où placer ledit contenu. *
+* options = options de rendu. *
+* *
+* Description : Ajoute à un tampon GLib le contenu de l'instance spécifiée. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_x86_mod_rm_operand_to_buffer(const GX86ModRMOperand *operand, GBufferLine *buffer, GRenderingOptions *options)
+{
+ GContentExporter *exporter; /* Autre vision de l'opérande */
+ char tmp[2]; /* Echelle en puissance de 2 */
+
+ exporter = G_CONTENT_EXPORTER(operand);
+
+ switch (g_rendering_options_get_syntax(options))
+ {
+ case ASX_INTEL:
+
+ g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY,
+ "[", 1, RTT_HOOK);
+
+ if (operand->scale > 0)
+ {
+ snprintf(tmp, 2, "%d", (int)pow(2, operand->scale));
+
+ g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY,
+ tmp, 1, RTT_IMMEDIATE);
+
+ g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY,
+ "*", 1, RTT_SIGNS);
+
+ }
+
+ g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->index), buffer, options);
+
+ if (operand->base != NULL)
+ {
+ g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY,
+ "+", 1, RTT_SIGNS);
+
+ g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->base), buffer, options);
+
+ }
+
+ if (operand->displacement != NULL)
+ {
+ if (g_imm_operand_is_negative(operand->displacement))
+ g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY,
+ "-", 1, RTT_SIGNS);
+ else
+ g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY,
+ "+", 1, RTT_SIGNS);
+
+ g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->displacement), buffer, options);
+
+ }
+
+ g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY,
+ "]", 1, RTT_HOOK);
+
+ break;
+
+ case ASX_ATT:
+
+ /* TODO */
+ g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY,
+ "[ModRM]", 7, RTT_HOOK);
+
+ break;
+
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à consulter. *
+* scale = facteur sous forme de puissance de deux. [OUT *
+* index = register principal de l'opérande. [OUT] *
+* *
+* Description : Fournit l'indice et l'échelle d'un opérande x86 ModRM. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_x86_mod_rm_operand_get_scale_and_index(const GX86ModRMOperand *operand, uint8_t *scale, const GX86Register **index)
+{
+ *scale = operand->scale;
+ *index = operand->index;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à consulter. *
+* *
+* Description : Fournit le registre de base d'un opérande x86 ModRM. *
+* *
+* Retour : Registre de base de l'opérande. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+const GX86Register *g_x86_mod_rm_operand_get_base(const GX86ModRMOperand *operand)
+{
+ return operand->base;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à consulter. *
+* *
+* Description : Fournit le décallage supplémentaire d'un opérande x86 ModRM. *
+* *
+* Retour : Décallage numérique pour l'opérande. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+const GImmOperand *g_x86_mod_rm_operand_get_displacement(const GX86ModRMOperand *operand)
+{
+ return operand->displacement;
+
+}
diff --git a/src/arch/x86/operands/modrm.h b/src/arch/x86/operands/modrm.h
new file mode 100644
index 0000000..89a274f
--- /dev/null
+++ b/src/arch/x86/operands/modrm.h
@@ -0,0 +1,70 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * modrm.h - prototypes pour les opérandes de type mod/rm
+ *
+ * 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 _ARCH_X86_OPERANDS_MODRM_H
+#define _ARCH_X86_OPERANDS_MODRM_H
+
+
+#include <glib-object.h>
+
+
+#include "../registers.h"
+#include "../../immediate.h"
+#include "../../operand.h"
+#include "../../../common/endianness.h"
+
+
+
+#define G_TYPE_X86_MOD_RM_OPERAND g_x86_mod_rm_operand_get_type()
+#define G_X86_MOD_RM_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_x86_mod_rm_operand_get_type(), GX86ModRMOperand))
+#define G_IS_X86_MOD_RM_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_x86_mod_rm_operand_get_type()))
+#define G_X86_MOD_RM_OPERAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_X86_MOD_RM_OPERAND, GX86ModRMOperandClass))
+#define G_IS_X86_MOD_RM_OPERAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_X86_MOD_RM_OPERAND))
+#define G_X86_MOD_RM_OPERAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_X86_MOD_RM_OPERAND, GX86ModRMOperandClass))
+
+
+/* Définition d'un opérande x86 de type ModRM (instance) */
+typedef struct _GX86ModRMOperand GX86ModRMOperand;
+
+/* Définition d'un opérande x86 de type ModRM (classe) */
+typedef struct _GX86ModRMOperandClass GX86ModRMOperandClass;
+
+
+/* Indique le type défini par la GLib pour un opérande x86 de type ModRM. */
+GType g_x86_mod_rm_operand_get_type(void);
+
+/* Crée un opérande x86 de type ModRM. */
+GArchOperand *g_x86_mod_rm_operand_new(const bin_t *, off_t *, off_t, MemoryDataSize);
+
+/* Fournit l'indice et l'échelle d'un opérande x86 ModRM. */
+void g_x86_mod_rm_operand_get_scale_and_index(const GX86ModRMOperand *operand, uint8_t *, const GX86Register **);
+
+/* Fournit le registre de base d'un opérande x86 ModRM. */
+const GX86Register *g_x86_mod_rm_operand_get_base(const GX86ModRMOperand *);
+
+/* Fournit le décallage supplémentaire d'un opérande x86 ModRM. */
+const GImmOperand *g_x86_mod_rm_operand_get_displacement(const GX86ModRMOperand *);
+
+
+
+#endif /* _ARCH_X86_OPERANDS_MODRM_H */
diff --git a/src/arch/x86/operands/moffs.c b/src/arch/x86/operands/moffs.c
new file mode 100644
index 0000000..3754e79
--- /dev/null
+++ b/src/arch/x86/operands/moffs.c
@@ -0,0 +1,189 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * moffs.c - opérandes d'emplacements mémoire
+ *
+ * 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 "moffs.h"
+
+
+#include "../../immediate.h"
+#include "../../operand-int.h"
+
+
+
+/* Définition d'un opérande visant un emplacement mémoire x86 (instance) */
+struct _GX86MOffsOperand
+{
+ GArchOperand parent; /* Instance parente */
+
+ GImmOperand *offset; /* Adresse mémoire visée */
+
+};
+
+/* Définition d'un opérande visant un emplacement mémoire x86 (classe) */
+struct _GX86MOffsOperandClass
+{
+ GArchOperandClass parent; /* Classe parente */
+
+};
+
+
+/* Initialise la classe des opérandes d'emplacement mémoire x86. */
+static void g_x86_moffs_operand_class_init(GX86MOffsOperandClass *);
+
+/* Initialise une instance d'opérande d'emplacement mémoire x86. */
+static void g_x86_moffs_operand_init(GX86MOffsOperand *);
+
+/* Ajoute du texte simple à un fichier ouvert en écriture. */
+static void g_x86_moffs_operand_add_text(const GX86MOffsOperand *, GRenderingOptions *, MainRendering, FILE *);
+
+/* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */
+static void g_x86_moffs_operand_to_buffer(const GX86MOffsOperand *, GBufferLine *, GRenderingOptions *);
+
+
+
+/* Indique le type défini par la GLib pour un opérande d'emplacement mémoire x86. */
+G_DEFINE_TYPE(GX86MOffsOperand, g_x86_moffs_operand, G_TYPE_ARCH_OPERAND);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des opérandes d'emplacement mémoire x86.*
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_x86_moffs_operand_class_init(GX86MOffsOperandClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = instance à initialiser. *
+* *
+* Description : Initialise une instance d'opérande d'emplacement mémoire x86.*
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_x86_moffs_operand_init(GX86MOffsOperand *operand)
+{
+ GContentExporter *parent; /* Instance parente */
+
+ parent = G_CONTENT_EXPORTER(operand);
+
+ parent->add_text = (add_text_fc)g_x86_moffs_operand_add_text;
+ parent->export_buffer = (export_buffer_fc)g_x86_moffs_operand_to_buffer;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : data = flux de données à analyser. *
+* pos = position courante dans ce flux. [OUT] *
+* len = taille totale des données à analyser. *
+* size = taille de l'opérande, et donc du registre. *
+* *
+* Description : Crée un opérande d'emplacement mémoire x86. *
+* *
+* Retour : Opérande mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchOperand *g_x86_moffs_operand_new(const bin_t *data, off_t *pos, off_t len, MemoryDataSize size)
+{
+ GX86MOffsOperand *result; /* Structure à retourner */
+ GImmOperand *offset; /* Emplacement lu */
+
+ result = NULL;
+
+ offset = g_imm_operand_new_from_data(size, data, pos, len, SRE_LITTLE /* FIXME */);
+
+ if (offset != NULL)
+ {
+ result = g_object_new(G_TYPE_X86_MOFFS_OPERAND, NULL);
+ result->offset = offset;
+ }
+
+ return G_ARCH_OPERAND(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à transcrire. *
+* options = options de rendu. *
+* rendering = support effectif final des lignes de code. *
+* stream = flux ouvert en écriture. *
+* *
+* Description : Ajoute du texte simple à un fichier ouvert en écriture. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_x86_moffs_operand_add_text(const GX86MOffsOperand *operand, GRenderingOptions *options, MainRendering rendering, FILE *stream)
+{
+ g_content_exporter_insert_text(G_CONTENT_EXPORTER(operand), stream, "ds:", 3, RTT_SEGMENT);
+
+ g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->offset), options, rendering, stream);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à transcrire. *
+* buffer = espace où placer ledit contenu. *
+* options = options de rendu. *
+* *
+* Description : Ajoute à un tampon GLib le contenu de l'instance spécifiée. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_x86_moffs_operand_to_buffer(const GX86MOffsOperand *operand, GBufferLine *buffer, GRenderingOptions *options)
+{
+ g_content_exporter_insert_into_buffer(G_CONTENT_EXPORTER(operand), buffer, BLC_ASSEMBLY,
+ "ds:", 3, RTT_SEGMENT);
+
+ g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->offset), buffer, options);
+
+}
diff --git a/src/arch/x86/operands/moffs.h b/src/arch/x86/operands/moffs.h
new file mode 100644
index 0000000..b4f8889
--- /dev/null
+++ b/src/arch/x86/operands/moffs.h
@@ -0,0 +1,59 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * moffs.h - prototypes pour les opérandes d'emplacements mémoire
+ *
+ * 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 _ARCH_X86_OPERANDS_MOFFS_H
+#define _ARCH_X86_OPERANDS_MOFFS_H
+
+
+#include <glib-object.h>
+
+
+#include "../../operand.h"
+#include "../../../common/endianness.h"
+
+
+
+#define G_TYPE_X86_MOFFS_OPERAND g_x86_moffs_operand_get_type()
+#define G_X86_MOFFS_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_x86_moffs_operand_get_type(), GX86MoffsOperand))
+#define G_IS_X86_MOFFS_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_x86_moffs_operand_get_type()))
+#define G_X86_MOFFS_OPERAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_X86_MOFFS_OPERAND, GX86MoffsOperandClass))
+#define G_IS_X86_MOFFS_OPERAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_X86_MOFFS_OPERAND))
+#define G_X86_MOFFS_OPERAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_X86_MOFFS_OPERAND, GX86MoffsOperandClass))
+
+
+/* Définition d'un opérande visant un emplacement mémoire x86 (instance) */
+typedef struct _GX86MOffsOperand GX86MOffsOperand;
+
+/* Définition d'un opérande visant un emplacement mémoire x86 (classe) */
+typedef struct _GX86MOffsOperandClass GX86MOffsOperandClass;
+
+
+/* Indique le type défini par la GLib pour un opérande d'emplacement mémoire x86. */
+GType g_x86_moffs_operand_get_type(void);
+
+/* Crée un opérande d'emplacement mémoire x86. */
+GArchOperand *g_x86_moffs_operand_new(const bin_t *, off_t *, off_t, MemoryDataSize);
+
+
+
+#endif /* _ARCH_X86_OPERANDS_MOFFS_H */
diff --git a/src/arch/x86/operands/register.c b/src/arch/x86/operands/register.c
new file mode 100644
index 0000000..a70ea60
--- /dev/null
+++ b/src/arch/x86/operands/register.c
@@ -0,0 +1,265 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * register.c - opérandes visant un registre x86
+ *
+ * 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 "register.h"
+
+
+#include "../../operand-int.h"
+
+
+
+/* Définition d'un opérande visant un registre x86 (instance) */
+struct _GX86RegisterOperand
+{
+ GArchOperand parent; /* Instance parente */
+
+ GX86Register *reg; /* Registre représenté */
+
+};
+
+
+/* Définition d'un opérande visant un registre x86 (classe) */
+struct _GX86RegisterOperandClass
+{
+ GArchOperandClass parent; /* Classe parente */
+
+};
+
+
+/* Initialise la classe des opérandes de registre x86. */
+static void g_x86_register_operand_class_init(GX86RegisterOperandClass *);
+
+/* Initialise une instance d'opérande de registre x86. */
+static void g_x86_register_operand_init(GX86RegisterOperand *);
+
+/* Ajoute du texte simple à un fichier ouvert en écriture. */
+static void g_x86_register_operand_add_text(const GX86RegisterOperand *, GRenderingOptions *, MainRendering, FILE *);
+
+/* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */
+static void g_x86_register_operand_to_buffer(const GX86RegisterOperand *, GBufferLine *, GRenderingOptions *);
+
+
+
+/* Indique le type défini par la GLib pour un opérande de registre x86. */
+G_DEFINE_TYPE(GX86RegisterOperand, g_x86_register_operand, G_TYPE_ARCH_OPERAND);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des opérandes de registre x86. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_x86_register_operand_class_init(GX86RegisterOperandClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = instance à initialiser. *
+* *
+* Description : Initialise une instance d'opérande de registre x86. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_x86_register_operand_init(GX86RegisterOperand *operand)
+{
+ GContentExporter *parent; /* Instance parente */
+
+ parent = G_CONTENT_EXPORTER(operand);
+
+ parent->add_text = (add_text_fc)g_x86_register_operand_add_text;
+ parent->export_buffer = (export_buffer_fc)g_x86_register_operand_to_buffer;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : data = flux de données à analyser. *
+* pos = position courante dans ce flux. [OUT] *
+* len = taille totale des données à analyser. *
+* size = taille de l'opérande, et donc du registre. *
+* base = indice du premier registre. *
+* *
+* Description : Crée un opérande visant un registre x86. *
+* *
+* Retour : Opérande mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchOperand *g_x86_register_operand_new_from_opcode(const bin_t *data, off_t *pos, off_t len, MemoryDataSize size, bin_t base)
+{
+ GX86RegisterOperand *result; /* Structure à retourner */
+ GX86Register *reg; /* Registre lu */
+
+ reg = g_x86_register_new(size, data[*pos] - base);
+
+ if (reg != NULL)
+ {
+ (*pos)++;
+
+ result = g_object_new(G_TYPE_X86_REGISTER_OPERAND, NULL);
+
+ result->reg = reg;
+
+ }
+ else result = NULL;
+
+ return G_ARCH_OPERAND(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : data = flux de données à analyser. *
+* pos = position courante dans ce flux. [OUT] *
+* len = taille totale des données à analyser. *
+* size = taille de l'opérande, et donc du registre. *
+* first = indique la partie du ModR/M à traiter. *
+* *
+* Description : Crée un opérande visant un registre x86. *
+* *
+* Retour : Opérande mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchOperand *g_x86_register_operand_new_from_mod_rm(const bin_t *data, off_t *pos, off_t len, MemoryDataSize size, bool first)
+{
+ GX86RegisterOperand *result; /* Structure à retourner */
+ bin_t index; /* Registre lu */
+ GX86Register *reg; /* Registre créé */
+
+ if (first) index = data[*pos] & 0x07;
+ else index = (data[*pos] & 0x38) >> 3;
+
+ reg = g_x86_register_new(size, index);
+
+ if (reg != NULL)
+ {
+ (*pos)++;
+
+ result = g_object_new(G_TYPE_X86_REGISTER_OPERAND, NULL);
+
+ result->reg = reg;
+
+ }
+ else result = NULL;
+
+ return G_ARCH_OPERAND(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : index = indice du registre visé. *
+* size = taille de l'opérande, et donc du registre. *
+* *
+* Description : Crée un opérande visant un registre x86 donné. *
+* *
+* Retour : Opérande mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchOperand *g_x86_register_operand_new_from_index(bin_t index, MemoryDataSize size)
+{
+ GX86RegisterOperand *result; /* Structure à retourner */
+ GX86Register *reg; /* Registre lu */
+
+ reg = g_x86_register_new(size, index);
+
+ if (reg != NULL)
+ {
+ result = g_object_new(G_TYPE_X86_REGISTER_OPERAND, NULL);
+
+ result->reg = reg;
+
+ }
+ else result = NULL;
+
+ return G_ARCH_OPERAND(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à transcrire. *
+* options = options de rendu. *
+* rendering = support effectif final des lignes de code. *
+* stream = flux ouvert en écriture. *
+* *
+* Description : Ajoute du texte simple à un fichier ouvert en écriture. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_x86_register_operand_add_text(const GX86RegisterOperand *operand, GRenderingOptions *options, MainRendering rendering, FILE *stream)
+{
+ g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->reg), options, rendering, stream);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à transcrire. *
+* buffer = espace où placer ledit contenu. *
+* options = options de rendu. *
+* *
+* Description : Ajoute à un tampon GLib le contenu de l'instance spécifiée. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_x86_register_operand_to_buffer(const GX86RegisterOperand *operand, GBufferLine *buffer, GRenderingOptions *options)
+{
+ g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->reg), buffer, options);
+
+}
diff --git a/src/arch/x86/operands/register.h b/src/arch/x86/operands/register.h
new file mode 100644
index 0000000..11bc87e
--- /dev/null
+++ b/src/arch/x86/operands/register.h
@@ -0,0 +1,66 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * register.h - prototypes pour les opérandes visant un registre x86
+ *
+ * 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 _ARCH_X86_OPERANDS_REGISTER_H
+#define _ARCH_X86_OPERANDS_REGISTER_H
+
+
+#include <glib-object.h>
+
+
+#include "../registers.h"
+#include "../../operand.h"
+#include "../../../common/endianness.h"
+
+
+
+#define G_TYPE_X86_REGISTER_OPERAND g_x86_register_operand_get_type()
+#define G_X86_REGISTER_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_x86_register_operand_get_type(), GX86RegisterOperand))
+#define G_IS_X86_REGISTER_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_x86_register_operand_get_type()))
+#define G_X86_REGISTER_OPERAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_X86_REGISTER_OPERAND, GX86RegisterOperandClass))
+#define G_IS_X86_REGISTER_OPERAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_X86_REGISTER_OPERAND))
+#define G_X86_REGISTER_OPERAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_X86_REGISTER_OPERAND, GX86RegisterOperandClass))
+
+
+/* Définition d'un opérande visant un registre x86 (instance) */
+typedef struct _GX86RegisterOperand GX86RegisterOperand;
+
+/* Définition d'un opérande visant un registre x86 (classe) */
+typedef struct _GX86RegisterOperandClass GX86RegisterOperandClass;
+
+
+/* Indique le type défini par la GLib pour un opérande de registre x86. */
+GType g_x86_register_operand_get_type(void);
+
+/* Crée un opérande visant un registre x86. */
+GArchOperand *g_x86_register_operand_new_from_opcode(const bin_t *, off_t *, off_t, MemoryDataSize, bin_t);
+
+/* Crée un opérande visant un registre x86. */
+GArchOperand *g_x86_register_operand_new_from_mod_rm(const bin_t *, off_t *, off_t, MemoryDataSize, bool);
+
+/* Crée un opérande visant un registre x86 donné. */
+GArchOperand *g_x86_register_operand_new_from_index(bin_t, MemoryDataSize);
+
+
+
+#endif /* _ARCH_X86_OPERANDS_REGISTER_H */
diff --git a/src/arch/x86/operands/relative.c b/src/arch/x86/operands/relative.c
new file mode 100644
index 0000000..3235a0d
--- /dev/null
+++ b/src/arch/x86/operands/relative.c
@@ -0,0 +1,221 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * relative.c - opérandes d'adresses relatives
+ *
+ * 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 "relative.h"
+
+
+#include "../../operand-int.h"
+
+
+
+/* Définition d'un opérande x86 d'adresse relative (instance) */
+struct _GX86RelativeOperand
+{
+ GArchOperand parent; /* Instance parente */
+
+ GImmOperand *immediate; /* Adresse visée reconstituée */
+
+};
+
+/* Définition d'un opérande x86 d'adresse relative (classe) */
+struct _GX86RelativeOperandClass
+{
+ GArchOperandClass parent; /* Classe parente */
+
+};
+
+
+/* Initialise la classe des opérandes x86 d'adresse relative. */
+static void g_x86_relative_operand_class_init(GX86RelativeOperandClass *);
+
+/* Initialise une instance d'opérande x86 d'adresse relative. */
+static void g_x86_relative_operand_init(GX86RelativeOperand *);
+
+/* Ajoute du texte simple à un fichier ouvert en écriture. */
+static void g_x86_relative_operand_add_text(const GX86RelativeOperand *, GRenderingOptions *, MainRendering, FILE *);
+
+/* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */
+static void g_x86_relative_operand_to_buffer(const GX86RelativeOperand *, GBufferLine *, GRenderingOptions *);
+
+
+
+/* Indique le type défini par la GLib pour un opérande x86 d'adresse relative. */
+G_DEFINE_TYPE(GX86RelativeOperand, g_x86_relative_operand, G_TYPE_ARCH_OPERAND);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des opérandes x86 d'adresse relative. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_x86_relative_operand_class_init(GX86RelativeOperandClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = instance à initialiser. *
+* *
+* Description : Initialise une instance d'opérande x86 d'adresse relative. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_x86_relative_operand_init(GX86RelativeOperand *operand)
+{
+ GContentExporter *parent; /* Instance parente */
+
+ parent = G_CONTENT_EXPORTER(operand);
+
+ parent->add_text = (add_text_fc)g_x86_relative_operand_add_text;
+ parent->export_buffer = (export_buffer_fc)g_x86_relative_operand_to_buffer;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : data = flux de données à analyser. *
+* pos = position courante dans ce flux. [OUT] *
+* len = taille totale des données à analyser. *
+* size = taille de l'opérande, et donc du registre. *
+* base = adresse de référence pour le calcul. *
+* *
+* Description : Crée un opérande X86 d'adresse relative. *
+* *
+* Retour : Opérande mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchOperand *g_x86_relative_operand_new(const bin_t *data, off_t *pos, off_t len, MemoryDataSize size, vmpa_t base)
+{
+ GX86RelativeOperand *result; /* Structure à retourner */
+ off_t init_pos; /* Position avant lecture */
+ int8_t val8; /* Valeur sur 8 bits */
+ int16_t val16; /* Valeur sur 16 bits */
+ int32_t val32; /* Valeur sur 32 bits */
+ vmpa_t address; /* Adresse finale visée */
+
+ init_pos = *pos;
+
+ switch (size)
+ {
+ case MDS_8_BITS_UNSIGNED:
+ read_s8(&val8, data, pos, len, SRE_LITTLE /* FIXME */);
+ address = base + (*pos - init_pos) + val8;
+ break;
+ case MDS_16_BITS_UNSIGNED:
+ read_s16(&val16, data, pos, len, SRE_LITTLE /* FIXME */);
+ address = base + (*pos - init_pos) + val16;
+ break;
+ case MDS_32_BITS_UNSIGNED:
+ read_s32(&val32, data, pos, len, SRE_LITTLE /* FIXME */);
+ address = base + (*pos - init_pos) + val32;
+ break;
+ default:
+ return NULL;
+ break;
+ }
+
+ result = g_object_new(G_TYPE_X86_RELATIVE_OPERAND, NULL);
+ result->immediate = g_imm_operand_new_from_value(MDS_32_BITS/*FIXME*/, (uint32_t)address/* FIXME */);
+
+ return G_ARCH_OPERAND(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à transcrire. *
+* options = options de rendu. *
+* rendering = support effectif final des lignes de code. *
+* stream = flux ouvert en écriture. *
+* *
+* Description : Ajoute du texte simple à un fichier ouvert en écriture. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_x86_relative_operand_add_text(const GX86RelativeOperand *operand, GRenderingOptions *options, MainRendering rendering, FILE *stream)
+{
+ g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->immediate), options, rendering, stream);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à transcrire. *
+* buffer = espace où placer ledit contenu. *
+* options = options de rendu. *
+* *
+* Description : Ajoute à un tampon GLib le contenu de l'instance spécifiée. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_x86_relative_operand_to_buffer(const GX86RelativeOperand *operand, GBufferLine *buffer, GRenderingOptions *options)
+{
+ g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->immediate), buffer, options);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à traiter. *
+* *
+* Description : Fournit l'adresse représentée par une opérande X86. *
+* *
+* Retour : Valeur portée par l'opérande. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+const GImmOperand *g_x86_relative_operand_get_value(const GX86RelativeOperand *operand)
+{
+ return operand->immediate;
+
+}
diff --git a/src/arch/x86/operands/relative.h b/src/arch/x86/operands/relative.h
new file mode 100644
index 0000000..083444a
--- /dev/null
+++ b/src/arch/x86/operands/relative.h
@@ -0,0 +1,63 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * relative.h - prototypes pour les opérandes d'adresses relatives
+ *
+ * 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 _ARCH_X86_OPERANDS_RELATIVE_H
+#define _ARCH_X86_OPERANDS_RELATIVE_H
+
+
+#include <glib-object.h>
+
+
+#include "../../immediate.h"
+#include "../../operand.h"
+#include "../../../common/endianness.h"
+
+
+
+#define G_TYPE_X86_RELATIVE_OPERAND g_x86_relative_operand_get_type()
+#define G_X86_RELATIVE_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_x86_relative_operand_get_type(), GX86RelativeOperand))
+#define G_IS_X86_RELATIVE_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_x86_relative_operand_get_type()))
+#define G_X86_RELATIVE_OPERAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_X86_RELATIVE_OPERAND, GX86RelativeOperandClass))
+#define G_IS_X86_RELATIVE_OPERAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_X86_RELATIVE_OPERAND))
+#define G_X86_RELATIVE_OPERAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_X86_RELATIVE_OPERAND, GX86RelativeOperandClass))
+
+
+/* Définition d'un opérande x86 d'adresse relative (instance) */
+typedef struct _GX86RelativeOperand GX86RelativeOperand;
+
+/* Définition d'un opérande x86 d'adresse relative (classe) */
+typedef struct _GX86RelativeOperandClass GX86RelativeOperandClass;
+
+
+/* Indique le type défini par la GLib pour un opérande x86 d'adresse relative. */
+GType g_x86_relative_operand_get_type(void);
+
+/* Crée un opérande X86 d'adresse relative. */
+GArchOperand *g_x86_relative_operand_new(const bin_t *, off_t *, off_t, MemoryDataSize, vmpa_t);
+
+/* Fournit l'adresse représentée par une opérande X86. */
+const GImmOperand *g_x86_relative_operand_get_value(const GX86RelativeOperand *);
+
+
+
+#endif /* _ARCH_X86_OPERANDS_RELATIVE_H */