summaryrefslogtreecommitdiff
path: root/src/arch/operands/immediate.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2025-03-17 07:36:58 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2025-03-17 07:36:58 (GMT)
commita28e1b94a83bee9a2424ab84818a5547eafaf0cf (patch)
treeecaf5556433afd4f19f4bfcbf378cdde3f619e51 /src/arch/operands/immediate.c
parentb18c64b69c8c048c640b5d9f6c45b1cfda605ae8 (diff)
Restore the definition of main operands.gtk4
Diffstat (limited to 'src/arch/operands/immediate.c')
-rw-r--r--src/arch/operands/immediate.c1320
1 files changed, 528 insertions, 792 deletions
diff --git a/src/arch/operands/immediate.c b/src/arch/operands/immediate.c
index f40c645..7ec5ebd 100644
--- a/src/arch/operands/immediate.c
+++ b/src/arch/operands/immediate.c
@@ -2,7 +2,7 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
* immediate.c - opérandes représentant des valeurs numériques
*
- * Copyright (C) 2020 Cyrille Bagard
+ * Copyright (C) 2020-2024 Cyrille Bagard
*
* This file is part of Chrysalide.
*
@@ -25,25 +25,32 @@
#include <assert.h>
+#include <stdarg.h>
+
+
+
+#if 0
+
#include <ctype.h>
#include <inttypes.h>
#include <limits.h>
#include <malloc.h>
-#include <stdarg.h>
#include <stdio.h>
#include <i18n.h>
+#endif
+
+
#include "immediate-int.h"
-#include "known.h"
-#include "rename-int.h"
-#include "targetable-int.h"
#include "../../common/asm.h"
-#include "../../common/extstr.h"
#include "../../common/sort.h"
-#include "../../core/columns.h"
+#include "../../glibext/comparable-int.h"
+#include "../../glibext/hashable-int.h"
+#include "../../glibext/serialize-int.h"
+#include "../../glibext/strbuilder-int.h"
@@ -51,68 +58,75 @@
/* Initialise la classe des opérandes de valeur immédiate. */
-static void g_imm_operand_class_init(GImmOperandClass *);
+static void g_immediate_operand_class_init(GImmediateOperandClass *);
-/* Initialise un opérande de valeur immédiate. */
-static void g_imm_operand_init(GImmOperand *);
+/* Procède à l'initialisation de l'interface de comparaison. */
+static void g_immediate_operand_comparable_object_iface_init(GComparableObjectInterface *);
+
+/* Procède à l'initialisation de l'interface de détermination. */
+static void g_immediate_operand_hashable_object_iface_init(GHashableObjectInterface *);
+
+/* Procède à l'initialisation de l'interface de sérialisation. */
+static void g_immediate_operand_serializable_iface_init(GSerializableObjectInterface *);
+
+/* Procède à l'initialisation de l'interface d'exportation. */
+static void g_immediate_operand_string_builder_iface_init(GStringBuilderInterface *, gpointer);
+
+#if 0
/* Procède à l'initialisation de l'interface de ciblage. */
-static void g_imm_operand_targetable_interface_init(GTargetableOperandInterface *);
+static void g_immediate_operand_targetable_interface_init(GTargetableOperandInterface *);
/* Procède à l'initialisation de l'interface de renommage. */
-static void g_imm_operand_renameable_interface_init(GRenameableOperandInterface *);
+static void g_immediate_operand_renameable_interface_init(GRenameableOperandInterface *);
+
+#endif
+
+/* Initialise un opérande de valeur immédiate. */
+static void g_immediate_operand_init(GImmediateOperand *);
/* Supprime toutes les références externes. */
-static void g_imm_operand_dispose(GImmOperand *);
+static void g_immediate_operand_dispose(GObject *);
/* Procède à la libération totale de la mémoire. */
-static void g_imm_operand_finalize(GImmOperand *);
+static void g_immediate_operand_finalize(GObject *);
-/* Construit la chaîne de caractères correspondant à l'opérande. */
-static size_t _g_imm_operand_to_string(const GImmOperand *, ImmOperandDisplay, char [IMM_MAX_SIZE]);
-/* Traduit un opérande en version humainement lisible. */
-static void g_imm_operand_print(const GImmOperand *, GBufferLine *);
+/* ---------------------- COMPARAISON DETAILLEE DE DEUX OBJETS ---------------------- */
-/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+/* Réalise une comparaison étendue entre objets. */
+static int g_immediate_operand_compare(const GComparableObject *, const GComparableObject *);
-/* Compare un opérande avec un autre. */
-static int g_imm_operand_compare(const GImmOperand *, const GImmOperand *, bool);
-#ifdef INCLUDE_GTK_SUPPORT
+/* ---------------------- CALCUL D'UNE EMPREINTE DE L'INSTANCE ---------------------- */
-/* Construit un petit résumé concis de l'opérande. */
-static char *g_imm_operand_build_tooltip(const GImmOperand *, const GLoadedBinary *);
-#endif
+/* Calcule l'empreinte sur 32 bits d'un objet. */
+static guint g_immediate_operand_hash(const GHashableObject *);
-/* Fournit l'empreinte d'un candidat à une centralisation. */
-static guint g_imm_operand_hash(const GImmOperand *, bool);
-/* Charge un contenu depuis une mémoire tampon. */
-static bool g_imm_operand_load(GImmOperand *, GObjectStorage *, packed_buffer_t *);
-/* Sauvegarde un contenu dans une mémoire tampon. */
-static bool g_imm_operand_store(GImmOperand *, GObjectStorage *, packed_buffer_t *);
+/* ------------------- MECANISMES DE CONSERVATION ET RESTAURATION ------------------- */
+/* Charge un objet depuis un flux de données. */
+static bool g_immediate_operand_load(GSerializableObject *, GObjectStorage *, int);
-/* ---------------------- COMMUNICATION D'UN CIBLAGE POTENTIEL ---------------------- */
+/* Sauvegarde un objet dans un flux de données. */
+static bool g_immediate_operand_store(const GSerializableObject *, GObjectStorage *, int);
-/* Obtient l'adresse de la cible visée par un opérande. */
-static bool g_imm_operand_get_addr(const GImmOperand *, const vmpa2t *, GBinFormat *, GArchProcessor *, vmpa2t *);
+/* ----------------- EXPORTATION SOUS FORME DE CHAINE DE CARACTERES ----------------- */
-/* ---------------------- CONSTRUCTION D'UN CONTENU ALTERNATIF ---------------------- */
+/* Exporte une chaîne de caractères à partir d'un objet. */
+static bool g_immediate_operand_to_string(const GStringBuilder *, unsigned int, sized_binary_t *);
-/* Construit un opérande de représentation alternative. */
-static GRenamedOperand *g_imm_operand_build(const GImmOperand *, const char *);
@@ -122,9 +136,12 @@ static GRenamedOperand *g_imm_operand_build(const GImmOperand *, const char *);
/* Indique le type défini pour un opérande de valeur numérique. */
-G_DEFINE_TYPE_WITH_CODE(GImmOperand, g_imm_operand, G_TYPE_ARCH_OPERAND,
- G_IMPLEMENT_INTERFACE(G_TYPE_TARGETABLE_OPERAND, g_imm_operand_targetable_interface_init)
- G_IMPLEMENT_INTERFACE(G_TYPE_RENAMEABLE_OPERAND, g_imm_operand_renameable_interface_init));
+G_DEFINE_TYPE_WITH_CODE(GImmediateOperand, g_immediate_operand, G_TYPE_ARCH_OPERAND,
+ G_IMPLEMENT_INTERFACE(G_TYPE_COMPARABLE_OBJECT, g_immediate_operand_comparable_object_iface_init)
+ G_IMPLEMENT_INTERFACE(G_TYPE_HASHABLE_OBJECT, g_immediate_operand_hashable_object_iface_init)
+ G_IMPLEMENT_INTERFACE(G_TYPE_SERIALIZABLE_OBJECT, g_immediate_operand_serializable_iface_init)
+ G_IMPLEMENT_INTERFACE(G_TYPE_STRING_BUILDER, g_immediate_operand_string_builder_iface_init)
+ G_IMPLEMENT_INTERFACE_IF_SYM(g_arch_operand_ui_get_type, g_immediate_operand_ui_arch_operand_ui_iface_init));
/******************************************************************************
@@ -139,36 +156,42 @@ G_DEFINE_TYPE_WITH_CODE(GImmOperand, g_imm_operand, G_TYPE_ARCH_OPERAND,
* *
******************************************************************************/
-static void g_imm_operand_class_init(GImmOperandClass *klass)
+static void g_immediate_operand_class_init(GImmediateOperandClass *klass)
{
GObjectClass *object; /* Autre version de la classe */
- GArchOperandClass *operand; /* Version de classe parente */
object = G_OBJECT_CLASS(klass);
- operand = G_ARCH_OPERAND_CLASS(klass);
- object->dispose = (GObjectFinalizeFunc/* ! */)g_imm_operand_dispose;
- object->finalize = (GObjectFinalizeFunc)g_imm_operand_finalize;
+ object->dispose = g_immediate_operand_dispose;
+ object->finalize = g_immediate_operand_finalize;
- operand->compare = (operand_compare_fc)g_imm_operand_compare;
- operand->print = (operand_print_fc)g_imm_operand_print;
-#ifdef INCLUDE_GTK_SUPPORT
- operand->build_tooltip = (operand_build_tooltip_fc)g_imm_operand_build_tooltip;
-#endif
+}
- operand->hash = (operand_hash_fc)g_imm_operand_hash;
- operand->load = (load_operand_fc)g_imm_operand_load;
- operand->store = (store_operand_fc)g_imm_operand_store;
+/******************************************************************************
+* *
+* Paramètres : iface = interface GLib à initialiser. *
+* *
+* Description : Procède à l'initialisation de l'interface de comparaison. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_immediate_operand_comparable_object_iface_init(GComparableObjectInterface *iface)
+{
+ iface->compare = g_immediate_operand_compare;
}
/******************************************************************************
* *
-* Paramètres : operand = instance à initialiser. *
+* Paramètres : iface = interface GLib à initialiser. *
* *
-* Description : Initialise un opérande de valeur immédiate. *
+* Description : Procède à l'initialisation de l'interface de détermination. *
* *
* Retour : - *
* *
@@ -176,23 +199,39 @@ static void g_imm_operand_class_init(GImmOperandClass *klass)
* *
******************************************************************************/
-static void g_imm_operand_init(GImmOperand *operand)
+static void g_immediate_operand_hashable_object_iface_init(GHashableObjectInterface *iface)
{
- GET_IMM_OP_EXTRA(operand)->size = MDS_UNDEFINED;
+ iface->hash = g_immediate_operand_hash;
- GET_IMM_OP_EXTRA(operand)->def_display = IOD_HEX;
- GET_IMM_OP_EXTRA(operand)->display = IOD_COUNT;
+}
- operand->raw = 0;
+
+/******************************************************************************
+* *
+* Paramètres : iface = interface GLib à initialiser. *
+* *
+* Description : Procède à l'initialisation de l'interface de sérialisation. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_immediate_operand_serializable_iface_init(GSerializableObjectInterface *iface)
+{
+ iface->load = g_immediate_operand_load;
+ iface->store = g_immediate_operand_store;
}
/******************************************************************************
* *
-* Paramètres : iface = interface GLib à initialiser. *
+* Paramètres : iface = interface GLib à initialiser. *
+* unused = pointeur non utilisé ici. *
* *
-* Description : Procède à l'initialisation de l'interface de ciblage. *
+* Description : Procède à l'initialisation de l'interface d'exportation. *
* *
* Retour : - *
* *
@@ -200,18 +239,18 @@ static void g_imm_operand_init(GImmOperand *operand)
* *
******************************************************************************/
-static void g_imm_operand_targetable_interface_init(GTargetableOperandInterface *iface)
+static void g_immediate_operand_string_builder_iface_init(GStringBuilderInterface *iface, gpointer unused)
{
- iface->get_addr = (get_targetable_addr_fc)g_imm_operand_get_addr;
+ iface->to_string = g_immediate_operand_to_string;
}
/******************************************************************************
* *
-* Paramètres : iface = interface GLib à initialiser. *
+* Paramètres : operand = instance à initialiser. *
* *
-* Description : Procède à l'initialisation de l'interface de renommage. *
+* Description : Initialise un opérande de valeur immédiate. *
* *
* Retour : - *
* *
@@ -219,16 +258,27 @@ static void g_imm_operand_targetable_interface_init(GTargetableOperandInterface
* *
******************************************************************************/
-static void g_imm_operand_renameable_interface_init(GRenameableOperandInterface *iface)
+static void g_immediate_operand_init(GImmediateOperand *operand)
{
- iface->build = (build_renameable_fc)g_imm_operand_build;
+ immop_extra_data_t extra; /* Données insérées à consulter*/
+
+ extra = GET_IMM_OP_EXTRA(operand);
+
+ extra.size = MDS_UNDEFINED;
+
+ extra.def_display = IOD_HEX;
+ extra.display = IOD_COUNT;
+
+ SET_IMM_OP_EXTRA(operand, &extra);
+
+ operand->raw = 0;
}
/******************************************************************************
* *
-* Paramètres : operand = instance d'objet GLib à traiter. *
+* Paramètres : object = instance d'objet GLib à traiter. *
* *
* Description : Supprime toutes les références externes. *
* *
@@ -238,16 +288,16 @@ static void g_imm_operand_renameable_interface_init(GRenameableOperandInterface
* *
******************************************************************************/
-static void g_imm_operand_dispose(GImmOperand *operand)
+static void g_immediate_operand_dispose(GObject *object)
{
- G_OBJECT_CLASS(g_imm_operand_parent_class)->dispose(G_OBJECT(operand));
+ G_OBJECT_CLASS(g_immediate_operand_parent_class)->dispose(object);
}
/******************************************************************************
* *
-* Paramètres : operand = instance d'objet GLib à traiter. *
+* Paramètres : object = instance d'objet GLib à traiter. *
* *
* Description : Procède à la libération totale de la mémoire. *
* *
@@ -257,9 +307,74 @@ static void g_imm_operand_dispose(GImmOperand *operand)
* *
******************************************************************************/
-static void g_imm_operand_finalize(GImmOperand *operand)
+static void g_immediate_operand_finalize(GObject *object)
+{
+ G_OBJECT_CLASS(g_immediate_operand_parent_class)->finalize(object);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : size = taille de l'opérande souhaitée. *
+* value = valeur sur x bits à venir récupérer. *
+* *
+* Description : Crée un opérande réprésentant une valeur numérique. *
+* *
+* Retour : Instruction mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchOperand *g_immediate_operand_new_from_value(MemoryDataSize size, uint64_t value)
{
- G_OBJECT_CLASS(g_imm_operand_parent_class)->finalize(G_OBJECT(operand));
+ GImmediateOperand *result; /* Opérande à retourner */
+
+ result = g_object_new(G_TYPE_IMMEDIATE_OPERAND, NULL);
+
+ if (!g_immediate_operand_create_from_value(result, size, value))
+ g_clear_object(&result);
+
+ return G_ARCH_OPERAND(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = instance à initialiser pleinement. *
+* size = taille de l'opérande souhaitée. *
+* value = valeur sur x bits à venir récupérer. *
+* *
+* Description : Met en place un opérande réprésentant une valeur numérique. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_immediate_operand_create_from_value(GImmediateOperand *operand, MemoryDataSize size, uint64_t value)
+{
+ bool result; /* Bilan à retourner */
+ immop_extra_data_t extra; /* Données insérées à consulter*/
+
+ result = (size != MDS_UNDEFINED);
+
+ if (result)
+ {
+ extra = GET_IMM_OP_EXTRA(operand);
+
+ extra.size = size;
+
+ operand->raw = value;
+
+ SET_IMM_OP_EXTRA(operand, &extra);
+
+ }
+
+ return result;
}
@@ -280,10 +395,41 @@ static void g_imm_operand_finalize(GImmOperand *operand)
* *
******************************************************************************/
-GArchOperand *_g_imm_operand_new_from_data(MemoryDataSize size, const GBinContent *content, vmpa2t *addr, bool *low, SourceEndian endian)
+GArchOperand *g_immediate_operand_new_from_data(MemoryDataSize size, const GBinContent *content, vmpa2t *addr, bool *low, SourceEndian endian)
{
- GImmOperand *result; /* Opérande à retourner */
- immop_extra_data_t *extra; /* Données insérées à modifier */
+ GImmediateOperand *result; /* Opérande à retourner */
+
+ result = g_object_new(G_TYPE_IMMEDIATE_OPERAND, NULL);
+
+ if (!g_immediate_operand_create_from_data(result, size, content, addr, low, endian))
+ g_clear_object(&result);
+
+ return G_ARCH_OPERAND(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = instance à initialiser pleinement. *
+* size = taille de l'opérande souhaitée. *
+* content = flux de données à analyser. *
+* addr = position courante dans ce flux. [OUT] *
+* low = position éventuelle des 4 bits visés. [OUT] *
+* endian = ordre des bits dans la source. *
+* *
+* Description : Crée un opérande réprésentant une valeur numérique. *
+* *
+* Retour : Instruction mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_immediate_operand_create_from_data(GImmediateOperand *operand, MemoryDataSize size, const GBinContent *content, vmpa2t *addr, bool *low, SourceEndian endian)
+{
+ bool result; /* Bilan à retourner */
+ uint64_t raw; /* Valeur brute lue */
uint8_t uval8; /* Valeur sur 8 bits */
uint16_t uval16; /* Valeur sur 16 bits */
uint32_t uval32; /* Valeur sur 32 bits */
@@ -293,125 +439,78 @@ GArchOperand *_g_imm_operand_new_from_data(MemoryDataSize size, const GBinConten
int32_t sval32; /* Valeur sur 32 bits */
int64_t sval64; /* Valeur sur 64 bits */
- result = g_object_new(G_TYPE_IMM_OPERAND, NULL);
-
- extra = GET_IMM_OP_EXTRA(result);
-
- extra->size = size;
-
switch (size)
{
case MDS_4_BITS_UNSIGNED:
- if (!g_binary_content_read_u4(content, addr, low, &uval8))
- goto gionfd_error;
- result->raw = uval8;
+ result = g_binary_content_read_u4(content, addr, low, &uval8);
+ if (result)
+ raw = uval8;
break;
case MDS_8_BITS_UNSIGNED:
- if (!g_binary_content_read_u8(content, addr, &uval8))
- goto gionfd_error;
- result->raw = uval8;
+ result = g_binary_content_read_u8(content, addr, &uval8);
+ if (result)
+ raw = uval8;
break;
case MDS_16_BITS_UNSIGNED:
- if (!g_binary_content_read_u16(content, addr, endian, &uval16))
- goto gionfd_error;
- result->raw = uval16;
+ result = g_binary_content_read_u16(content, addr, endian, &uval16);
+ if (result)
+ raw = uval16;
break;
case MDS_32_BITS_UNSIGNED:
- if (!g_binary_content_read_u32(content, addr, endian, &uval32))
- goto gionfd_error;
- result->raw = uval32;
+ result = g_binary_content_read_u32(content, addr, endian, &uval32);
+ if (result)
+ raw = uval32;
break;
case MDS_64_BITS_UNSIGNED:
- if (!g_binary_content_read_u64(content, addr, endian, &uval64))
- goto gionfd_error;
- result->raw = uval64;
+ result = g_binary_content_read_u64(content, addr, endian, &uval64);
+ if (result)
+ raw = uval64;
break;
case MDS_4_BITS_SIGNED:
- if (!g_binary_content_read_s4(content, addr, low, &sval8))
- goto gionfd_error;
- result->raw = sval8;
+ result = g_binary_content_read_s4(content, addr, low, &sval8);
+ if (result)
+ raw = sval8;
break;
case MDS_8_BITS_SIGNED:
- if (!g_binary_content_read_s8(content, addr, &sval8))
- goto gionfd_error;
- result->raw = sval8;
+ result = g_binary_content_read_s8(content, addr, &sval8);
+ if (result)
+ raw = sval8;
break;
case MDS_16_BITS_SIGNED:
- if (!g_binary_content_read_s16(content, addr, endian, &sval16))
- goto gionfd_error;
- result->raw = sval16;
+ result = g_binary_content_read_s16(content, addr, endian, &sval16);
+ if (result)
+ raw = sval16;
break;
case MDS_32_BITS_SIGNED:
- if (!g_binary_content_read_s32(content, addr, endian, &sval32))
- goto gionfd_error;
- result->raw = sval32;
+ result = g_binary_content_read_s32(content, addr, endian, &sval32);
+ if (result)
+ raw = sval32;
break;
case MDS_64_BITS_SIGNED:
- if (!g_binary_content_read_s64(content, addr, endian, &sval64))
- goto gionfd_error;
- result->raw = sval64;
+ result = g_binary_content_read_s64(content, addr, endian, &sval64);
+ if (result)
+ raw = sval64;
break;
case MDS_UNDEFINED:
- goto gionfd_error;
+ result = false;
break;
}
- return G_ARCH_OPERAND(result);
-
- gionfd_error:
-
- g_object_unref(G_OBJECT(result));
-
- return NULL;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : size = taille de l'opérande souhaitée. *
-* value = valeur sur x bits à venir récupérer. *
-* *
-* Description : Crée un opérande réprésentant une valeur numérique. *
-* *
-* Retour : Instruction mise en place. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-GArchOperand *g_imm_operand_new_from_value(MemoryDataSize size, uint64_t value)
-{
- GImmOperand *result; /* Opérande à retourner */
- immop_extra_data_t *extra; /* Données insérées à modifier */
-
- if (size == MDS_UNDEFINED)
- result = NULL;
-
- else
- {
- result = g_object_new(G_TYPE_IMM_OPERAND, NULL);
-
- extra = GET_IMM_OP_EXTRA(result);
-
- extra->size = size;
-
- result->raw = value;
-
- }
+ if (result)
+ result = g_immediate_operand_create_from_value(operand, size, raw);
- return (result != NULL ? G_ARCH_OPERAND(result) : NULL);
+ return result;
}
@@ -428,18 +527,14 @@ GArchOperand *g_imm_operand_new_from_value(MemoryDataSize size, uint64_t value)
* *
******************************************************************************/
-MemoryDataSize g_imm_operand_get_size(const GImmOperand *operand)
+MemoryDataSize g_immediate_operand_get_size(const GImmediateOperand *operand)
{
MemoryDataSize result; /* Taille à retourner */
- immop_extra_data_t *extra; /* Données insérées à consulter*/
+ immop_extra_data_t extra; /* Données insérées à consulter*/
extra = GET_IMM_OP_EXTRA(operand);
- LOCK_GOBJECT_EXTRA(extra);
-
- result = extra->size;
-
- UNLOCK_GOBJECT_EXTRA(extra);
+ result = extra.size;
return result;
@@ -460,10 +555,10 @@ MemoryDataSize g_imm_operand_get_size(const GImmOperand *operand)
* *
******************************************************************************/
-bool g_imm_operand_get_value(const GImmOperand *operand, MemoryDataSize size, ...)
+bool g_immediate_operand_get_value(const GImmediateOperand *operand, MemoryDataSize size, ...)
{
bool result; /* Bilan à retourner */
- immop_extra_data_t *extra; /* Données insérées à consulter*/
+ immop_extra_data_t extra; /* Données insérées à consulter*/
va_list ap; /* Liste des compléments */
uint8_t *uval8; /* Valeur sur 8 bits */
uint16_t *uval16; /* Valeur sur 16 bits */
@@ -478,9 +573,7 @@ bool g_imm_operand_get_value(const GImmOperand *operand, MemoryDataSize size, ..
extra = GET_IMM_OP_EXTRA(operand);
- LOCK_GOBJECT_EXTRA(extra);
-
- if (extra->size != size)
+ if (extra.size != size)
goto exit;
va_start(ap, size);
@@ -533,8 +626,6 @@ bool g_imm_operand_get_value(const GImmOperand *operand, MemoryDataSize size, ..
exit:
- UNLOCK_GOBJECT_EXTRA(extra);
-
return result;
}
@@ -542,6 +633,37 @@ bool g_imm_operand_get_value(const GImmOperand *operand, MemoryDataSize size, ..
/******************************************************************************
* *
+* Paramètres : operand = structure dont le contenu est à actualiser. [OUT] *
+* size = taille de l'opérande souhaitée. *
+* value = valeur sur x bits à venir récupérer. *
+* *
+* Description : Définit la nouvelle valeur de l'opérande à une valeur. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_immediate_operand_set_value(GImmediateOperand *operand, MemoryDataSize size, uint64_t value)
+{
+ immop_extra_data_t extra; /* Données insérées à consulter*/
+
+ assert(size != MDS_UNDEFINED);
+
+ extra = GET_IMM_OP_EXTRA(operand);
+
+ extra.size = size;
+
+ operand->raw = value;
+
+ SET_IMM_OP_EXTRA(operand, &extra);
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : operand = opérande à consulter. *
* *
* Description : Fournit la valeur brute représentée par l'opérande. *
@@ -552,42 +674,55 @@ bool g_imm_operand_get_value(const GImmOperand *operand, MemoryDataSize size, ..
* *
******************************************************************************/
-uint64_t g_imm_operand_get_raw_value(const GImmOperand *operand)
+uint64_t g_immediate_operand_get_raw_value(const GImmediateOperand *operand)
{
- return operand->raw;
+ uint64_t result; /* Valeur brute à retourner */
+
+ result = operand->raw;
+
+ return result;
}
/******************************************************************************
* *
-* Paramètres : operand = structure dont le contenu est à actualiser. [OUT] *
-* size = taille de l'opérande souhaitée. *
-* value = valeur sur x bits à venir récupérer. *
+* Paramètres : operand = structure dont le contenu est à consulter. *
* *
-* Description : Définit la nouvelle valeur de l'opérande à une valeur. *
+* Description : Indique le signe d'une valeur immédiate. *
* *
-* Retour : - *
+* Retour : true si la valeur est strictement négative, false sinon. *
* *
* Remarques : - *
* *
******************************************************************************/
-void g_imm_operand_set_value(GImmOperand *operand, MemoryDataSize size, uint64_t value)
+bool g_immediate_operand_is_negative(const GImmediateOperand *operand)
{
- immop_extra_data_t *extra; /* Données insérées à consulter*/
-
- assert(size != MDS_UNDEFINED);
+ bool result; /* Bilan à renvoyer */
+ immop_extra_data_t extra; /* Données insérées à consulter*/
extra = GET_IMM_OP_EXTRA(operand);
- LOCK_GOBJECT_EXTRA(extra);
-
- extra->size = size;
-
- operand->raw = value;
+ switch (extra.size)
+ {
+ case MDS_4_BITS_SIGNED:
+ case MDS_8_BITS_SIGNED:
+ case MDS_16_BITS_SIGNED:
+ case MDS_32_BITS_SIGNED:
+ case MDS_64_BITS_SIGNED:
+ /**
+ * Pour les valeurs plus petites que 64 bits, le compilateur
+ * réalise une extension de signe lors du transtypage.
+ */
+ result = (operand->raw & 0x8000000000000000ll);
+ break;
+ default:
+ result = false;
+ break;
+ }
- UNLOCK_GOBJECT_EXTRA(extra);
+ return result;
}
@@ -605,17 +740,15 @@ void g_imm_operand_set_value(GImmOperand *operand, MemoryDataSize size, uint64_t
* *
******************************************************************************/
-void g_imm_operand_set_default_display(GImmOperand *operand, ImmOperandDisplay display)
+void g_immediate_operand_set_default_display(GImmediateOperand *operand, ImmOperandDisplay display)
{
- immop_extra_data_t *extra; /* Données insérées à consulter*/
+ immop_extra_data_t extra; /* Données insérées à consulter*/
extra = GET_IMM_OP_EXTRA(operand);
- LOCK_GOBJECT_EXTRA(extra);
+ extra.def_display = display;
- extra->def_display = display;
-
- UNLOCK_GOBJECT_EXTRA(extra);
+ SET_IMM_OP_EXTRA(operand, &extra);
}
@@ -632,18 +765,14 @@ void g_imm_operand_set_default_display(GImmOperand *operand, ImmOperandDisplay d
* *
******************************************************************************/
-ImmOperandDisplay g_imm_operand_get_default_display(const GImmOperand *operand)
+ImmOperandDisplay g_immediate_operand_get_default_display(const GImmediateOperand *operand)
{
ImmOperandDisplay result; /* Affichage à retourner */
- immop_extra_data_t *extra; /* Données insérées à consulter*/
+ immop_extra_data_t extra; /* Données insérées à consulter*/
extra = GET_IMM_OP_EXTRA(operand);
- LOCK_GOBJECT_EXTRA(extra);
-
- result = extra->def_display;
-
- UNLOCK_GOBJECT_EXTRA(extra);
+ result = extra.def_display;
return result;
@@ -663,17 +792,15 @@ ImmOperandDisplay g_imm_operand_get_default_display(const GImmOperand *operand)
* *
******************************************************************************/
-void g_imm_operand_set_display(GImmOperand *operand, ImmOperandDisplay display)
+void g_immediate_operand_set_display(GImmediateOperand *operand, ImmOperandDisplay display)
{
- immop_extra_data_t *extra; /* Données insérées à consulter*/
+ immop_extra_data_t extra; /* Données insérées à consulter*/
extra = GET_IMM_OP_EXTRA(operand);
- LOCK_GOBJECT_EXTRA(extra);
+ extra.display = display;
- extra->display = display;
-
- UNLOCK_GOBJECT_EXTRA(extra);
+ SET_IMM_OP_EXTRA(operand, &extra);
}
@@ -690,94 +817,225 @@ void g_imm_operand_set_display(GImmOperand *operand, ImmOperandDisplay display)
* *
******************************************************************************/
-ImmOperandDisplay g_imm_operand_get_display(const GImmOperand *operand)
+ImmOperandDisplay g_immediate_operand_get_display(const GImmediateOperand *operand)
{
ImmOperandDisplay result; /* Affichage à retourner */
- immop_extra_data_t *extra; /* Données insérées à consulter*/
+ immop_extra_data_t extra; /* Données insérées à consulter*/
extra = GET_IMM_OP_EXTRA(operand);
- LOCK_GOBJECT_EXTRA(extra);
-
- if (extra->display != IOD_COUNT)
- result = extra->display;
+ if (extra.display != IOD_COUNT)
+ result = extra.display;
else
- result = extra->def_display;
-
- UNLOCK_GOBJECT_EXTRA(extra);
+ result = extra.def_display;
return result;
}
+
+/* ---------------------------------------------------------------------------------- */
+/* COMPARAISON DETAILLEE DE DEUX OBJETS */
+/* ---------------------------------------------------------------------------------- */
+
+
/******************************************************************************
* *
-* Paramètres : operand = structure dont le contenu est à consulter. *
+* Paramètres : object = premier objet à consulter pour une comparaison. *
+* other = second objet à consulter pour une comparaison. *
* *
-* Description : Indique le signe d'une valeur immédiate. *
+* Description : Réalise une comparaison étendue entre objets. *
* *
-* Retour : true si la valeur est strictement négative, false sinon. *
+* Retour : Bilan de la comparaison. *
* *
* Remarques : - *
* *
******************************************************************************/
-bool g_imm_operand_is_negative(const GImmOperand *operand)
+static int g_immediate_operand_compare(const GComparableObject *object, const GComparableObject *other)
{
- bool result; /* Bilan à renvoyer */
- immop_extra_data_t *extra; /* Données insérées à consulter*/
+ int result; /* Bilan à retourner */
+ GComparableObjectInterface *iface; /* Interface utilisée */
+ GComparableObjectInterface *parent_iface; /* Interface parente */
+ GImmediateOperand *operand_a; /* Version spécialisée #0 */
+ GImmediateOperand *operand_b; /* Version spécialisée #1 */
+ immop_extra_data_t extra_a; /* Données insérées à consulter*/
+ immop_extra_data_t extra_b; /* Données insérées à consulter*/
- extra = GET_IMM_OP_EXTRA(operand);
+ iface = G_COMPARABLE_OBJECT_GET_IFACE(object);
+
+ parent_iface = g_type_interface_peek_parent(iface);
- LOCK_GOBJECT_EXTRA(extra);
+ result = parent_iface->compare(object, other);
- switch (extra->size)
+ if (result == 0)
{
- case MDS_4_BITS_SIGNED:
- case MDS_8_BITS_SIGNED:
- case MDS_16_BITS_SIGNED:
- case MDS_32_BITS_SIGNED:
- case MDS_64_BITS_SIGNED:
- /**
- * Pour les valeurs plus petites que 64 bits, le compilateur
- * réalise une extension de signe lors du transtypage.
- */
- result = (operand->raw & 0x8000000000000000ll);
- break;
- default:
- result = false;
- break;
+ operand_a = G_IMMEDIATE_OPERAND(object);
+
+ extra_a = GET_IMM_OP_EXTRA(operand_a);
+
+ operand_b = G_IMMEDIATE_OPERAND(other);
+
+ extra_b = GET_IMM_OP_EXTRA(operand_b);
+
+ result = sort_unsigned_long(extra_a.size, extra_b.size);
+
+ if (result == 0)
+ sort_uint64_t(operand_a->raw, operand_b->raw);
+
+ if (result == 0)
+ result = sort_unsigned_long(extra_a.def_display, extra_b.def_display);
+
+ if (result == 0)
+ result = sort_unsigned_long(extra_a.display, extra_b.display);
+
}
- UNLOCK_GOBJECT_EXTRA(extra);
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* CALCUL D'UNE EMPREINTE DE L'INSTANCE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : object = objet dont l'instance est à consulter. *
+* *
+* Description : Calcule l'empreinte sur 32 bits d'un objet. *
+* *
+* Retour : Valeur de représentation, unique pour l'objet ou non. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static guint g_immediate_operand_hash(const GHashableObject *object)
+{
+ guint result; /* Valeur à retourner */
+ GHashableObjectInterface *iface; /* Interface utilisée */
+ GHashableObjectInterface *parent_iface; /* Interface parente */
+ GImmediateOperand *operand; /* Version spécialisée */
+
+ iface = G_HASHABLE_OBJECT_GET_IFACE(object);
+
+ parent_iface = g_type_interface_peek_parent(iface);
+
+ result = parent_iface->hash(object);
+
+ operand = G_IMMEDIATE_OPERAND(object);
+
+ result ^= (operand->raw & 0xffffffff);
+ result ^= (operand->raw >> 32);
return result;
}
+
+/* ---------------------------------------------------------------------------------- */
+/* MECANISMES DE CONSERVATION ET RESTAURATION */
+/* ---------------------------------------------------------------------------------- */
+
+
/******************************************************************************
* *
-* Paramètres : operand = structure dont le contenu est à consulter. *
+* Paramètres : object = élément GLib à constuire. *
+* storage = conservateur de données à manipuler. *
+* fd = flux ouvert en lecture. *
* *
-* Description : Indique si une valeur immédiate est nulle ou non. *
+* Description : Charge un objet depuis un flux de données. *
* *
-* Retour : true si la valeur est nulle, false sinon. *
+* Retour : Bilan de l'opération. *
* *
* Remarques : - *
* *
******************************************************************************/
-bool g_imm_operand_is_null(const GImmOperand *operand)
+static bool g_immediate_operand_load(GSerializableObject *object, GObjectStorage *storage, int fd)
{
- return (operand->raw == 0ll);
+ bool result; /* Bilan à retourner */
+ GSerializableObjectInterface *iface; /* Interface utilisée */
+ GSerializableObjectInterface *parent_iface; /* Interface parente */
+ uleb128_t val; /* Valeur sauvegardée */
+ GImmediateOperand *operand; /* Version spécialisée */
+
+ iface = G_SERIALIZABLE_OBJECT_GET_IFACE(object);
+
+ parent_iface = g_type_interface_peek_parent(iface);
+
+ result = parent_iface->load(object, storage, fd);
+
+ if (result)
+ {
+ result = load_uleb128(&val, fd);
+
+ if (result)
+ {
+ operand = G_IMMEDIATE_OPERAND(object);
+ operand->raw = val;
+ }
+
+ }
+
+ return result;
}
/******************************************************************************
* *
+* Paramètres : object = élément GLib à consulter. *
+* storage = conservateur de données à manipuler. *
+* fd = flux ouvert en écriture. *
+* *
+* Description : Sauvegarde un objet dans un flux de données. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_immediate_operand_store(const GSerializableObject *object, GObjectStorage *storage, int fd)
+{
+ bool result; /* Bilan à retourner */
+ GSerializableObjectInterface *iface; /* Interface utilisée */
+ GSerializableObjectInterface *parent_iface; /* Interface parente */
+ GImmediateOperand *operand; /* Version spécialisée */
+
+ iface = G_SERIALIZABLE_OBJECT_GET_IFACE(object);
+
+ parent_iface = g_type_interface_peek_parent(iface);
+
+ result = parent_iface->store(object, storage, fd);
+ if (!result) goto exit;
+
+ operand = G_IMMEDIATE_OPERAND(object);
+
+ result = store_uleb128((uleb128_t []) { operand->raw }, fd);
+
+ exit:
+
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* EXPORTATION SOUS FORME DE CHAINE DE CARACTERES */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
* Paramètres : operand = opérande à transcrire. *
* display = type d'affichage demandé. *
* value = valeur portée par l'opérande transcrite. [OUT] *
@@ -790,10 +1048,10 @@ bool g_imm_operand_is_null(const GImmOperand *operand)
* *
******************************************************************************/
-static size_t _g_imm_operand_to_string(const GImmOperand *operand, ImmOperandDisplay display, char value[IMM_MAX_SIZE])
+size_t _g_immediate_operand_to_string(const GImmediateOperand *operand, ImmOperandDisplay display, char value[IMM_MAX_SIZE])
{
size_t result; /* Longueur à retourner */
- immop_extra_data_t *extra; /* Données insérées à consulter*/
+ immop_extra_data_t extra; /* Données insérées à consulter*/
unsigned int range; /* Catégorie de la taille */
const char *prefix; /* Entrée en matière */
const char *suffix; /* Sortie de matière */
@@ -813,13 +1071,11 @@ static size_t _g_imm_operand_to_string(const GImmOperand *operand, ImmOperandDis
static const char *conv_si_defs[] = { "", "o", "d", "x", "c" };
static const char *conv_us_defs[] = { "", "o", "u", "x", "c" };
- assert(display <= IOD_LAST_VALID);
+ assert(display < IOD_COUNT);
extra = GET_IMM_OP_EXTRA(operand);
- //LOCK_GOBJECT_EXTRA(extra);
-
- range = MDS_RANGE(extra->size);
+ range = MDS_RANGE(extra.size);
/* Encadrement pour les caractères */
if (display == IOD_CHAR)
@@ -862,10 +1118,10 @@ static size_t _g_imm_operand_to_string(const GImmOperand *operand, ImmOperandDis
if (do_padding)
{
- if (extra->display != IOD_COUNT)
- do_padding = (extra->display != IOD_BIN && extra->display != IOD_HEX);
+ if (extra.display != IOD_COUNT)
+ do_padding = (extra.display == IOD_BIN || extra.display == IOD_HEX);
else
- do_padding = (extra->def_display != IOD_BIN && extra->def_display != IOD_HEX);
+ do_padding = (extra.def_display == IOD_BIN || extra.def_display == IOD_HEX);
}
switch (display)
@@ -892,7 +1148,7 @@ static size_t _g_imm_operand_to_string(const GImmOperand *operand, ImmOperandDis
if (display != IOD_BIN)
{
- if (MDS_IS_SIGNED(extra->size))
+ if (MDS_IS_SIGNED(extra.size))
conv = conv_si_defs[display];
else
conv = conv_us_defs[display];
@@ -929,7 +1185,7 @@ static size_t _g_imm_operand_to_string(const GImmOperand *operand, ImmOperandDis
snprintf(format, sizeof(format), "%s%s%s%s%s%s%s", prefix, alternate, intro, zpad, lmod, conv, suffix);
- switch (extra->size)
+ switch (extra.size)
{
case MDS_UNDEFINED:
result = snprintf(value, IMM_MAX_SIZE, "<? undef value ?>");
@@ -982,8 +1238,6 @@ static size_t _g_imm_operand_to_string(const GImmOperand *operand, ImmOperandDis
}
- //UNLOCK_GOBJECT_EXTRA(extra);
-
assert(result > 0);
return result;
@@ -993,555 +1247,37 @@ static size_t _g_imm_operand_to_string(const GImmOperand *operand, ImmOperandDis
/******************************************************************************
* *
-* Paramètres : operand = opérande à transcrire. *
-* syntax = type de représentation demandée. *
-* value = valeur portée par l'opérande transcrite. [OUT] *
+* Paramètres : builder = objet dont l'instance est exportable. *
+* flags = éventuelles indications pour l'opération. *
+* out = chaîne de caractères mise en place. [OUT] *
* *
-* Description : Construit la chaîne de caractères correspondant à l'opérande.*
+* Description : Exporte une chaîne de caractères à partir d'un objet. *
* *
-* Retour : Nombre de caractères utilisés. *
+* Retour : Bilan de l'opération. *
* *
-* Remarques : - *
+* Remarques : La sortie out est à nettoyer avec exit_sized_binary() après *
+* usage. *
* *
******************************************************************************/
-size_t g_imm_operand_to_string(const GImmOperand *operand, char value[IMM_MAX_SIZE])
+static bool g_immediate_operand_to_string(const GStringBuilder *builder, unsigned int flags, sized_binary_t *out)
{
- size_t result; /* Longueur à retourner */
+ bool result; /* Bilan à retourner */
+ const GImmediateOperand *operand; /* Version spécialisée */
ImmOperandDisplay display; /* Type d'affichage courant */
-
- display = g_imm_operand_get_display(operand);
-
- result = _g_imm_operand_to_string(operand, display, value);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* 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_imm_operand_print(const GImmOperand *operand, GBufferLine *line)
-{
char value[IMM_MAX_SIZE]; /* Chaîne à imprimer */
size_t len; /* Taille de l'élément inséré */
- len = g_imm_operand_to_string(operand, value);
-
- g_buffer_line_append_text(line, DLC_ASSEMBLY, value, len, RTT_IMMEDIATE, G_OBJECT(operand));
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : operand = opérande à traiter. *
-* pos = valeur résultante. [OUT] *
-* *
-* Description : Convertit une valeur immédiate en position de type phys_t. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool g_imm_operand_to_phys_t(const GImmOperand *operand, phys_t *pos)
-{
- bool result; /* Bilan à renvoyer */
- immop_extra_data_t *extra; /* Données insérées à consulter*/
-
- extra = GET_IMM_OP_EXTRA(operand);
-
- LOCK_GOBJECT_EXTRA(extra);
-
- result = !MDS_IS_SIGNED(extra->size);
-
- if (result)
- *pos = operand->raw;
-
- UNLOCK_GOBJECT_EXTRA(extra);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : operand = opérande à traiter. *
-* addr = valeur résultante. [OUT] *
-* *
-* Description : Convertit une valeur immédiate en adresse de type virt_t. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool g_imm_operand_to_virt_t(const GImmOperand *operand, virt_t *addr)
-{
- bool result; /* Bilan à renvoyer */
- immop_extra_data_t *extra; /* Données insérées à consulter*/
-
- extra = GET_IMM_OP_EXTRA(operand);
-
- LOCK_GOBJECT_EXTRA(extra);
-
- result = !MDS_IS_SIGNED(extra->size);
-
- if (result)
- *addr = operand->raw;
-
- UNLOCK_GOBJECT_EXTRA(extra);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : operand = opérande à traiter. *
-* val = valeur résultante. [OUT] *
-* *
-* Description : Convertit une valeur immédiate en valeur de type leb128_t. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-void g_imm_operand_as_leb128(const GImmOperand *operand, leb128_t *val)
-{
- immop_extra_data_t *extra; /* Données insérées à consulter*/
-
- extra = GET_IMM_OP_EXTRA(operand);
-
- LOCK_GOBJECT_EXTRA(extra);
-
- *val = operand->raw;
-
- UNLOCK_GOBJECT_EXTRA(extra);
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : operand = opérande à traiter. *
-* val = valeur résultante. [OUT] *
-* *
-* Description : Convertit une valeur immédiate en valeur de type uleb128_t. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-void g_imm_operand_as_uleb128(const GImmOperand *operand, uleb128_t *val)
-{
- immop_extra_data_t *extra; /* Données insérées à consulter*/
-
- extra = GET_IMM_OP_EXTRA(operand);
-
- LOCK_GOBJECT_EXTRA(extra);
-
- *val = operand->raw;
-
- UNLOCK_GOBJECT_EXTRA(extra);
-
-}
-
-
-
-/* ---------------------------------------------------------------------------------- */
-/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
-/* ---------------------------------------------------------------------------------- */
-
-
-/******************************************************************************
-* *
-* Paramètres : a = premier opérande à consulter. *
-* b = second opérande à consulter. *
-* lock = précise le besoin en verrouillage. *
-* *
-* Description : Compare un opérande avec un autre. *
-* *
-* Retour : Bilan de la comparaison. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static int g_imm_operand_compare(const GImmOperand *a, const GImmOperand *b, bool lock)
-{
- int result; /* Bilan à retourner */
- immop_extra_data_t *ea; /* Données insérées à modifier */
- immop_extra_data_t *eb; /* Données insérées à modifier */
- GArchOperandClass *class; /* Classe parente normalisée */
-
- ea = GET_IMM_OP_EXTRA(a);
- eb = GET_IMM_OP_EXTRA(b);
-
- if (lock)
- {
- LOCK_GOBJECT_EXTRA(ea);
- LOCK_GOBJECT_EXTRA(eb);
- }
-
- result = sort_unsigned_long(ea->size, eb->size);
-
- if (result == 0)
- sort_uint64_t(a->raw, b->raw);
-
- if (result == 0)
- result = sort_unsigned_long(ea->def_display, eb->def_display);
-
- if (result == 0)
- result = sort_unsigned_long(ea->display, eb->display);
-
- if (result == 0)
- {
- class = G_ARCH_OPERAND_CLASS(g_imm_operand_parent_class);
- result = class->compare(G_ARCH_OPERAND(a), G_ARCH_OPERAND(b), false);
- }
-
- if (lock)
- {
- UNLOCK_GOBJECT_EXTRA(eb);
- UNLOCK_GOBJECT_EXTRA(ea);
- }
-
- return result;
-
-}
-
-
-#ifdef INCLUDE_GTK_SUPPORT
-
-
-/******************************************************************************
-* *
-* 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 (operand->raw <= UCHAR_MAX && isprint(operand->raw))
- switch (operand->raw)
- {
- case '&':
- asprintf(&result, _("Character: '&amp;'"));
- break;
- case '<':
- asprintf(&result, _("Character: '&lt;'"));
- break;
- case '>':
- asprintf(&result, _("Character: '&gt;'"));
- break;
- default:
- asprintf(&result, _("Character: '%c'"), (char)operand->raw);
- break;
- }
-
- else
- asprintf(&result, _("Character: &lt;not printable&gt;"));
-
- /* Binaire */
-
- _g_imm_operand_to_string(operand, 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, 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, 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, IOD_HEX, value);
-
- asprintf(&conv, _("Hexadecimal: %s"), value);
-
- result = stradd(result, "\n");
- result = stradd(result, conv);
-
- free(conv);
-
- return result;
-
-}
-
-
-#endif
-
-
-/******************************************************************************
-* *
-* Paramètres : operand = objet dont l'instance se veut unique. *
-* lock = précise le besoin en verrouillage. *
-* *
-* Description : Fournit l'empreinte d'un candidat à une centralisation. *
-* *
-* Retour : Empreinte de l'élément représenté. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static guint g_imm_operand_hash(const GImmOperand *operand, bool lock)
-{
- guint result; /* Valeur à retourner */
- immop_extra_data_t *extra; /* Données insérées à modifier */
- GArchOperandClass *class; /* Classe parente normalisée */
-
- extra = GET_IMM_OP_EXTRA(operand);
-
- if (lock)
- LOCK_GOBJECT_EXTRA(extra);
-
- class = G_ARCH_OPERAND_CLASS(g_imm_operand_parent_class);
- result = class->hash(G_ARCH_OPERAND(operand), false);
-
- result ^= (operand->raw & 0xffffffff);
- result ^= (operand->raw >> 32);
-
- if (lock)
- UNLOCK_GOBJECT_EXTRA(extra);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : operand = élément GLib à constuire. *
-* storage = conservateur de données à manipuler ou NULL. *
-* pbuf = zone tampon à lire. *
-* *
-* Description : Charge un contenu depuis une mémoire tampon. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static bool g_imm_operand_load(GImmOperand *operand, GObjectStorage *storage, packed_buffer_t *pbuf)
-{
- bool result; /* Bilan à retourner */
- GArchOperandClass *parent; /* Classe parente à consulter */
- immop_extra_data_t *extra; /* Données insérées à modifier */
- uleb128_t value; /* Valeur ULEB128 à charger */
- uint8_t val; /* Champ de bits manipulé */
-
- parent = G_ARCH_OPERAND_CLASS(g_imm_operand_parent_class);
-
- result = parent->load(G_ARCH_OPERAND(operand), storage, pbuf);
-
- if (result)
- {
- extra = GET_IMM_OP_EXTRA(operand);
-
- LOCK_GOBJECT_EXTRA(extra);
-
- result = unpack_uleb128(&value, pbuf);
-
- if (result)
- extra->size = value;
-
- if (result)
- {
- result = extract_packed_buffer(pbuf, &val, sizeof(uint8_t), false);
-
- if (result)
- extra->def_display = val;
-
- }
-
- if (result)
- {
- result = extract_packed_buffer(pbuf, &val, sizeof(uint8_t), false);
-
- if (result)
- extra->display = val;
-
- }
-
- UNLOCK_GOBJECT_EXTRA(extra);
-
- }
-
- if (result)
- result = extract_packed_buffer(pbuf, &operand->raw, sizeof(uint64_t), true);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : operand = élément GLib à consulter. *
-* storage = conservateur de données à manipuler ou NULL. *
-* pbuf = zone tampon à remplir. *
-* *
-* Description : Sauvegarde un contenu dans une mémoire tampon. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static bool g_imm_operand_store(GImmOperand *operand, GObjectStorage *storage, packed_buffer_t *pbuf)
-{
- bool result; /* Bilan à retourner */
- GArchOperandClass *parent; /* Classe parente à consulter */
- immop_extra_data_t *extra; /* Données insérées à modifier */
+ operand = G_IMMEDIATE_OPERAND(builder);
- parent = G_ARCH_OPERAND_CLASS(g_imm_operand_parent_class);
+ display = g_immediate_operand_get_display(operand);
- result = parent->store(G_ARCH_OPERAND(operand), storage, pbuf);
+ len = _g_immediate_operand_to_string(operand, display, value);
- if (result)
- {
- extra = GET_IMM_OP_EXTRA(operand);
-
- LOCK_GOBJECT_EXTRA(extra);
-
- result = pack_uleb128((uleb128_t []){ extra->size }, pbuf);
-
- if (result)
- result = extend_packed_buffer(pbuf, (uint8_t []) { extra->def_display }, sizeof(uint8_t), false);
-
- if (result)
- result = extend_packed_buffer(pbuf, (uint8_t []) { extra->display }, sizeof(uint8_t), false);
-
- UNLOCK_GOBJECT_EXTRA(extra);
-
- }
+ result = (len > 0);
if (result)
- result = extend_packed_buffer(pbuf, &operand->raw, sizeof(uint64_t), true);
-
- return result;
-
-}
-
-
-
-/* ---------------------------------------------------------------------------------- */
-/* COMMUNICATION D'UN CIBLAGE POTENTIEL */
-/* ---------------------------------------------------------------------------------- */
-
-
-/******************************************************************************
-* *
-* Paramètres : operand = operande à consulter. *
-* src = localisation de l'instruction mère. *
-* format = format reconnu pour le binaire chargé. *
-* proc = architecture associée à ce même binaire. *
-* addr = localisation de la cible. [OUT] *
-* *
-* Description : Obtient l'adresse de la cible visée par un opérande. *
-* *
-* Retour : true si la cible est valide, false sinon. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static bool g_imm_operand_get_addr(const GImmOperand *operand, const vmpa2t *src, GBinFormat *format, GArchProcessor *proc, vmpa2t *addr)
-{
- bool result; /* Bilan à retourner */
- virt_t virt; /* Adresse virtuelle */
-
- result = g_imm_operand_to_virt_t(operand, &virt);
-
- if (result)
- result = g_exe_format_translate_address_into_vmpa(G_EXE_FORMAT(format), virt, addr);
-
- return result;
-
-}
-
-
-
-/* ---------------------------------------------------------------------------------- */
-/* CONSTRUCTION D'UN CONTENU ALTERNATIF */
-/* ---------------------------------------------------------------------------------- */
-
-
-/******************************************************************************
-* *
-* Paramètres : operand = operande à consulter. *
-* text = texte alternatif de représentation. *
-* *
-* Description : Construit un opérande de représentation alternative. *
-* *
-* Retour : Nouvel opérande, en version renommée. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static GRenamedOperand *g_imm_operand_build(const GImmOperand *operand, const char *text)
-{
- GRenamedOperand *result; /* Instance à retourner */
-
- result = G_RENAMED_OPERAND(g_known_imm_operand_new(operand, text));
+ add_to_sized_binary(out, value, len);
return result;