/* Chrysalide - Outil d'analyse de fichiers binaires
* immediate-ui.c - opérandes représentant des valeurs numériques sous forme graphique
*
* Copyright (C) 2024 Cyrille Bagard
*
* This file is part of Chrysalide.
*
* Chrysalide is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Chrysalide is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Chrysalide. If not, see .
*/
#include "immediate-ui.h"
#include
#include "immediate-int.h"
#include "../../common/extstr.h"
#include "../../glibext/tokenstyle.h"
#include "../../glibext/options/disass.h"
/* Traduit un opérande en version humainement lisible. */
static void g_immediate_operand_ui_print(const GImmediateOperand *, GBufferLine *);
/* Construit un petit résumé concis de l'opérande. */
static char *g_immediate_operand_ui_build_tooltip(const GImmediateOperand *, const GLoadedBinary *);
/******************************************************************************
* *
* Paramètres : iface = interface GLib à initialiser. *
* *
* Description : Procède à l'initialisation de l'interface d'opérande UI. *
* *
* Retour : - *
* *
* Remarques : - *
* *
******************************************************************************/
void g_immediate_operand_ui_arch_operand_ui_iface_init(GArchOperandUIInterface *iface)
{
iface->print = (print_operand_ui_fc)g_immediate_operand_ui_print;
iface->build_tooltip = (build_operand_ui_tooltip_fc)g_immediate_operand_ui_build_tooltip;
}
/******************************************************************************
* *
* Paramètres : operand = opérande à traiter. *
* line = ligne tampon où imprimer l'opérande donné. *
* *
* Description : Traduit un opérande en version humainement lisible. *
* *
* Retour : - *
* *
* Remarques : - *
* *
******************************************************************************/
static void g_immediate_operand_ui_print(const GImmediateOperand *operand, GBufferLine *line)
{
GImmediateOperand *base; /* Version d'instance basique */
ImmOperandDisplay display; /* Type d'affichage courant */
char value[IMM_MAX_SIZE]; /* Chaîne à imprimer */
size_t len; /* Taille de l'élément inséré */
base = G_IMMEDIATE_OPERAND(operand);
display = g_immediate_operand_get_display(base);
len = _g_immediate_operand_to_string(base, display, value);
g_buffer_line_append_text(line, ACO_ASSEMBLY, TRT_IMMEDIATE, value, len, NULL, G_OBJECT(operand));
}
/******************************************************************************
* *
* 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_immediate_operand_ui_build_tooltip(const GImmediateOperand *operand, const GLoadedBinary *binary)
{
char *result; /* Description à retourner */
GImmediateOperand *base; /* Version d'instance basique */
char value[IMM_MAX_SIZE]; /* Conversion artificielle */
char *conv; /* Affichage de la Conversion */
base = G_IMMEDIATE_OPERAND(operand);
if (base->raw <= UCHAR_MAX && isprint(base->raw))
switch (base->raw)
{
case '&':
asprintf(&result, _("Character: '&'"));
break;
case '<':
asprintf(&result, _("Character: '<'"));
break;
case '>':
asprintf(&result, _("Character: '>'"));
break;
default:
asprintf(&result, _("Character: '%c'"), (char)base->raw);
break;
}
else
asprintf(&result, _("Character: <not printable>"));
/* Binaire */
_g_immediate_operand_to_string(base, IOD_BIN, value);
asprintf(&conv, _("Binary: %s"), value);
result = stradd(result, "\n");
result = stradd(result, conv);
free(conv);
/* Octal */
_g_immediate_operand_to_string(base, IOD_OCT, value);
asprintf(&conv, _("Octal: %s"), value);
result = stradd(result, "\n");
result = stradd(result, conv);
free(conv);
/* Décimal */
_g_immediate_operand_to_string(base, IOD_DEC, value);
asprintf(&conv, _("Decimal: %s"), value);
result = stradd(result, "\n");
result = stradd(result, conv);
free(conv);
/* Hexadécimal */
_g_immediate_operand_to_string(base, IOD_HEX, value);
asprintf(&conv, _("Hexadecimal: %s"), value);
result = stradd(result, "\n");
result = stradd(result, conv);
free(conv);
return result;
}