summaryrefslogtreecommitdiff
path: root/src/arch/x86/operand.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/x86/operand.c')
-rw-r--r--src/arch/x86/operand.c220
1 files changed, 112 insertions, 108 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);
}