summaryrefslogtreecommitdiff
path: root/src/arch/immediate.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/immediate.c')
-rw-r--r--src/arch/immediate.c173
1 files changed, 111 insertions, 62 deletions
diff --git a/src/arch/immediate.c b/src/arch/immediate.c
index f8bba35..54d8135 100644
--- a/src/arch/immediate.c
+++ b/src/arch/immediate.c
@@ -27,6 +27,7 @@
#include <malloc.h>
#include <stdarg.h>
#include <stdio.h>
+#include <string.h>
#include "operand-int.h"
@@ -83,8 +84,8 @@ static void g_imm_operand_class_init(GImmOperandClass *);
/* Initialise la classe des lignes de descriptions initiales. */
static void g_imm_operand_init(GImmOperand *);
-/* Traduit un opérande en version humainement lisible. */
-static char *g_imm_operand_get_text(const GImmOperand *, const GExeFormat *, AsmSyntax);
+/* Ajoute à un texte GTK le contenu d'un opérande. */
+static void g_imm_operand_add_to_gtk_buffer(const GImmOperand *, const GExeFormat *, AsmSyntax, GtkTextBuffer *, GtkTextIter *);
/* Indique le type défini pour un opérande de valeur numérique. */
@@ -124,11 +125,11 @@ static void g_imm_operand_class_init(GImmOperandClass *klass)
static void g_imm_operand_init(GImmOperand *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_imm_operand_get_text;
+ parent->add_arch_to_gtk_buffer = (add_arch_to_gtk_buffer_fc)g_imm_operand_add_to_gtk_buffer;
}
@@ -174,21 +175,35 @@ GArchOperand *g_imm_operand_new_from_data(MemoryDataSize size, const bin_t *data
goto gionfd_error;
break;
+ case AOS_64_BITS_UNSIGNED:
+ if (!read_u64(&result->unsigned_imm.val64, data, pos, len, endian))
+ goto gionfd_error;
+ break;
+
case AOS_8_BITS_SIGNED:
- if (!read_u8(&result->signed_imm.val8, data, pos, len, endian))
+ if (!read_s8(&result->signed_imm.val8, data, pos, len, endian))
goto gionfd_error;
break;
case AOS_16_BITS_SIGNED:
- if (!read_u16(&result->signed_imm.val16, data, pos, len, endian))
+ if (!read_s16(&result->signed_imm.val16, data, pos, len, endian))
goto gionfd_error;
break;
case AOS_32_BITS_SIGNED:
- if (!read_u32(&result->signed_imm.val32, data, pos, len, endian))
+ if (!read_s32(&result->signed_imm.val32, data, pos, len, endian))
goto gionfd_error;
break;
+ case AOS_64_BITS_SIGNED:
+ if (!read_s64(&result->signed_imm.val64, data, pos, len, endian))
+ goto gionfd_error;
+ break;
+
+ case MDS_UNDEFINED:
+ goto gionfd_error;
+ break;
+
}
return G_ARCH_OPERAND(result);
@@ -326,74 +341,73 @@ bool g_imm_operand_is_negative(const GImmOperand *operand)
/******************************************************************************
* *
-* 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_imm_operand_get_text(const GImmOperand *operand, const GExeFormat *format, AsmSyntax syntax)
+static void g_imm_operand_add_to_gtk_buffer(const GImmOperand *operand, const GExeFormat *format, AsmSyntax syntax, GtkTextBuffer *buffer, GtkTextIter *iter)
{
- char *result; /* Chaîne à retourner */
+ char value[VMPA_MAX_SIZE]; /* Chaîne à imprimer */
vmpa_t address; /* Décallage final constaté */
const char *label; /* Etiquette de symbole */
SymbolType symtype; /* Type de symbole */
char *printable; /* Version texte présentable */
- char buffer[256]; /* Complément d'information */
/* Valeur brute */
- result = (char *)calloc(19, sizeof(char));
-
switch (syntax)
{
case ASX_INTEL:
switch (operand->size)
{
case MDS_UNDEFINED:
- snprintf(result, 19, "$0x???");
+ snprintf(value, VMPA_MAX_SIZE, "0x???");
break;
case AOS_8_BITS_UNSIGNED:
- snprintf(result, 19, "0x%hhx", operand->unsigned_imm.val8);
+ snprintf(value, VMPA_MAX_SIZE, "0x%hhx", operand->unsigned_imm.val8);
break;
case AOS_16_BITS_UNSIGNED:
- snprintf(result, 19, "0x%hx", operand->unsigned_imm.val16);
+ snprintf(value, VMPA_MAX_SIZE, "0x%hx", operand->unsigned_imm.val16);
break;
case AOS_32_BITS_UNSIGNED:
- snprintf(result, 19, "0x%x", operand->unsigned_imm.val32);
+ snprintf(value, VMPA_MAX_SIZE, "0x%x", operand->unsigned_imm.val32);
break;
case AOS_64_BITS_UNSIGNED:
- snprintf(result, 19, "0x%llx", operand->unsigned_imm.val64);
+ snprintf(value, VMPA_MAX_SIZE, "0x%llx", operand->unsigned_imm.val64);
break;
case AOS_8_BITS_SIGNED:
if (g_imm_operand_is_negative(operand))
- snprintf(result, 19, "0x%hhx", ~operand->signed_imm.val8 + 1);
+ snprintf(value, VMPA_MAX_SIZE, "0x%hhx", ~operand->signed_imm.val8 + 1);
else
- snprintf(result, 19, "0x%hhx", operand->signed_imm.val8);
+ snprintf(value, VMPA_MAX_SIZE, "0x%hhx", operand->signed_imm.val8);
break;
case AOS_16_BITS_SIGNED:
if (g_imm_operand_is_negative(operand))
- snprintf(result, 19, "0x%hx", ~operand->signed_imm.val16 + 1);
+ snprintf(value, VMPA_MAX_SIZE, "0x%hx", ~operand->signed_imm.val16 + 1);
else
- snprintf(result, 19, "0x%hx", operand->signed_imm.val16);
+ snprintf(value, VMPA_MAX_SIZE, "0x%hx", operand->signed_imm.val16);
break;
case AOS_32_BITS_SIGNED:
if (g_imm_operand_is_negative(operand))
- snprintf(result, 19, "0x%x", ~operand->signed_imm.val32 + 1);
+ snprintf(value, VMPA_MAX_SIZE, "0x%x", ~operand->signed_imm.val32 + 1);
else
- snprintf(result, 19, "0x%x", operand->signed_imm.val32);
+ snprintf(value, VMPA_MAX_SIZE, "0x%x", operand->signed_imm.val32);
break;
case AOS_64_BITS_SIGNED:
if (g_imm_operand_is_negative(operand))
- snprintf(result, 19, "0x%llx", ~operand->signed_imm.val64 + 1);
+ snprintf(value, VMPA_MAX_SIZE, "0x%llx", ~operand->signed_imm.val64 + 1);
else
- snprintf(result, 19, "0x%llx", operand->signed_imm.val64);
+ snprintf(value, VMPA_MAX_SIZE, "0x%llx", operand->signed_imm.val64);
break;
}
break;
@@ -402,63 +416,100 @@ static char *g_imm_operand_get_text(const GImmOperand *operand, const GExeFormat
switch (operand->size)
{
case MDS_UNDEFINED:
- snprintf(result, 19, "$0x???");
+ snprintf(value, VMPA_MAX_SIZE, "$0x???");
break;
case AOS_8_BITS_UNSIGNED:
- snprintf(result, 19, "$0x%hhx", operand->unsigned_imm.val8);
+ snprintf(value, VMPA_MAX_SIZE, "$0x%hhx", operand->unsigned_imm.val8);
break;
case AOS_16_BITS_UNSIGNED:
- snprintf(result, 19, "$0x%hx", operand->unsigned_imm.val16);
+ snprintf(value, VMPA_MAX_SIZE, "$0x%hx", operand->unsigned_imm.val16);
break;
case AOS_32_BITS_UNSIGNED:
- snprintf(result, 19, "$0x%x", operand->unsigned_imm.val32);
+ snprintf(value, VMPA_MAX_SIZE, "$0x%x", operand->unsigned_imm.val32);
break;
case AOS_64_BITS_UNSIGNED:
- snprintf(result, 19, "$0x%llx", operand->unsigned_imm.val64);
+ snprintf(value, VMPA_MAX_SIZE, "$0x%llx", operand->unsigned_imm.val64);
break;
case AOS_8_BITS_SIGNED:
- snprintf(result, 19, "$0x%hhx", ~operand->signed_imm.val8 + 1);
+ snprintf(value, VMPA_MAX_SIZE, "$0x%hhx", ~operand->signed_imm.val8 + 1);
break;
case AOS_16_BITS_SIGNED:
- snprintf(result, 19, "$0x%hx", ~operand->signed_imm.val16 + 1);
+ snprintf(value, VMPA_MAX_SIZE, "$0x%hx", ~operand->signed_imm.val16 + 1);
break;
case AOS_32_BITS_SIGNED:
- snprintf(result, 19, "$0x%x", ~operand->signed_imm.val32 + 1);
+ snprintf(value, VMPA_MAX_SIZE, "$0x%x", ~operand->signed_imm.val32 + 1);
break;
case AOS_64_BITS_SIGNED:
- snprintf(result, 19, "$0x%llx", ~operand->signed_imm.val64 + 1);
+ snprintf(value, VMPA_MAX_SIZE, "$0x%llx", ~operand->signed_imm.val64 + 1);
break;
}
break;
+ default:
+ break;
+
}
+ g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(operand), buffer, iter,
+ value, strlen(value), RTT_IMMEDIATE);
+
/* Complément d'information */
- if (operand->size == AOS_32_BITS_SIGNED || operand->size == AOS_32_BITS_UNSIGNED) /* FIXME */
+ if (operand->size == g_arch_processor_get_memory_size(get_arch_processor_from_format(format)))
{
- address = operand->unsigned_imm.val32; /* FIXME !!! */
-
- if (g_binary_format_resolve_symbol(G_BIN_FORMAT(format), &label, &symtype, &address))
+ if (g_imm_operand_to_vmpa_t(operand, &address))
{
- switch (symtype)
+ if (g_binary_format_resolve_symbol(G_BIN_FORMAT(format), &label, &symtype, &address))
{
- case STP_OBJECT:
- case STP_FUNCTION:
- if (address == 0) snprintf(buffer, 256, " &lt;%s&gt;", label);
- else snprintf(buffer, 256, " &lt;%s+0x%llx&gt;", label, address);
- result = stradd(result, buffer);
- break;
+ switch (symtype)
+ {
+ case STP_OBJECT:
+ case STP_FUNCTION:
+ g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(operand), buffer, iter,
+ " ", 1, RTT_NONE);
+ g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(operand), buffer, iter,
+ "<", 1, RTT_LTGT);
- case STP_STRING:
- printable = strdup(label);
- printable = escape_crlf(printable);
- printable = strrpl(printable, "<", "&lt;");
- printable = strrpl(printable, ">", "&gt;");
- snprintf(buffer, 256, " \"%s\"", printable);
- result = stradd(result, buffer);
- free(printable);
- break;
+ g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(operand), buffer, iter,
+ label, strlen(label), RTT_LTGT);
+
+ if (address > 0)
+ {
+ g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(operand), buffer, iter,
+ "+", 1, RTT_LTGT);
+
+ snprintf(value, VMPA_MAX_SIZE, "0x%llx", address);
+
+ g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(operand), buffer, iter,
+ value, strlen(value), RTT_LTGT);
+
+ }
+
+ g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(operand), buffer, iter,
+ ">", 1, RTT_LTGT);
+
+ break;
+
+ case STP_STRING:
+ printable = strdup(label);
+ printable = escape_crlf(printable);
+ /*printable = strrpl(printable, "<", "&lt;");
+ printable = strrpl(printable, ">", "&gt;");*/
+
+ g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(operand), buffer, iter,
+ " ", 1, RTT_NONE);
+ g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(operand), buffer, iter,
+ "\"", 1, RTT_STRING);
+ g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(operand), buffer, iter,
+ printable, strlen(printable), RTT_STRING);
+ g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(operand), buffer, iter,
+ "\"", 1, RTT_STRING);
+
+ free(printable);
+
+ break;
+
+ }
}
@@ -466,8 +517,6 @@ static char *g_imm_operand_get_text(const GImmOperand *operand, const GExeFormat
}
- return result;
-
}