diff options
Diffstat (limited to 'plugins/dalvik/operands/register.c')
-rw-r--r-- | plugins/dalvik/operands/register.c | 156 |
1 files changed, 80 insertions, 76 deletions
diff --git a/plugins/dalvik/operands/register.c b/plugins/dalvik/operands/register.c index d2dd174..7d011a0 100644 --- a/plugins/dalvik/operands/register.c +++ b/plugins/dalvik/operands/register.c @@ -24,18 +24,14 @@ #include "register.h" -#include <arch/operand-int.h> -#include <arch/register.h> +#include <arch/register-int.h> /* Définition d'un opérande visant un registre Dalvik (instance) */ struct _GDalvikRegisterOperand { - GArchOperand parent; /* Instance parente */ - - GDalvikRegister *reg; /* Registre représenté */ - bool is_written; /* Changement de contenu */ + GRegisterOperand parent; /* Instance parente */ }; @@ -43,7 +39,7 @@ struct _GDalvikRegisterOperand /* Définition d'un opérande visant un registre Dalvik (classe) */ struct _GDalvikRegisterOperandClass { - GArchOperandClass parent; /* Classe parente */ + GRegisterOperandClass parent; /* Classe parente */ }; @@ -60,16 +56,21 @@ static void g_dalvik_register_operand_dispose(GDalvikRegisterOperand *); /* Procède à la libération totale de la mémoire. */ static void g_dalvik_register_operand_finalize(GDalvikRegisterOperand *); -/* Compare un opérande avec un autre. */ -static int g_dalvik_register_operand_compare(const GDalvikRegisterOperand *, const GDalvikRegisterOperand *); -/* Traduit un opérande en version humainement lisible. */ -static void g_dalvik_register_operand_print(const GDalvikRegisterOperand *, GBufferLine *, AsmSyntax); + +/* --------------------- TRANSPOSITIONS VIA CACHE DES OPERANDES --------------------- */ + + +/* Charge un opérande depuis une mémoire tampon. */ +static bool g_dalvik_register_operand_unserialize(GDalvikRegisterOperand *, GAsmStorage *, GBinFormat *, packed_buffer *); + +/* Sauvegarde un opérande dans une mémoire tampon. */ +static bool g_dalvik_register_operand_serialize(const GDalvikRegisterOperand *, GAsmStorage *, packed_buffer *); /* Indique le type défini par la GLib pour un opérande de registre Dalvik. */ -G_DEFINE_TYPE(GDalvikRegisterOperand, g_dalvik_register_operand, G_TYPE_ARCH_OPERAND); +G_DEFINE_TYPE(GDalvikRegisterOperand, g_dalvik_register_operand, G_TYPE_REGISTER_OPERAND); /****************************************************************************** @@ -96,8 +97,8 @@ static void g_dalvik_register_operand_class_init(GDalvikRegisterOperandClass *kl operand = G_ARCH_OPERAND_CLASS(klass); - operand->compare = (operand_compare_fc)g_dalvik_register_operand_compare; - operand->print = (operand_print_fc)g_dalvik_register_operand_print; + operand->unserialize = (unserialize_operand_fc)g_dalvik_register_operand_unserialize; + operand->serialize = (serialize_operand_fc)g_dalvik_register_operand_serialize; } @@ -116,8 +117,6 @@ static void g_dalvik_register_operand_class_init(GDalvikRegisterOperandClass *kl static void g_dalvik_register_operand_init(GDalvikRegisterOperand *operand) { - operand->reg = NULL; - operand->is_written = false; } @@ -136,9 +135,6 @@ static void g_dalvik_register_operand_init(GDalvikRegisterOperand *operand) static void g_dalvik_register_operand_dispose(GDalvikRegisterOperand *operand) { - if (operand->reg != NULL) - g_object_unref(G_OBJECT(operand->reg)); - G_OBJECT_CLASS(g_dalvik_register_operand_parent_class)->dispose(G_OBJECT(operand)); } @@ -165,51 +161,6 @@ static void g_dalvik_register_operand_finalize(GDalvikRegisterOperand *operand) /****************************************************************************** * * -* Paramètres : a = premier opérande à consulter. * -* b = second opérande à consulter. * -* * -* Description : Compare un opérande avec un autre. * -* * -* Retour : Bilan de la comparaison. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int g_dalvik_register_operand_compare(const GDalvikRegisterOperand *a, const GDalvikRegisterOperand *b) -{ - int result; /* Bilan à retourner */ - - result = g_dalvik_register_compare(a->reg, b->reg); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : operand = opérande à traiter. * -* line = ligne tampon où imprimer l'opérande donné. * -* syntax = type de représentation demandée. * -* * -* Description : Traduit un opérande en version humainement lisible. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_dalvik_register_operand_print(const GDalvikRegisterOperand *operand, GBufferLine *line, AsmSyntax syntax) -{ - g_arch_register_print(G_ARCH_REGISTER(operand->reg), line, syntax); - -} - - -/****************************************************************************** -* * * Paramètres : content = flux de données à analyser. * * pos = position courante dans ce flux. [OUT] * * low = position éventuelle des 4 bits visés. [OUT] * @@ -303,7 +254,7 @@ GArchOperand *g_dalvik_register_operand_new_from_existing(GDalvikRegister *reg) result = g_object_new(G_TYPE_DALVIK_REGISTER_OPERAND, NULL); - result->reg = reg; + G_REGISTER_OPERAND(result)->reg = G_ARCH_REGISTER(reg); return G_ARCH_OPERAND(result); @@ -324,44 +275,97 @@ GArchOperand *g_dalvik_register_operand_new_from_existing(GDalvikRegister *reg) const GDalvikRegister *g_dalvik_register_operand_get(const GDalvikRegisterOperand *operand) { - return operand->reg; + GDalvikRegister *result; /* Instance à retourner */ + + result = G_DALVIK_REGISTER(G_REGISTER_OPERAND(operand)->reg); + + return result; } + +/* ---------------------------------------------------------------------------------- */ +/* TRANSPOSITIONS VIA CACHE DES OPERANDES */ +/* ---------------------------------------------------------------------------------- */ + + /****************************************************************************** * * -* Paramètres : operand = opérande représentant un registre à mettre à jour. * +* 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 : Marque l'opérande comme étant écrit plutôt que consulté. * +* Description : Charge un opérande depuis une mémoire tampon. * * * -* Retour : - * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -void g_dalvik_register_operand_mark_as_written(GDalvikRegisterOperand *operand) +static bool g_dalvik_register_operand_unserialize(GDalvikRegisterOperand *operand, GAsmStorage *storage, GBinFormat *format, packed_buffer *pbuf) { - operand->is_written = true; + bool result; /* Bilan à retourner */ + GArchOperandClass *parent; /* Classe parente à consulter */ + uint16_t index; /* Identifiant de registre */ + GDalvikRegister *reg; /* Registre à intégrer */ + + parent = G_ARCH_OPERAND_CLASS(g_dalvik_register_operand_parent_class); + + result = parent->unserialize(G_ARCH_OPERAND(operand), storage, format, pbuf); + + if (result) + { + result = extract_packed_buffer(pbuf, &index, sizeof(uint16_t), true); + + if (result) + { + reg = g_dalvik_register_new(index); + result = (reg != NULL); + } + + if (result) + G_REGISTER_OPERAND(operand)->reg = G_ARCH_REGISTER(reg); + + } + + return result; } /****************************************************************************** * * -* Paramètres : operand = opérande représentant un registre à consulter. * +* Paramètres : operand = opérande d'assemblage à consulter. * +* storage = mécanisme de sauvegarde à manipuler. * +* pbuf = zone tampon à remplir. * * * -* Description : Indique le type d'accès réalisé sur l'opérande. * +* Description : Sauvegarde un opérande dans une mémoire tampon. * * * -* Retour : Type d'accès : true en cas d'écriture, false sinon. * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -bool g_dalvik_register_operand_is_written(const GDalvikRegisterOperand *operand) +static bool g_dalvik_register_operand_serialize(const GDalvikRegisterOperand *operand, GAsmStorage *storage, packed_buffer *pbuf) { - return operand->is_written; + bool result; /* Bilan à retourner */ + GArchOperandClass *parent; /* Classe parente à consulter */ + uint16_t index; /* Identifiant de registre */ + + parent = G_ARCH_OPERAND_CLASS(g_dalvik_register_operand_parent_class); + + result = parent->serialize(G_ARCH_OPERAND(operand), storage, pbuf); + + if (result) + { + index = g_dalvik_register_get_index(G_DALVIK_REGISTER(G_REGISTER_OPERAND(operand)->reg)); + result = extend_packed_buffer(pbuf, &index, sizeof(uint16_t), true); + } + + return result; } |