summaryrefslogtreecommitdiff
path: root/src/arch/x86
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2009-08-30 10:55:45 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2009-08-30 10:55:45 (GMT)
commitac447bc36e65b91f97434cf2613ccb1e768267e0 (patch)
tree471f3b49629269d7ea44a6ea8b9177fe7e437817 /src/arch/x86
parent184249f07fb32fb2449723f5f94ce221015231b7 (diff)
Rendered using the GTK buffer (crappy version).
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@107 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/arch/x86')
-rw-r--r--src/arch/x86/operand.c220
-rw-r--r--src/arch/x86/operand.h4
-rw-r--r--src/arch/x86/registers.c413
-rw-r--r--src/arch/x86/registers.h35
4 files changed, 370 insertions, 302 deletions
diff --git a/src/arch/x86/operand.c b/src/arch/x86/operand.c
index 69c08dc..31c993f 100644
--- a/src/arch/x86/operand.c
+++ b/src/arch/x86/operand.c
@@ -70,7 +70,7 @@ struct _GX86RegisterOperand
{
GX86Operand parent; /* Instance parente */
- x86_register *reg; /* Registre représenté */
+ GX86Register *reg; /* Registre représenté */
};
@@ -89,8 +89,8 @@ 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 *);
-/* Traduit un opérande en version humainement lisible. */
-static char *g_x86_register_operand_get_text(const GX86RegisterOperand *, const GExeFormat *, AsmSyntax);
+/* Ajoute à un texte GTK le contenu d'un opérande. */
+static void g_x86_register_operand_add_to_gtk_buffer(const GX86RegisterOperand *, const GExeFormat *, AsmSyntax, GtkTextBuffer *, GtkTextIter *);
@@ -103,8 +103,8 @@ struct _GX86ModRMOperand
GX86Operand parent; /* Instance parente */
uint8_t scale; /* Puissance de deux */
- x86_register *index; /* Registre servant d'indice */
- x86_register *base; /* Registre de base */
+ GX86Register *index; /* Registre servant d'indice */
+ GX86Register *base; /* Registre de base */
GImmOperand *displacement; /* Décallage supplémentaire */
};
@@ -124,8 +124,8 @@ 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 *);
-/* Traduit un opérande en version humainement lisible. */
-static char *g_x86_mod_rm_operand_get_text(const GX86ModRMOperand *, const GExeFormat *, AsmSyntax);
+/* Ajoute à un texte GTK le contenu d'un opérande. */
+static void g_x86_mod_rm_operand_add_to_gtk_buffer(const GX86ModRMOperand *, const GExeFormat *, AsmSyntax, GtkTextBuffer *, GtkTextIter *);
@@ -155,8 +155,8 @@ 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 *);
-/* Traduit un opérande en version humainement lisible. */
-static char *g_x86_relative_operand_get_text(const GX86RelativeOperand *, const GExeFormat *, AsmSyntax);
+/* Ajoute à un texte GTK le contenu d'un opérande. */
+static void g_x86_relative_operand_add_to_gtk_buffer(const GX86RelativeOperand *, const GExeFormat *, AsmSyntax, GtkTextBuffer *, GtkTextIter *);
@@ -186,8 +186,8 @@ 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 *);
-/* Traduit un opérande en version humainement lisible. */
-static char *g_x86_moffs_operand_get_text(const GX86MOffsOperand *, const GExeFormat *, AsmSyntax);
+/* Ajoute à un texte GTK le contenu d'un opérande. */
+static void g_x86_moffs_operand_add_to_gtk_buffer(const GX86MOffsOperand *, const GExeFormat *, AsmSyntax, GtkTextBuffer *, GtkTextIter *);
@@ -278,11 +278,11 @@ static void g_x86_register_operand_class_init(GX86RegisterOperandClass *klass)
static void g_x86_register_operand_init(GX86RegisterOperand *operand)
{
- GArchOperand *parent; /* Instance parente */
+ GContentExporter *parent; /* Instance parente */
- parent = G_ARCH_OPERAND(operand);
+ parent = G_CONTENT_EXPORTER(operand);
- parent->get_text = (get_operand_text_fc)g_x86_register_operand_get_text;
+ parent->add_arch_to_gtk_buffer = (add_arch_to_gtk_buffer_fc)g_x86_register_operand_add_to_gtk_buffer;
}
@@ -306,9 +306,9 @@ static void g_x86_register_operand_init(GX86RegisterOperand *operand)
GArchOperand *g_x86_register_operand_new_from_opcode(const bin_t *data, off_t *pos, off_t len, AsmOperandSize size, bin_t base)
{
GX86RegisterOperand *result; /* Structure à retourner */
- x86_register *reg; /* Registre lu */
+ GX86Register *reg; /* Registre lu */
- reg = get_x86_register(size, data[*pos] - base);
+ reg = g_x86_register_new(size, data[*pos] - base);
if (reg != NULL)
{
@@ -346,12 +346,12 @@ GArchOperand *g_x86_register_operand_new_from_mod_rm(const bin_t *data, off_t *p
{
GX86RegisterOperand *result; /* Structure à retourner */
bin_t index; /* Registre lu */
- x86_register *reg; /* Registre créé */
+ GX86Register *reg; /* Registre créé */
if (first) index = data[*pos] & 0x07;
else index = (data[*pos] & 0x38) >> 3;
- reg = get_x86_register(size, index);
+ reg = g_x86_register_new(size, index);
if (reg != NULL)
{
@@ -385,9 +385,9 @@ GArchOperand *g_x86_register_operand_new_from_mod_rm(const bin_t *data, off_t *p
GArchOperand *g_x86_register_operand_new_from_index(bin_t index, AsmOperandSize size)
{
GX86RegisterOperand *result; /* Structure à retourner */
- x86_register *reg; /* Registre lu */
+ GX86Register *reg; /* Registre lu */
- reg = get_x86_register(size, index);
+ reg = g_x86_register_new(size, index);
if (reg != NULL)
{
@@ -405,25 +405,23 @@ GArchOperand *g_x86_register_operand_new_from_index(bin_t index, AsmOperandSize
/******************************************************************************
* *
-* Paramètres : operand = opérande à traiter. *
-* format = format du binaire manipulé. *
-* syntax = type de représentation demandée. *
+* Paramètres : operand = opérande à transcrire. *
+* format = format du binaire manipulé. *
+* syntax = type de représentation demandée. *
+* buffer = zone de texte à venir compléter. *
+* iter = point d'insertion du nouveau texte. *
* *
-* Description : Traduit un opérande en version humainement lisible. *
+* Description : Ajoute à un texte GTK le contenu d'un opérande. *
* *
-* Retour : Chaîne de caractères à libérer de la mémoire. *
+* Retour : - *
* *
* Remarques : - *
* *
******************************************************************************/
-static char *g_x86_register_operand_get_text(const GX86RegisterOperand *operand, const GExeFormat *format, AsmSyntax syntax)
+static void g_x86_register_operand_add_to_gtk_buffer(const GX86RegisterOperand *operand, const GExeFormat *format, AsmSyntax syntax, GtkTextBuffer *buffer, GtkTextIter *iter)
{
- char *result; /* Chaîne à retourner */
-
- result = x86_register_as_text(operand->reg, syntax);
-
- return result;
+ g_content_exporter_add_arch_to_gtk_buffer(G_CONTENT_EXPORTER(operand->reg), format, syntax, buffer, iter);
}
@@ -470,11 +468,11 @@ static void g_x86_mod_rm_operand_class_init(GX86ModRMOperandClass *klass)
static void g_x86_mod_rm_operand_init(GX86ModRMOperand *operand)
{
- GArchOperand *parent; /* Instance parente */
+ GContentExporter *parent; /* Instance parente */
- parent = G_ARCH_OPERAND(operand);
+ parent = G_CONTENT_EXPORTER(operand);
- parent->get_text = (get_operand_text_fc)g_x86_mod_rm_operand_get_text;
+ parent->add_arch_to_gtk_buffer = (add_arch_to_gtk_buffer_fc)g_x86_mod_rm_operand_add_to_gtk_buffer;
}
@@ -498,43 +496,43 @@ GArchOperand *g_x86_mod_rm_operand_new(const bin_t *data, off_t *pos, off_t len,
{
GX86ModRMOperand *result; /* Structure à retourner */
uint8_t mod; /* Modificateur présent */
- x86_register *reg; /* Registre lu */
+ 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 = get_x86_register(size, data[*pos] & 0x07);
+ reg = g_x86_register_new(size, data[*pos] & 0x07);
if (reg == NULL) return NULL;
(*pos)++;
/* Vieille astuce de l'emplacement mémoire fixe ? */
- if (is_x86_register_base_pointer(reg) && mod == 0x00)
+ if (g_x86_register_is_base_pointer(reg) && mod == 0x00)
{
- free_x86_register(reg);
+ /* FIXME *///free_x86_register(reg);
return g_imm_operand_new_from_data(MDS_32_BITS/* FIXME */, data, pos, len, SRE_LITTLE);
}
result = g_object_new(G_TYPE_X86_MOD_RM_OPERAND, NULL);
/* A la recherche d'un SIB */
- if (is_x86_register_stack_pointer(reg))
+ if (g_x86_register_is_stack_pointer(reg))
{
- free_x86_register(reg);
+ /* FIXME *///free_x86_register(reg);
- result->base = get_x86_register(size, data[*pos] & 0x07);
+ result->base = g_x86_register_new(size, data[*pos] & 0x07);
if (result->base == NULL) goto gxmron_error;
- result->index = get_x86_register(size, (data[*pos] & 0x38) >> 3);
+ 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 (is_x86_register_stack_pointer(result->index))
+ if (g_x86_register_is_stack_pointer(result->index))
{
- free_x86_register(result->index);
+ /* FIXME *///free_x86_register(result->index);
result->index = result->base;
result->base = NULL;
}
@@ -549,9 +547,9 @@ GArchOperand *g_x86_mod_rm_operand_new(const bin_t *data, off_t *pos, off_t len,
switch (mod)
{
case 0x00:
- if (result->base != NULL && is_x86_register_base_pointer(result->base))
+ if (result->base != NULL && g_x86_register_is_base_pointer(result->base))
{
- free_x86_register(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);
@@ -584,72 +582,79 @@ GArchOperand *g_x86_mod_rm_operand_new(const bin_t *data, off_t *pos, off_t len,
/******************************************************************************
* *
-* Paramètres : operand = opérande à traiter. *
-* format = format du binaire manipulé. *
-* syntax = type de représentation demandée. *
+* Paramètres : operand = opérande à transcrire. *
+* format = format du binaire manipulé. *
+* syntax = type de représentation demandée. *
+* buffer = zone de texte à venir compléter. *
+* iter = point d'insertion du nouveau texte. *
* *
-* Description : Traduit un opérande en version humainement lisible. *
+* Description : Ajoute à un texte GTK le contenu d'un opérande. *
* *
-* Retour : Chaîne de caractères à libérer de la mémoire. *
+* Retour : - *
* *
* Remarques : - *
* *
******************************************************************************/
-static char *g_x86_mod_rm_operand_get_text(const GX86ModRMOperand *operand, const GExeFormat *format, AsmSyntax syntax)
+static void g_x86_mod_rm_operand_add_to_gtk_buffer(const GX86ModRMOperand *operand, const GExeFormat *format, AsmSyntax syntax, GtkTextBuffer *buffer, GtkTextIter *iter)
{
- char *result; /* Chaîne à retourner */
- char *tmp; /* Chaîne de registre */
+ char tmp[2]; /* Echelle en puissance de 2 */
switch (syntax)
{
case ASX_INTEL:
- result = (char *)calloc(1 + 10 + 2, sizeof(char));
-
- strcpy(result, "[");
+ g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(operand), buffer, iter,
+ "[", 1, RTT_HOOK);
if (operand->scale > 0)
- snprintf(&result[1], 12, "%d*", (int)pow(2, operand->scale));
-
- tmp = x86_register_as_text(operand->index, syntax);
- result = stradd(result, tmp);
- free(tmp);
-
- if (operand->base != NULL)
{
- result = stradd(result, "+");
+ snprintf(tmp, 2, "%d", (int)pow(2, operand->scale));
+
+ g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(operand), buffer, iter,
+ tmp, 1, RTT_IMMEDIATE);
- tmp = x86_register_as_text(operand->base, syntax);
- result = stradd(result, tmp);
- free(tmp);
+ g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(operand), buffer, iter,
+ "*", 1, RTT_SIGNS);
}
+ g_content_exporter_add_arch_to_gtk_buffer(G_CONTENT_EXPORTER(operand->index),
+ format, syntax, buffer, iter);
+
+ if (operand->base != NULL)
+ g_content_exporter_add_arch_to_gtk_buffer(G_CONTENT_EXPORTER(operand->base),
+ format, syntax, buffer, iter);
+
if (operand->displacement != NULL)
{
- if (g_imm_operand_is_negative(operand->displacement)) result = stradd(result, "-");
- else result = stradd(result, "+");
+ if (g_imm_operand_is_negative(operand->displacement))
+ g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(operand), buffer, iter,
+ "-", 1, RTT_SIGNS);
+ else
+ g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(operand), buffer, iter,
+ "+", 1, RTT_SIGNS);
- tmp = g_arch_operand_get_text(G_ARCH_OPERAND(operand->displacement), format, syntax);
- result = stradd(result, tmp);
- free(tmp);
+ g_content_exporter_add_arch_to_gtk_buffer(G_CONTENT_EXPORTER(operand->displacement),
+ format, syntax, buffer, iter);
}
- result = stradd(result, "]");
+ g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(operand), buffer, iter,
+ "]", 1, RTT_HOOK);
break;
case ASX_ATT:
- result = strdup("[modRM]");
+ /* TODO */
+ g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(operand), buffer, iter,
+ "[ModRM]", 7, RTT_HOOK);
+
break;
}
- return result;
-
}
@@ -667,7 +672,7 @@ static char *g_x86_mod_rm_operand_get_text(const GX86ModRMOperand *operand, cons
* *
******************************************************************************/
-void g_x86_mod_rm_operand_get_scale_and_index(const GX86ModRMOperand *operand, uint8_t *scale, const x86_register **index)
+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;
@@ -687,7 +692,7 @@ void g_x86_mod_rm_operand_get_scale_and_index(const GX86ModRMOperand *operand, u
* *
******************************************************************************/
-const x86_register *g_x86_mod_rm_operand_get_base(const GX86ModRMOperand *operand)
+const GX86Register *g_x86_mod_rm_operand_get_base(const GX86ModRMOperand *operand)
{
return operand->base;
@@ -755,11 +760,11 @@ static void g_x86_relative_operand_class_init(GX86RelativeOperandClass *klass)
static void g_x86_relative_operand_init(GX86RelativeOperand *operand)
{
- GArchOperand *parent; /* Instance parente */
+ GContentExporter *parent; /* Instance parente */
- parent = G_ARCH_OPERAND(operand);
+ parent = G_CONTENT_EXPORTER(operand);
- parent->get_text = (get_operand_text_fc)g_x86_relative_operand_get_text;
+ parent->add_arch_to_gtk_buffer = (add_arch_to_gtk_buffer_fc)g_x86_relative_operand_add_to_gtk_buffer;
}
@@ -822,25 +827,24 @@ GArchOperand *g_x86_relative_operand_new(const bin_t *data, off_t *pos, off_t le
/******************************************************************************
* *
-* Paramètres : operand = opérande à traiter. *
-* format = format du binaire manipulé. *
-* syntax = type de représentation demandée. *
+* Paramètres : operand = opérande à transcrire. *
+* format = format du binaire manipulé. *
+* syntax = type de représentation demandée. *
+* buffer = zone de texte à venir compléter. *
+* iter = point d'insertion du nouveau texte. *
* *
-* Description : Traduit un opérande en version humainement lisible. *
+* Description : Ajoute à un texte GTK le contenu d'un opérande. *
* *
-* Retour : Chaîne de caractères à libérer de la mémoire. *
+* Retour : - *
* *
* Remarques : - *
* *
******************************************************************************/
-static char *g_x86_relative_operand_get_text(const GX86RelativeOperand *operand, const GExeFormat *format, AsmSyntax syntax)
+static void g_x86_relative_operand_add_to_gtk_buffer(const GX86RelativeOperand *operand, const GExeFormat *format, AsmSyntax syntax, GtkTextBuffer *buffer, GtkTextIter *iter)
{
- char *result; /* Chaîne à retourner */
-
- result = g_arch_operand_get_text(operand->immediate, format, syntax);
-
- return result;
+ g_content_exporter_add_arch_to_gtk_buffer(G_CONTENT_EXPORTER(operand->immediate),
+ format, syntax, buffer, iter);
}
@@ -906,11 +910,11 @@ static void g_x86_moffs_operand_class_init(GX86MOffsOperandClass *klass)
static void g_x86_moffs_operand_init(GX86MOffsOperand *operand)
{
- GArchOperand *parent; /* Instance parente */
+ GContentExporter *parent; /* Instance parente */
- parent = G_ARCH_OPERAND(operand);
+ parent = G_CONTENT_EXPORTER(operand);
- parent->get_text = (get_operand_text_fc)g_x86_moffs_operand_get_text;
+ parent->add_arch_to_gtk_buffer = (add_arch_to_gtk_buffer_fc)g_x86_moffs_operand_add_to_gtk_buffer;
}
@@ -952,27 +956,27 @@ GArchOperand *g_x86_moffs_operand_new(const bin_t *data, off_t *pos, off_t len,
/******************************************************************************
* *
-* Paramètres : operand = opérande à traiter. *
-* format = format du binaire manipulé. *
-* syntax = type de représentation demandée. *
+* Paramètres : operand = opérande à transcrire. *
+* format = format du binaire manipulé. *
+* syntax = type de représentation demandée. *
+* buffer = zone de texte à venir compléter. *
+* iter = point d'insertion du nouveau texte. *
* *
-* Description : Traduit un opérande en version humainement lisible. *
+* Description : Ajoute à un texte GTK le contenu d'un opérande. *
* *
-* Retour : Chaîne de caractères à libérer de la mémoire. *
+* Retour : - *
* *
* Remarques : - *
* *
******************************************************************************/
-static char *g_x86_moffs_operand_get_text(const GX86MOffsOperand *operand, const GExeFormat *format, AsmSyntax syntax)
+static void g_x86_moffs_operand_add_to_gtk_buffer(const GX86MOffsOperand *operand, const GExeFormat *format, AsmSyntax syntax, GtkTextBuffer *buffer, GtkTextIter *iter)
{
- char *result; /* Chaîne à retourner */
-
- result = g_arch_operand_get_text(operand->offset, format, syntax);
-
- result = strprep(result, "ds:");
+ g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(operand), buffer, iter,
+ "ds:", 3, RTT_SEGMENT);
- return result;
+ g_content_exporter_add_arch_to_gtk_buffer(G_CONTENT_EXPORTER(operand->offset),
+ format, syntax, buffer, iter);
}
diff --git a/src/arch/x86/operand.h b/src/arch/x86/operand.h
index cbf2ed2..cb04ca8 100644
--- a/src/arch/x86/operand.h
+++ b/src/arch/x86/operand.h
@@ -108,10 +108,10 @@ GType g_x86_mod_rm_operand_get_type(void);
GArchOperand *g_x86_mod_rm_operand_new(const bin_t *, off_t *, off_t, AsmOperandSize);
/* 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 x86_register **);
+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 x86_register *g_x86_mod_rm_operand_get_base(const GX86ModRMOperand *);
+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 *);
diff --git a/src/arch/x86/registers.c b/src/arch/x86/registers.c
index 802e2f6..4e186ed 100644
--- a/src/arch/x86/registers.c
+++ b/src/arch/x86/registers.c
@@ -24,10 +24,12 @@
#include "registers.h"
-#include <malloc.h>
#include <stdio.h>
+#include "../operand-int.h"
+
+
/* Liste des registres 8 bits */
typedef enum _X868bRegister
@@ -78,9 +80,13 @@ typedef enum _X8632bRegister
} X8632bRegister;
-/* Registre x86 */
-struct _x86_register
+/* Représentation d'un registre x86 (instance) */
+struct _GX86Register
{
+ GArchOperand parent; /* Instance parente */
+
+ MemoryDataSize size; /* Taille de ce registre */
+
union
{
X868bRegister reg8; /* Registre 8 bits */
@@ -89,30 +95,85 @@ struct _x86_register
} reg;
- AsmOperandSize size; /* Taille de ce registre */
+};
+
+
+/* Représentation d'un registre x86 (classe) */
+struct _GX86RegisterClass
+{
+ GArchOperandClass parent; /* Classe parente */
};
+/* Ajoute à un texte GTK le contenu d'un opérande. */
+static void g_x86_register_add_to_gtk_buffer(const GX86Register *, const GExeFormat *, AsmSyntax, GtkTextBuffer *, GtkTextIter *);
+
+
+
+/* Indique le type défini pour une représentation d'un registre x86. */
+G_DEFINE_TYPE(GX86Register, g_x86_register, G_TYPE_CONTENT_EXPORTER);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des lignes de représentation. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_x86_register_class_init(GX86RegisterClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : reg = instance à initialiser. *
+* *
+* Description : Initialise une instance de ligne de représentation. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_x86_register_init(GX86Register *reg)
+{
+ GContentExporter *parent; /* Instance parente */
+
+ parent = G_CONTENT_EXPORTER(reg);
+
+ parent->add_arch_to_gtk_buffer = (add_arch_to_gtk_buffer_fc)g_x86_register_add_to_gtk_buffer;
+
+}
+
/******************************************************************************
* *
* Paramètres : size = indique la taille du registre. *
* value = valeur correspondant au registre. *
* *
-* Description : Récupère l'indentifiant interne d'un registre. *
+* Description : Crée une réprésentation de registre x86. *
* *
-* Retour : Registre définit ou NULL. *
+* Retour : Adresse de la structure mise en place. *
* *
* Remarques : - *
* *
******************************************************************************/
-x86_register *get_x86_register(AsmOperandSize size, bin_t value)
+GX86Register *g_x86_register_new(MemoryDataSize size, bin_t value)
{
- x86_register *result; /* Représentation à renvoyer */
+ GX86Register *result; /* Structure à retourner */
- result = (x86_register *)calloc(1, sizeof(x86_register));
+ result = g_object_new(G_TYPE_X86_REGISTER, NULL);
result->size = size;
@@ -125,7 +186,7 @@ x86_register *get_x86_register(AsmOperandSize size, bin_t value)
result->reg.reg8 = (X868bRegister)value;
break;
default:
- goto gxr_error;
+ goto gxrn_error;
break;
}
break;
@@ -137,7 +198,7 @@ x86_register *get_x86_register(AsmOperandSize size, bin_t value)
result->reg.reg16 = (X8616bRegister)value;
break;
default:
- goto gxr_error;
+ goto gxrn_error;
break;
}
break;
@@ -149,22 +210,22 @@ x86_register *get_x86_register(AsmOperandSize size, bin_t value)
result->reg.reg32 = (X8632bRegister)value;
break;
default:
- goto gxr_error;
+ goto gxrn_error;
break;
}
break;
default:
- goto gxr_error;
+ goto gxrn_error;
break;
}
return result;
- gxr_error:
+ gxrn_error:
- free(result);
+ /* FIXME free(result); */
return NULL;
@@ -173,133 +234,26 @@ x86_register *get_x86_register(AsmOperandSize size, bin_t value)
/******************************************************************************
* *
-* Paramètres : reg = registre à supprimer. *
-* *
-* Description : Efface de la mémoire l'indentifiant interne d'un registre. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-void free_x86_register(x86_register *reg)
-{
- free(reg);
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : reg = registre à consulter. *
-* *
-* Description : Indique si le registre correspond à ebp ou similaire. *
-* *
-* Retour : true si la correspondance est avérée, false sinon. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool is_x86_register_base_pointer(const x86_register *reg)
-{
- bool result; /* Bilan à remonter */
-
- switch (reg->size)
- {
- case AOS_8_BITS_UNSIGNED:
- case AOS_8_BITS_SIGNED:
- result = (reg->reg.reg8 == X86_REG8_CH);
- break;
- case AOS_16_BITS_UNSIGNED:
- case AOS_16_BITS_SIGNED:
- result = (reg->reg.reg16 == X86_REG16_BP);
- break;
- case AOS_32_BITS_UNSIGNED:
- case AOS_32_BITS_SIGNED:
- result = (reg->reg.reg32 == X86_REG32_EBP);
- break;
- /*
- case AOS_64_BITS_UNSIGNED:
- case AOS_64_BITS_SIGNED:
- result = (reg->reg.reg8 == X86_REG8_CH);
- break;
- */
- default:
- result = false;
-
- }
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : reg = registre à consulter. *
-* *
-* Description : Indique si le registre correspond à esp ou similaire. *
-* *
-* Retour : true si la correspondance est avérée, false sinon. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool is_x86_register_stack_pointer(const x86_register *reg)
-{
- bool result; /* Bilan à remonter */
-
- switch (reg->size)
- {
- case AOS_8_BITS_UNSIGNED:
- case AOS_8_BITS_SIGNED:
- result = (reg->reg.reg8 == X86_REG8_AH);
- break;
- case AOS_16_BITS_UNSIGNED:
- case AOS_16_BITS_SIGNED:
- result = (reg->reg.reg16 == X86_REG16_SP);
- break;
- case AOS_32_BITS_UNSIGNED:
- case AOS_32_BITS_SIGNED:
- result = (reg->reg.reg32 == X86_REG32_ESP);
- break;
- /*
- case AOS_64_BITS_UNSIGNED:
- case AOS_64_BITS_SIGNED:
- result = (reg->reg.reg8 == X86_REG8_CH);
- break;
- */
- default:
- result = false;
-
- }
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : reg = registre à imprimer. *
+* Paramètres : operand = opérande à transcrire. *
+* format = format du binaire manipulé. *
* syntax = type de représentation demandée. *
+* buffer = zone de texte à venir compléter. *
+* iter = point d'insertion du nouveau texte. *
* *
-* Description : Traduit un registre x86 en texte. *
+* Description : Ajoute à un texte GTK le contenu d'un opérande. *
* *
-* Retour : Traduction en chaîne à libérer de la mémoire. *
+* Retour : - *
* *
* Remarques : - *
* *
******************************************************************************/
-char *x86_register_as_text(const x86_register *reg, AsmSyntax syntax)
+static void g_x86_register_add_to_gtk_buffer(const GX86Register *reg, const GExeFormat *format, AsmSyntax syntax, GtkTextBuffer *buffer, GtkTextIter *iter)
{
- char *result; /* Chaîne à renvoyer */
+ char key[5]; /* Mot clef principal */
+ size_t klen; /* Taille de ce mot clef */
- result = (char *)calloc(5, sizeof(char));
+ klen = 0;
switch (syntax)
{
@@ -307,31 +261,32 @@ char *x86_register_as_text(const x86_register *reg, AsmSyntax syntax)
switch (reg->size)
{
case AOS_8_BITS:
+ klen = 2;
switch (reg->reg.reg8)
{
case X86_REG8_AL:
- snprintf(result, 5, "al");
+ snprintf(key, 5, "al");
break;
case X86_REG8_CL:
- snprintf(result, 5, "cl");
+ snprintf(key, 5, "cl");
break;
case X86_REG8_DL:
- snprintf(result, 5, "dl");
+ snprintf(key, 5, "dl");
break;
case X86_REG8_BL:
- snprintf(result, 5, "bl");
+ snprintf(key, 5, "bl");
break;
case X86_REG8_AH:
- snprintf(result, 5, "ah");
+ snprintf(key, 5, "ah");
break;
case X86_REG8_CH:
- snprintf(result, 5, "ch");
+ snprintf(key, 5, "ch");
break;
case X86_REG8_DH:
- snprintf(result, 5, "dh");
+ snprintf(key, 5, "dh");
break;
case X86_REG8_BH:
- snprintf(result, 5, "bh");
+ snprintf(key, 5, "bh");
break;
case X86_REG8_NONE:
/* Ne devrait jamais arriver */
@@ -340,31 +295,32 @@ char *x86_register_as_text(const x86_register *reg, AsmSyntax syntax)
break;
case AOS_16_BITS:
+ klen = 2;
switch (reg->reg.reg16)
{
case X86_REG16_AX:
- snprintf(result, 5, "ax");
+ snprintf(key, 5, "ax");
break;
case X86_REG16_CX:
- snprintf(result, 5, "cx");
+ snprintf(key, 5, "cx");
break;
case X86_REG16_DX:
- snprintf(result, 5, "dx");
+ snprintf(key, 5, "dx");
break;
case X86_REG16_BX:
- snprintf(result, 5, "bx");
+ snprintf(key, 5, "bx");
break;
case X86_REG16_SP:
- snprintf(result, 5, "sp");
+ snprintf(key, 5, "sp");
break;
case X86_REG16_BP:
- snprintf(result, 5, "bp");
+ snprintf(key, 5, "bp");
break;
case X86_REG16_SI:
- snprintf(result, 5, "si");
+ snprintf(key, 5, "si");
break;
case X86_REG16_DI:
- snprintf(result, 5, "di");
+ snprintf(key, 5, "di");
break;
case X86_REG16_NONE:
/* Ne devrait jamais arriver */
@@ -373,31 +329,32 @@ char *x86_register_as_text(const x86_register *reg, AsmSyntax syntax)
break;
case AOS_32_BITS:
+ klen = 3;
switch (reg->reg.reg32)
{
case X86_REG32_EAX:
- snprintf(result, 5, "eax");
+ snprintf(key, 5, "eax");
break;
case X86_REG32_ECX:
- snprintf(result, 5, "ecx");
+ snprintf(key, 5, "ecx");
break;
case X86_REG32_EDX:
- snprintf(result, 5, "edx");
+ snprintf(key, 5, "edx");
break;
case X86_REG32_EBX:
- snprintf(result, 5, "ebx");
+ snprintf(key, 5, "ebx");
break;
case X86_REG32_ESP:
- snprintf(result, 5, "esp");
+ snprintf(key, 5, "esp");
break;
case X86_REG32_EBP:
- snprintf(result, 5, "ebp");
+ snprintf(key, 5, "ebp");
break;
case X86_REG32_ESI:
- snprintf(result, 5, "esi");
+ snprintf(key, 5, "esi");
break;
case X86_REG32_EDI:
- snprintf(result, 5, "edi");
+ snprintf(key, 5, "edi");
break;
case X86_REG32_NONE:
printf("null reg\n");
@@ -416,31 +373,32 @@ char *x86_register_as_text(const x86_register *reg, AsmSyntax syntax)
switch (reg->size)
{
case AOS_8_BITS:
+ klen = 3;
switch (reg->reg.reg8)
{
case X86_REG8_AL:
- snprintf(result, 5, "%%al");
+ snprintf(key, 5, "%%al");
break;
case X86_REG8_CL:
- snprintf(result, 5, "%%cl");
+ snprintf(key, 5, "%%cl");
break;
case X86_REG8_DL:
- snprintf(result, 5, "%%dl");
+ snprintf(key, 5, "%%dl");
break;
case X86_REG8_BL:
- snprintf(result, 5, "%%bl");
+ snprintf(key, 5, "%%bl");
break;
case X86_REG8_AH:
- snprintf(result, 5, "%%ah");
+ snprintf(key, 5, "%%ah");
break;
case X86_REG8_CH:
- snprintf(result, 5, "%%ch");
+ snprintf(key, 5, "%%ch");
break;
case X86_REG8_DH:
- snprintf(result, 5, "%%dh");
+ snprintf(key, 5, "%%dh");
break;
case X86_REG8_BH:
- snprintf(result, 5, "%%bh");
+ snprintf(key, 5, "%%bh");
break;
case X86_REG8_NONE:
/* Ne devrait jamais arriver */
@@ -449,31 +407,32 @@ char *x86_register_as_text(const x86_register *reg, AsmSyntax syntax)
break;
case AOS_16_BITS:
+ klen = 3;
switch (reg->reg.reg16)
{
case X86_REG16_AX:
- snprintf(result, 5, "%%ax");
+ snprintf(key, 5, "%%ax");
break;
case X86_REG16_CX:
- snprintf(result, 5, "%%cx");
+ snprintf(key, 5, "%%cx");
break;
case X86_REG16_DX:
- snprintf(result, 5, "%%dx");
+ snprintf(key, 5, "%%dx");
break;
case X86_REG16_BX:
- snprintf(result, 5, "%%bx");
+ snprintf(key, 5, "%%bx");
break;
case X86_REG16_SP:
- snprintf(result, 5, "%%sp");
+ snprintf(key, 5, "%%sp");
break;
case X86_REG16_BP:
- snprintf(result, 5, "%%bp");
+ snprintf(key, 5, "%%bp");
break;
case X86_REG16_SI:
- snprintf(result, 5, "%%si");
+ snprintf(key, 5, "%%si");
break;
case X86_REG16_DI:
- snprintf(result, 5, "%%di");
+ snprintf(key, 5, "%%di");
break;
case X86_REG16_NONE:
/* Ne devrait jamais arriver */
@@ -482,31 +441,32 @@ char *x86_register_as_text(const x86_register *reg, AsmSyntax syntax)
break;
case AOS_32_BITS:
+ klen = 4;
switch (reg->reg.reg32)
{
case X86_REG32_EAX:
- snprintf(result, 5, "%%eax");
+ snprintf(key, 5, "%%eax");
break;
case X86_REG32_ECX:
- snprintf(result, 5, "%%ecx");
+ snprintf(key, 5, "%%ecx");
break;
case X86_REG32_EDX:
- snprintf(result, 5, "%%edx");
+ snprintf(key, 5, "%%edx");
break;
case X86_REG32_EBX:
- snprintf(result, 5, "%%ebx");
+ snprintf(key, 5, "%%ebx");
break;
case X86_REG32_ESP:
- snprintf(result, 5, "%%esp");
+ snprintf(key, 5, "%%esp");
break;
case X86_REG32_EBP:
- snprintf(result, 5, "%%ebp");
+ snprintf(key, 5, "%%ebp");
break;
case X86_REG32_ESI:
- snprintf(result, 5, "%%esi");
+ snprintf(key, 5, "%%esi");
break;
case X86_REG32_EDI:
- snprintf(result, 5, "%%edi");
+ snprintf(key, 5, "%%edi");
break;
case X86_REG32_NONE:
/* Ne devrait jamais arriver */
@@ -525,6 +485,99 @@ char *x86_register_as_text(const x86_register *reg, AsmSyntax syntax)
}
+ g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(reg), buffer, iter,
+ key, klen, RTT_REGISTER);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : reg = registre à consulter. *
+* *
+* Description : Indique si le registre correspond à ebp ou similaire. *
+* *
+* Retour : true si la correspondance est avérée, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_x86_register_is_base_pointer(const GX86Register *reg)
+{
+ bool result; /* Bilan à remonter */
+
+ switch (reg->size)
+ {
+ case AOS_8_BITS_UNSIGNED:
+ case AOS_8_BITS_SIGNED:
+ result = (reg->reg.reg8 == X86_REG8_CH);
+ break;
+ case AOS_16_BITS_UNSIGNED:
+ case AOS_16_BITS_SIGNED:
+ result = (reg->reg.reg16 == X86_REG16_BP);
+ break;
+ case AOS_32_BITS_UNSIGNED:
+ case AOS_32_BITS_SIGNED:
+ result = (reg->reg.reg32 == X86_REG32_EBP);
+ break;
+ /*
+ case AOS_64_BITS_UNSIGNED:
+ case AOS_64_BITS_SIGNED:
+ result = (reg->reg.reg8 == X86_REG8_CH);
+ break;
+ */
+ default:
+ result = false;
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : reg = registre à consulter. *
+* *
+* Description : Indique si le registre correspond à esp ou similaire. *
+* *
+* Retour : true si la correspondance est avérée, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_x86_register_is_stack_pointer(const GX86Register *reg)
+{
+ bool result; /* Bilan à remonter */
+
+ switch (reg->size)
+ {
+ case AOS_8_BITS_UNSIGNED:
+ case AOS_8_BITS_SIGNED:
+ result = (reg->reg.reg8 == X86_REG8_AH);
+ break;
+ case AOS_16_BITS_UNSIGNED:
+ case AOS_16_BITS_SIGNED:
+ result = (reg->reg.reg16 == X86_REG16_SP);
+ break;
+ case AOS_32_BITS_UNSIGNED:
+ case AOS_32_BITS_SIGNED:
+ result = (reg->reg.reg32 == X86_REG32_ESP);
+ break;
+ /*
+ case AOS_64_BITS_UNSIGNED:
+ case AOS_64_BITS_SIGNED:
+ result = (reg->reg.reg8 == X86_REG8_CH);
+ break;
+ */
+ default:
+ result = false;
+
+ }
+
return result;
}
diff --git a/src/arch/x86/registers.h b/src/arch/x86/registers.h
index 491d5bc..18bced7 100644
--- a/src/arch/x86/registers.h
+++ b/src/arch/x86/registers.h
@@ -25,29 +25,40 @@
#define _ARCH_X86_REGISTERS_H
+#include <glib-object.h>
+#include <stdbool.h>
+
+
#include "../archbase.h"
-#include "../operand.h"
-/* Registre x86 */
-typedef struct _x86_register x86_register;
+#define G_TYPE_X86_REGISTER g_x86_register_get_type()
+#define G_X86_REGISTER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_x86_register_get_type(), GX86Register))
+#define G_IS_X86_REGISTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_x86_register_get_type()))
+#define G_X86_REGISTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_X86_REGISTER, GX86RegisterClass))
+#define G_IS_X86_REGISTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_X86_REGISTER))
+#define G_X86_REGISTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_X86_REGISTER, GX86RegisterClass))
+
+/* Représentation d'un registre x86 (instance) */
+typedef struct _GX86Register GX86Register;
-/* Récupère l'indentifiant interne d'un registre. */
-x86_register *get_x86_register(AsmOperandSize, bin_t);
+/* Représentation d'un registre x86 (classe) */
+typedef struct _GX86RegisterClass GX86RegisterClass;
-/* Efface de la mémoire l'indentifiant interne d'un registre. */
-void free_x86_register(x86_register *);
+
+/* Indique le type défini pour une représentation d'un registre x86. */
+GType g_x86_register_get_type(void);
+
+/* Crée une réprésentation de registre x86. */
+GX86Register *g_x86_register_new(MemoryDataSize, bin_t);
/* Indique si le registre correspond à ebp ou similaire. */
-bool is_x86_register_base_pointer(const x86_register *);
+bool g_x86_register_is_base_pointer(const GX86Register *);
/* Indique si le registre correspond à esp ou similaire. */
-bool is_x86_register_stack_pointer(const x86_register *);
-
-/* Traduit un registre x86 en texte. */
-char *x86_register_as_text(const x86_register *, AsmSyntax);
+bool g_x86_register_is_stack_pointer(const GX86Register *);