diff options
Diffstat (limited to 'plugins/stackvars/operand.c')
-rw-r--r-- | plugins/stackvars/operand.c | 62 |
1 files changed, 40 insertions, 22 deletions
diff --git a/plugins/stackvars/operand.c b/plugins/stackvars/operand.c index 6eff546..387f766 100644 --- a/plugins/stackvars/operand.c +++ b/plugins/stackvars/operand.c @@ -24,8 +24,8 @@ #include "operand.h" -#include <malloc.h> #include <stdio.h> +#include <string.h> #include <arch/operand-int.h> @@ -37,7 +37,8 @@ struct _GStackVarOperand { GArchOperand parent; /* Instance parente */ - const GArchOperand *child; /* Opérand d'origine substitué */ + const GBinRoutine *routine; /* Routine d'appartenance */ + const GX86ModRMOperand *child; /* Opérand d'origine substitué */ }; @@ -56,15 +57,15 @@ static void g_stack_var_operand_class_init(GStackVarOperandClass *); /* Initialise l'instande d'un opérandes de substitution. */ static void g_stack_var_operand_init(GStackVarOperand *); -/* Traduit un opérande en version humainement lisible. */ -static char *g_stack_var_operand_get_text(const GStackVarOperand *, const GExeFormat *, AsmSyntax); +/* Ajoute à un texte GTK le contenu d'un opérande. */ +static void g_stack_var_operand_add_to_gtk_buffer(const GStackVarOperand *, const GExeFormat *, AsmSyntax, GtkTextBuffer *, GtkTextIter *); + /* Indique le type défini pour un opérande de substitution pour variable de pile. */ G_DEFINE_TYPE(GStackVarOperand, g_stack_var_operand, G_TYPE_ARCH_OPERAND); - /****************************************************************************** * * * Paramètres : klass = classe à initialiser. * @@ -97,18 +98,19 @@ static void g_stack_var_operand_class_init(GStackVarOperandClass *klass) static void g_stack_var_operand_init(GStackVarOperand *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_stack_var_operand_get_text; + parent->add_arch_to_gtk_buffer = (add_arch_to_gtk_buffer_fc)g_stack_var_operand_add_to_gtk_buffer; } /****************************************************************************** * * -* Paramètres : child = opérande d'origine à substituer. * +* Paramètres : routine = routine d'appatenance de l'opérande. * +* child = opérande d'origine à substituer. * * * * Description : Crée un opérande de substitution pour variable de pile. * * * @@ -118,41 +120,57 @@ static void g_stack_var_operand_init(GStackVarOperand *operand) * * ******************************************************************************/ -GArchOperand *g_stack_var_operand_new(const GArchOperand *child) +GArchOperand *g_stack_var_operand_new(const GBinRoutine *routine, const GX86ModRMOperand *child) { - GStackVarOperand *result; /* Opérande à retourner */ + GStackVarOperand *result; /* Opérande à retourner */ result = g_object_new(G_TYPE_STACK_VAR_OPERAND, NULL); + result->routine = routine; result->child = child; - return result; + return G_ARCH_OPERAND(result); } /****************************************************************************** * * -* 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_stack_var_operand_get_text(const GStackVarOperand *operand, const GExeFormat *format, AsmSyntax syntax) +static void g_stack_var_operand_add_to_gtk_buffer(const GStackVarOperand *operand, const GExeFormat *format, AsmSyntax syntax, GtkTextBuffer *buffer, GtkTextIter *iter) { - char *result; /* Chaîne à retourner */ + const GImmOperand *displacement; /* Décallage supplémentaire */ + size_t value; /* Position dans la pile */ + bool negative; /* Direction dans la pile */ + size_t index; /* Indice de la variable */ + char name[32]; /* Nom de la variable */ + + displacement = g_x86_mod_rm_operand_get_displacement(operand->child); + g_imm_operand_to_size_t(displacement, &value, &negative); + + g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(operand), buffer, iter, + "[", 1, RTT_HOOK); - result = (char *)calloc(19, sizeof(char)); + index = g_binary_routine_get_var_index_from_offset(operand->routine, value, negative); + snprintf(name, 32, "%s%u", negative ? "local" : "arg", index); - snprintf(result, 19, "[<b>varX</b>]"); + g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(operand), buffer, iter, + name, strlen(name), RTT_VAR_NAME); - return result; + g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(operand), buffer, iter, + "]", 1, RTT_HOOK); } |