diff options
Diffstat (limited to 'src/arch/immediate.c')
-rw-r--r-- | src/arch/immediate.c | 130 |
1 files changed, 120 insertions, 10 deletions
diff --git a/src/arch/immediate.c b/src/arch/immediate.c index 5df1f42..5970f06 100644 --- a/src/arch/immediate.c +++ b/src/arch/immediate.c @@ -25,6 +25,7 @@ #include <assert.h> +#include <ctype.h> #include <inttypes.h> #include <malloc.h> #include <stdarg.h> @@ -32,6 +33,9 @@ #include <string.h> +#include <i18n.h> + + #include "operand-int.h" #include "../common/asm.h" #include "../common/extstr.h" @@ -79,9 +83,15 @@ static void g_imm_operand_dispose(GImmOperand *); /* Procède à la libération totale de la mémoire. */ static void g_imm_operand_finalize(GImmOperand *); +/* Construit la chaîne de caractères correspondant à l'opérande. */ +static size_t _g_imm_operand_to_string(const GImmOperand *, AsmSyntax, ImmOperandDisplay, char [IMM_MAX_SIZE]); + /* Traduit un opérande en version humainement lisible. */ static void g_imm_operand_print(const GImmOperand *, GBufferLine *, AsmSyntax); +/* Construit un petit résumé concis de l'opérande. */ +static char *g_imm_operand_build_tooltip(const GImmOperand *, const GLoadedBinary *); + /* Indique le type défini pour un opérande de valeur numérique. */ @@ -113,6 +123,7 @@ static void g_imm_operand_class_init(GImmOperandClass *klass) object->finalize = (GObjectFinalizeFunc)g_imm_operand_finalize; operand->print = (operand_print_fc)g_imm_operand_print; + operand->build_tooltip = (operand_build_tooltip_fc)g_imm_operand_build_tooltip; g_signal_new("value-changed", G_TYPE_IMM_OPERAND, @@ -662,6 +673,7 @@ bool g_imm_operand_is_null(const GImmOperand *operand) * * * Paramètres : operand = opérande à transcrire. * * syntax = type de représentation demandée. * +* display = type d'affichage demandé. * * value = valeur portée par l'opérande transcrite. [OUT] * * * * Description : Construit la chaîne de caractères correspondant à l'opérande.* @@ -672,7 +684,7 @@ bool g_imm_operand_is_null(const GImmOperand *operand) * * ******************************************************************************/ -size_t g_imm_operand_to_string(const GImmOperand *operand, AsmSyntax syntax, char value[IMM_MAX_SIZE]) +static size_t _g_imm_operand_to_string(const GImmOperand *operand, AsmSyntax syntax, ImmOperandDisplay display, char value[IMM_MAX_SIZE]) { size_t result; /* Longueur à retourner */ unsigned int range; /* Catégorie de la taille */ @@ -685,7 +697,7 @@ size_t g_imm_operand_to_string(const GImmOperand *operand, AsmSyntax syntax, cha const char *conv; /* Opérateur de conversion */ char binval[65]; /* Conversion intégrée */ unsigned int max; /* Indice du plus fort bit */ - unsigned int i; /* Boucle de parcours #1 */ + unsigned int i; /* Boucle de parcours */ char format[16 + 65]; /* Format d'impression final */ static const char *zpad_defs[] = { "", "02", "04", "08", "016" }; @@ -698,7 +710,7 @@ size_t g_imm_operand_to_string(const GImmOperand *operand, AsmSyntax syntax, cha range = MDS_RANGE(operand->size); /* Encadrement pour les caractères */ - if (operand->display == IOD_CHAR) + if (display == IOD_CHAR) { prefix = (syntax == ASX_ATT ? "$'" : "'"); suffix = "'"; @@ -710,7 +722,7 @@ size_t g_imm_operand_to_string(const GImmOperand *operand, AsmSyntax syntax, cha } /* Préfix de forme '0x', 'b' ou '0' */ - switch (operand->display) + switch (display) { case IOD_BIN: alternate = "b"; @@ -727,13 +739,13 @@ size_t g_imm_operand_to_string(const GImmOperand *operand, AsmSyntax syntax, cha } /* Va-t-on réellement avoir besoin d'un formatage ? */ - if (operand->display != IOD_BIN) + if (display != IOD_BIN) intro = "%"; else intro = ""; /* Drapeau de remplissage ? */ - switch (operand->display) + switch (display) { case IOD_BIN: case IOD_CHAR: @@ -751,12 +763,12 @@ size_t g_imm_operand_to_string(const GImmOperand *operand, AsmSyntax syntax, cha /* Spécification de la conversion */ - if (operand->display != IOD_BIN) + if (display != IOD_BIN) { if (MDS_IS_SIGNED(operand->size)) - conv = conv_si_defs[operand->display]; + conv = conv_si_defs[display]; else - conv = conv_us_defs[operand->display]; + conv = conv_us_defs[display]; } else @@ -779,7 +791,7 @@ size_t g_imm_operand_to_string(const GImmOperand *operand, AsmSyntax syntax, cha conv = binval; for (i = max; i > 0; i--) - binval[max - i] = (operand->raw & (1 << (i - 1)) ? '1' : '0'); + binval[max - i] = (operand->raw & (1llu << (i - 1)) ? '1' : '0'); binval[max] = '\0'; @@ -852,6 +864,31 @@ size_t g_imm_operand_to_string(const GImmOperand *operand, AsmSyntax syntax, cha /****************************************************************************** * * +* Paramètres : operand = opérande à transcrire. * +* syntax = type de représentation demandée. * +* value = valeur portée par l'opérande transcrite. [OUT] * +* * +* Description : Construit la chaîne de caractères correspondant à l'opérande.* +* * +* Retour : Nombre de caractères utilisés. * +* * +* Remarques : - * +* * +******************************************************************************/ + +size_t g_imm_operand_to_string(const GImmOperand *operand, AsmSyntax syntax, char value[IMM_MAX_SIZE]) +{ + size_t result; /* Longueur à retourner */ + + result = _g_imm_operand_to_string(operand, syntax, operand->display, value); + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : operand = opérande à traiter. * * line = ligne tampon où imprimer l'opérande donné. * * syntax = type de représentation demandée. * @@ -878,6 +915,79 @@ static void g_imm_operand_print(const GImmOperand *operand, GBufferLine *line, A /****************************************************************************** * * +* Paramètres : operand = opérande à consulter. * +* binary = informations relatives au binaire chargé. * +* * +* Description : Construit un petit résumé concis de l'opérande. * +* * +* Retour : Chaîne de caractères à libérer après usage ou NULL. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static char *g_imm_operand_build_tooltip(const GImmOperand *operand, const GLoadedBinary *binary) +{ + char *result; /* Description à retourner */ + char value[IMM_MAX_SIZE]; /* Conversion artificielle */ + char *conv; /* Affichage de la Conversion */ + + if (isprint(operand->raw)) + asprintf(&result, _("Character: '%c'"), (char)operand->raw); + else + asprintf(&result, _("Character: <not printable>")); + + /* Binaire */ + + _g_imm_operand_to_string(operand, ASX_INTEL, IOD_BIN, value); + + asprintf(&conv, _("Binary: %s"), value); + + result = stradd(result, "\n"); + result = stradd(result, conv); + + free(conv); + + /* Octal */ + + _g_imm_operand_to_string(operand, ASX_INTEL, IOD_OCT, value); + + asprintf(&conv, _("Octal: %s"), value); + + result = stradd(result, "\n"); + result = stradd(result, conv); + + free(conv); + + /* Décimal */ + + _g_imm_operand_to_string(operand, ASX_INTEL, IOD_DEC, value); + + asprintf(&conv, _("Decimal: %s"), value); + + result = stradd(result, "\n"); + result = stradd(result, conv); + + free(conv); + + /* Hexadécimal */ + + _g_imm_operand_to_string(operand, ASX_INTEL, IOD_HEX, value); + + asprintf(&conv, _("Hexadecimal: %s"), value); + + result = stradd(result, "\n"); + result = stradd(result, conv); + + free(conv); + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : operand = opérande à traiter. * * pos = valeur résultante. [OUT] * * * |