diff options
Diffstat (limited to 'plugins/arm/v7/operands/offset.c')
-rw-r--r-- | plugins/arm/v7/operands/offset.c | 280 |
1 files changed, 121 insertions, 159 deletions
diff --git a/plugins/arm/v7/operands/offset.c b/plugins/arm/v7/operands/offset.c index 615e296..724523d 100644 --- a/plugins/arm/v7/operands/offset.c +++ b/plugins/arm/v7/operands/offset.c @@ -24,22 +24,26 @@ #include "offset.h" +#include <assert.h> #include <stdio.h> #include <string.h> -#include <arch/operand-int.h> -#include <common/sort.h> -#include <gtkext/gtkblockdisplay.h> +#include <core/columns.h> +#include "../operand-int.h" + + + +/* -------------------------- DEFINITION D'UN NOUVEAU TYPE -------------------------- */ + /* Définition d'un opérande visant à constituer un décalage relatif ARMv7 (instance) */ struct _GArmV7OffsetOperand { - GArchOperand parent; /* Instance parente */ + GArmV7Operand parent; /* Instance parente */ - bool positive; /* Sens du décalage */ GArchOperand *value; /* Valeur du décalage */ }; @@ -48,7 +52,7 @@ struct _GArmV7OffsetOperand /* Définition d'un opérande visant à constituer un décalage relatif ARMv7 (classe) */ struct _GArmV7OffsetOperandClass { - GArchOperandClass parent; /* Classe parente */ + GArmV7OperandClass parent; /* Classe parente */ }; @@ -65,8 +69,13 @@ static void g_armv7_offset_operand_dispose(GArmV7OffsetOperand *); /* Procède à la libération totale de la mémoire. */ static void g_armv7_offset_operand_finalize(GArmV7OffsetOperand *); + + +/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */ + + /* Compare un opérande avec un autre. */ -static int g_armv7_offset_operand_compare(const GArmV7OffsetOperand *, const GArmV7OffsetOperand *); +static int g_armv7_offset_operand_compare(const GArmV7OffsetOperand *, const GArmV7OffsetOperand *, bool); /* Détermine le chemin conduisant à un opérande interne. */ static char *g_armv7_offset_operand_find_inner_operand_path(const GArmV7OffsetOperand *, const GArchOperand *); @@ -77,21 +86,21 @@ static GArchOperand *g_armv7_offset_operand_get_inner_operand_from_path(const GA /* Traduit un opérande en version humainement lisible. */ static void g_armv7_offset_operand_print(const GArmV7OffsetOperand *, GBufferLine *); +/* Fournit une liste de candidats embarqués par un candidat. */ +static GArchOperand **g_armv7_offset_operand_list_inner_instances(const GArmV7OffsetOperand *, size_t *); - -/* --------------------- TRANSPOSITIONS VIA CACHE DES OPERANDES --------------------- */ +/* Met à jour une liste de candidats embarqués par un candidat. */ +static void g_armv7_offset_operand_update_inner_instances(GArmV7OffsetOperand *, GArchOperand **, size_t); -/* Charge un opérande depuis une mémoire tampon. */ -static bool g_armv7_offset_operand_unserialize(GArmV7OffsetOperand *, GAsmStorage *, GBinFormat *, packed_buffer_t *); - -/* Sauvegarde un opérande dans une mémoire tampon. */ -static bool g_armv7_offset_operand_serialize(const GArmV7OffsetOperand *, GAsmStorage *, packed_buffer_t *); +/* ---------------------------------------------------------------------------------- */ +/* DEFINITION D'UN NOUVEAU TYPE */ +/* ---------------------------------------------------------------------------------- */ /* Indique le type défini par la GLib pour un décalage relatif ARMv7. */ -G_DEFINE_TYPE(GArmV7OffsetOperand, g_armv7_offset_operand, G_TYPE_ARCH_OPERAND); +G_DEFINE_TYPE(GArmV7OffsetOperand, g_armv7_offset_operand, G_TYPE_ARMV7_OPERAND); /****************************************************************************** @@ -124,8 +133,11 @@ static void g_armv7_offset_operand_class_init(GArmV7OffsetOperandClass *klass) operand->print = (operand_print_fc)g_armv7_offset_operand_print; - operand->unserialize = (unserialize_operand_fc)g_armv7_offset_operand_unserialize; - operand->serialize = (serialize_operand_fc)g_armv7_offset_operand_serialize; + operand->list_inner = (operand_list_inners_fc)g_armv7_offset_operand_list_inner_instances; + operand->update_inner = (operand_update_inners_fc)g_armv7_offset_operand_update_inner_instances; + + operand->load = g_arch_operand_load_generic_fixed_1; + operand->store = g_arch_operand_store_generic_fixed; } @@ -163,8 +175,7 @@ static void g_armv7_offset_operand_init(GArmV7OffsetOperand *operand) static void g_armv7_offset_operand_dispose(GArmV7OffsetOperand *operand) { - if (operand->value != NULL) - g_object_unref(G_OBJECT(operand->value)); + g_clear_object(&operand->value); G_OBJECT_CLASS(g_armv7_offset_operand_parent_class)->dispose(G_OBJECT(operand)); @@ -192,8 +203,69 @@ static void g_armv7_offset_operand_finalize(GArmV7OffsetOperand *operand) /****************************************************************************** * * -* Paramètres : a = premier opérande à consulter. * -* b = second opérande à consulter. * +* Paramètres : positive = indique si la quantité doit être ajoutée ou non. * +* value = valeur du décalage à appliquer. * +* * +* Description : Crée un décalage selon un sens et une valeur donnés. * +* * +* Retour : Opérande mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArchOperand *g_armv7_offset_operand_new(bool positive, GArchOperand *value) +{ + GArmV7OffsetOperand *result; /* Structure à retourner */ + + result = g_object_new(G_TYPE_ARMV7_OFFSET_OPERAND, NULL); + + if (positive) + g_arch_operand_set_flag(G_ARCH_OPERAND(result), A7OOF_POSITIVE); + + result->value = value; + + return G_ARCH_OPERAND(result); + +} + + +/****************************************************************************** +* * +* Paramètres : operand = opérande à consulter. * +* * +* Description : Founit la valeur utilisée pour un décalage. * +* * +* Retour : Opérande en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArchOperand *g_armv7_offset_operand_get_value(const GArmV7OffsetOperand *operand) +{ + GArchOperand *result; /* Instance à retourner */ + + result = operand->value; + + g_object_ref(G_OBJECT(result)); + + return result; + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* 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. * * * @@ -203,16 +275,18 @@ static void g_armv7_offset_operand_finalize(GArmV7OffsetOperand *operand) * * ******************************************************************************/ -static int g_armv7_offset_operand_compare(const GArmV7OffsetOperand *a, const GArmV7OffsetOperand *b) +static int g_armv7_offset_operand_compare(const GArmV7OffsetOperand *a, const GArmV7OffsetOperand *b, bool lock) { int result; /* Bilan à faire remonter */ - - result = sort_boolean(a->positive, b->positive); - if (result != 0) goto gaooc_done; + GArchOperandClass *class; /* Classe parente normalisée */ result = g_arch_operand_compare(a->value, b->value); - gaooc_done: + if (result == 0) + { + class = G_ARCH_OPERAND_CLASS(g_armv7_offset_operand_parent_class); + result = class->compare(G_ARCH_OPERAND(a), G_ARCH_OPERAND(b), false); + } return result; @@ -299,7 +373,7 @@ static GArchOperand *g_armv7_offset_operand_get_inner_operand_from_path(const GA static void g_armv7_offset_operand_print(const GArmV7OffsetOperand *operand, GBufferLine *line) { - if (!operand->positive) + if (!g_arch_operand_has_flag(G_ARCH_OPERAND(operand), A7OOF_POSITIVE)) g_buffer_line_append_text(line, DLC_ASSEMBLY, "-", 1, RTT_KEY_WORD, NULL); g_arch_operand_print(operand->value, line); @@ -309,127 +383,27 @@ static void g_armv7_offset_operand_print(const GArmV7OffsetOperand *operand, GBu /****************************************************************************** * * -* Paramètres : positive = indique si la quantité doit être ajoutée ou non. * -* value = valeur du décalage à appliquer. * +* Paramètres : operand = objet dont l'instance se veut unique. * +* count = quantité d'instances à l'unicité internes. * * * -* Description : Crée un décalage selon un sens et une valeur donnés. * +* Description : Fournit une liste de candidats embarqués par un candidat. * * * -* Retour : Opérande mis en place. * +* Retour : Liste de candidats internes ou NULL si aucun. * * * * Remarques : - * * * ******************************************************************************/ -GArchOperand *g_armv7_offset_operand_new(bool positive, GArchOperand *value) +static GArchOperand **g_armv7_offset_operand_list_inner_instances(const GArmV7OffsetOperand *operand, size_t *count) { - GArmV7OffsetOperand *result; /* Structure à retourner */ + GArchOperand **result; /* Instances à retourner */ - result = g_object_new(G_TYPE_ARMV7_OFFSET_OPERAND, NULL); + *count = 1; - result->positive = positive; - result->value = value; + result = malloc(*count * sizeof(GArchOperand *)); - return G_ARCH_OPERAND(result); - -} - - -/****************************************************************************** -* * -* Paramètres : operand = opérande à consulter. * -* * -* Description : Indique le sens du décalage représenté. * -* * -* Retour : Indication d'ajout ou de retrait. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool g_armv7_offset_operand_is_positive(const GArmV7OffsetOperand *operand) -{ - return operand->positive; - -} - - -/****************************************************************************** -* * -* Paramètres : operand = opérande à consulter. * -* * -* Description : Founit la valeur utilisée pour un décalage. * -* * -* Retour : Opérande en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GArchOperand *g_armv7_offset_operand_get_value(const GArmV7OffsetOperand *operand) -{ - GArchOperand *result; /* Instance à retourner */ - - result = operand->value; - - g_object_ref(G_OBJECT(result)); - - return result; - -} - - - -/* ---------------------------------------------------------------------------------- */ -/* TRANSPOSITIONS VIA CACHE DES OPERANDES */ -/* ---------------------------------------------------------------------------------- */ - - -/****************************************************************************** -* * -* Paramètres : operand = opérande d'assemblage à constituer. * -* storage = mécanisme de sauvegarde à manipuler. * -* format = format binaire chargé associé à l'architecture. * -* pbuf = zone tampon à remplir. * -* * -* Description : Charge un opérande depuis une mémoire tampon. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool g_armv7_offset_operand_unserialize(GArmV7OffsetOperand *operand, GAsmStorage *storage, GBinFormat *format, packed_buffer_t *pbuf) -{ - bool result; /* Bilan à retourner */ - GArchOperandClass *parent; /* Classe parente à consulter */ - GArchOperand *value; /* Valeur à intégrer */ - uint8_t positive; /* Sens du décalage */ - - parent = G_ARCH_OPERAND_CLASS(g_armv7_offset_operand_parent_class); - - result = parent->unserialize(G_ARCH_OPERAND(operand), storage, format, pbuf); - - if (result) - { - value = g_arch_operand_load(storage, format, pbuf); - - if (value == NULL) - result = false; - - else - operand->value = value; - - } - - if (result) - { - result = extract_packed_buffer(pbuf, &positive, sizeof(uint8_t), false); - - if (result) - operand->positive = (positive == 1 ? true : false); - - } + result[0] = operand->value; + g_object_ref(G_OBJECT(result[0])); return result; @@ -438,37 +412,25 @@ static bool g_armv7_offset_operand_unserialize(GArmV7OffsetOperand *operand, GAs /****************************************************************************** * * -* Paramètres : operand = opérande d'assemblage à consulter. * -* storage = mécanisme de sauvegarde à manipuler. * -* pbuf = zone tampon à remplir. * +* Paramètres : operand = objet dont l'instance se veut unique. * +* instances = liste de candidats internes devenus singletons. * +* count = quantité d'instances à l'unicité internes. * * * -* Description : Sauvegarde un opérande dans une mémoire tampon. * +* Description : Met à jour une liste de candidats embarqués par un candidat. * * * -* Retour : Bilan de l'opération. * +* Retour : - * * * * Remarques : - * * * ******************************************************************************/ -static bool g_armv7_offset_operand_serialize(const GArmV7OffsetOperand *operand, GAsmStorage *storage, packed_buffer_t *pbuf) +static void g_armv7_offset_operand_update_inner_instances(GArmV7OffsetOperand *operand, GArchOperand **instances, size_t count) { - bool result; /* Bilan à retourner */ - GArchOperandClass *parent; /* Classe parente à consulter */ - uint8_t positive; /* Sens du décalage */ - - parent = G_ARCH_OPERAND_CLASS(g_armv7_offset_operand_parent_class); + assert(count == 1); - result = parent->serialize(G_ARCH_OPERAND(operand), storage, pbuf); + g_clear_object(&operand->value); - if (result) - { - positive = (operand->positive ? 1 : 0); - result = extend_packed_buffer(pbuf, &positive, sizeof(uint8_t), false); - } - - if (result) - result = g_arch_operand_store(operand->value, storage, pbuf); - - return result; + operand->value = instances[0]; + g_object_ref(G_OBJECT(instances[0])); } |