diff options
Diffstat (limited to 'plugins/dalvik')
-rw-r--r-- | plugins/dalvik/core.c | 2 | ||||
-rw-r--r-- | plugins/dalvik/operand.c | 3 | ||||
-rw-r--r-- | plugins/dalvik/operands/register.c | 112 | ||||
-rw-r--r-- | plugins/dalvik/operands/register.h | 2 | ||||
-rw-r--r-- | plugins/dalvik/register.c | 134 | ||||
-rw-r--r-- | plugins/dalvik/register.h | 5 |
6 files changed, 133 insertions, 125 deletions
diff --git a/plugins/dalvik/core.c b/plugins/dalvik/core.c index cc96843..524e3c9 100644 --- a/plugins/dalvik/core.c +++ b/plugins/dalvik/core.c @@ -63,6 +63,8 @@ static void register_dalvik_gtypes(void) g_type_ensure(G_TYPE_DALVIK_POOL_OPERAND); g_type_ensure(G_TYPE_DALVIK_REGISTER_OPERAND); + g_type_ensure(G_TYPE_DALVIK_REGISTER); + } diff --git a/plugins/dalvik/operand.c b/plugins/dalvik/operand.c index 4d8fc73..e89bcab 100644 --- a/plugins/dalvik/operand.c +++ b/plugins/dalvik/operand.c @@ -29,6 +29,9 @@ #include <stdarg.h> +#include <arch/operands/register.h> + + /* Liste de tous les types d'opérandes */ typedef enum _DalvikOperandID diff --git a/plugins/dalvik/operands/register.c b/plugins/dalvik/operands/register.c index 7d011a0..ede3eb6 100644 --- a/plugins/dalvik/operands/register.c +++ b/plugins/dalvik/operands/register.c @@ -24,7 +24,7 @@ #include "register.h" -#include <arch/register-int.h> +#include <arch/operands/register-int.h> @@ -58,17 +58,6 @@ static void g_dalvik_register_operand_finalize(GDalvikRegisterOperand *); -/* --------------------- 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_REGISTER_OPERAND); @@ -88,18 +77,12 @@ G_DEFINE_TYPE(GDalvikRegisterOperand, g_dalvik_register_operand, G_TYPE_REGISTER static void g_dalvik_register_operand_class_init(GDalvikRegisterOperandClass *klass) { GObjectClass *object; /* Autre version de la classe */ - GArchOperandClass *operand; /* Version de classe parente */ object = G_OBJECT_CLASS(klass); object->dispose = (GObjectFinalizeFunc/* ! */)g_dalvik_register_operand_dispose; object->finalize = (GObjectFinalizeFunc)g_dalvik_register_operand_finalize; - operand = G_ARCH_OPERAND_CLASS(klass); - - operand->unserialize = (unserialize_operand_fc)g_dalvik_register_operand_unserialize; - operand->serialize = (serialize_operand_fc)g_dalvik_register_operand_serialize; - } @@ -181,7 +164,7 @@ GArchOperand *g_dalvik_register_operand_new(const GBinContent *content, vmpa2t * uint8_t index8; /* Indice sur 8 bits */ uint16_t index16; /* Indice sur 16 bits */ bool test; /* Bilan de lecture */ - GDalvikRegister *reg; /* Registre à représenter */ + GArchRegister *reg; /* Registre à représenter */ result = NULL; @@ -248,13 +231,13 @@ GArchOperand *g_dalvik_register_operand_new(const GBinContent *content, vmpa2t * * * ******************************************************************************/ -GArchOperand *g_dalvik_register_operand_new_from_existing(GDalvikRegister *reg) +GArchOperand *g_dalvik_register_operand_new_from_existing(GArchRegister *reg) { GDalvikRegisterOperand *result; /* Structure à retourner */ result = g_object_new(G_TYPE_DALVIK_REGISTER_OPERAND, NULL); - G_REGISTER_OPERAND(result)->reg = G_ARCH_REGISTER(reg); + G_REGISTER_OPERAND(result)->reg = reg; return G_ARCH_OPERAND(result); @@ -282,90 +265,3 @@ const GDalvikRegister *g_dalvik_register_operand_get(const GDalvikRegisterOperan 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_dalvik_register_operand_unserialize(GDalvikRegisterOperand *operand, GAsmStorage *storage, GBinFormat *format, packed_buffer *pbuf) -{ - 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 d'assemblage à consulter. * -* storage = mécanisme de sauvegarde à manipuler. * -* pbuf = zone tampon à remplir. * -* * -* Description : Sauvegarde un opérande dans une mémoire tampon. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool g_dalvik_register_operand_serialize(const GDalvikRegisterOperand *operand, GAsmStorage *storage, packed_buffer *pbuf) -{ - 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; - -} diff --git a/plugins/dalvik/operands/register.h b/plugins/dalvik/operands/register.h index 29b14c8..cca1ff4 100644 --- a/plugins/dalvik/operands/register.h +++ b/plugins/dalvik/operands/register.h @@ -59,7 +59,7 @@ GType g_dalvik_register_operand_get_type(void); GArchOperand *g_dalvik_register_operand_new(const GBinContent *, vmpa2t *, bool *, MemoryDataSize, SourceEndian); /* Crée un opérande visant un registre Dalvik. */ -GArchOperand *g_dalvik_register_operand_new_from_existing(GDalvikRegister *); +GArchOperand *g_dalvik_register_operand_new_from_existing(GArchRegister *); /* Fournit le registre Dalvik associé à l'opérande. */ const GDalvikRegister *g_dalvik_register_operand_get(const GDalvikRegisterOperand *); diff --git a/plugins/dalvik/register.c b/plugins/dalvik/register.c index 1e59421..458d219 100644 --- a/plugins/dalvik/register.c +++ b/plugins/dalvik/register.c @@ -76,7 +76,18 @@ static guint g_dalvik_register_hash(const GDalvikRegister *); static void g_dalvik_register_print(const GDalvikRegister *, GBufferLine *, AsmSyntax); /* Crée une réprésentation de registre Dalvik. */ -static GDalvikRegister *_g_dalvik_register_new(uint16_t); +static GArchRegister *_g_dalvik_register_new(uint16_t); + + + +/* --------------------- TRANSPOSITIONS VIA CACHE DES REGISTRES --------------------- */ + + +/* Charge un registre depuis une mémoire tampon. */ +static GArchRegister *g_dalvik_register_unserialize(GDalvikRegister *, GAsmStorage *, packed_buffer *); + +/* Sauvegarde un registre dans une mémoire tampon. */ +static bool g_dalvik_register_serialize(const GDalvikRegister *, GAsmStorage *, packed_buffer *); @@ -84,13 +95,13 @@ static GDalvikRegister *_g_dalvik_register_new(uint16_t); /* Conservation des registres utilisés */ -static GDalvikRegister **_dalvik_registers = NULL; +static GArchRegister **_dalvik_registers = NULL; static size_t _dreg_count = 0; G_LOCK_DEFINE_STATIC(_dreg_mutex); /* Fournit le singleton associé à un registre Dalvik. */ -static GDalvikRegister *get_dalvik_register(uint16_t); +static GArchRegister *get_dalvik_register(uint16_t); @@ -118,18 +129,20 @@ G_DEFINE_TYPE(GDalvikRegister, g_dalvik_register, G_TYPE_ARCH_REGISTER); static void g_dalvik_register_class_init(GDalvikRegisterClass *klass) { GObjectClass *object; /* Autre version de la classe */ - GArchRegisterClass *register_class; /* Classe de haut niveau */ + GArchRegisterClass *reg_class; /* Classe de haut niveau */ object = G_OBJECT_CLASS(klass); object->dispose = (GObjectFinalizeFunc/* ! */)g_dalvik_register_dispose; object->finalize = (GObjectFinalizeFunc)g_dalvik_register_finalize; - register_class = G_ARCH_REGISTER_CLASS(klass); + reg_class = G_ARCH_REGISTER_CLASS(klass); - register_class->hash = (reg_hash_fc)g_dalvik_register_hash; - register_class->compare = (reg_compare_fc)g_dalvik_register_compare; - register_class->print = (reg_print_fc)g_dalvik_register_print; + reg_class->hash = (reg_hash_fc)g_dalvik_register_hash; + reg_class->compare = (reg_compare_fc)g_dalvik_register_compare; + reg_class->print = (reg_print_fc)g_dalvik_register_print; + reg_class->unserialize = (reg_unserialize_fc)g_dalvik_register_unserialize; + reg_class->serialize = (reg_serialize_fc)g_dalvik_register_serialize; } @@ -261,7 +274,7 @@ static void g_dalvik_register_print(const GDalvikRegister *reg, GBufferLine *lin * * ******************************************************************************/ -static GDalvikRegister *_g_dalvik_register_new(uint16_t index) +static GArchRegister *_g_dalvik_register_new(uint16_t index) { GDalvikRegister *result; /* Structure à retourner */ @@ -269,7 +282,7 @@ static GDalvikRegister *_g_dalvik_register_new(uint16_t index) result->index = index; - return result; + return G_ARCH_REGISTER(result); } @@ -286,9 +299,9 @@ static GDalvikRegister *_g_dalvik_register_new(uint16_t index) * * ******************************************************************************/ -GDalvikRegister *g_dalvik_register_new(uint16_t index) +GArchRegister *g_dalvik_register_new(uint16_t index) { - GDalvikRegister *result; /* Structure à retourner */ + GArchRegister *result; /* Structure à retourner */ result = get_dalvik_register(index); @@ -342,6 +355,97 @@ int g_dalvik_register_compare(const GDalvikRegister *a, const GDalvikRegister *b /* ---------------------------------------------------------------------------------- */ +/* TRANSPOSITIONS VIA CACHE DES OPERANDES */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : reg = registre d'architecture à constituer. * +* storage = mécanisme de sauvegarde à manipuler. * +* pbuf = zone tampon à remplir. * +* * +* Description : Charge un registre depuis une mémoire tampon. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GArchRegister *g_dalvik_register_unserialize(GDalvikRegister *reg, GAsmStorage *storage, packed_buffer *pbuf) +{ + GArchRegister *result; /* Instance à retourner */ + uint16_t index; /* Indice du registre */ + bool status; /* Bilan d'une extraction */ + GArchRegisterClass *parent; /* Classe parente à consulter */ + + status = extract_packed_buffer(pbuf, &index, sizeof(uint16_t), true); + + if (status) + { + result = get_dalvik_register(index); + + if (result == NULL) + g_object_unref(G_OBJECT(reg)); + + } + + else + { + g_object_unref(G_OBJECT(reg)); + result = NULL; + } + + if (result != NULL) + { + parent = G_ARCH_REGISTER_CLASS(g_dalvik_register_parent_class); + + result = parent->unserialize(result, storage, pbuf); + + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : reg = registre d'architecture à consulter. * +* storage = mécanisme de sauvegarde à manipuler. * +* pbuf = zone tampon à remplir. * +* * +* Description : Sauvegarde un registre dans une mémoire tampon. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool g_dalvik_register_serialize(const GDalvikRegister *reg, GAsmStorage *storage, packed_buffer *pbuf) +{ + bool result; /* Bilan à retourner */ + GArchRegisterClass *parent; /* Classe parente à consulter */ + + result = extend_packed_buffer(pbuf, ®->index, sizeof(uint16_t), true); + + if (result) + { + parent = G_ARCH_REGISTER_CLASS(g_dalvik_register_parent_class); + + result = parent->serialize(G_ARCH_REGISTER(reg), storage, pbuf); + + } + + return result; + +} + + + +/* ---------------------------------------------------------------------------------- */ /* GESTION SOUS FORME DE SINGLETONS */ /* ---------------------------------------------------------------------------------- */ @@ -358,9 +462,9 @@ int g_dalvik_register_compare(const GDalvikRegister *a, const GDalvikRegister *b * * ******************************************************************************/ -static GDalvikRegister *get_dalvik_register(uint16_t index) +static GArchRegister *get_dalvik_register(uint16_t index) { - GDalvikRegister *result; /* Structure à retourner */ + GArchRegister *result; /* Structure à retourner */ size_t new_count; /* Nouvelle taille à considérer*/ size_t i; /* Boucle de parcours */ @@ -370,7 +474,7 @@ static GDalvikRegister *get_dalvik_register(uint16_t index) { new_count = index + 1; - _dalvik_registers = realloc(_dalvik_registers, new_count * sizeof(GDalvikRegister *)); + _dalvik_registers = realloc(_dalvik_registers, new_count * sizeof(GArchRegister *)); for (i = _dreg_count; i < new_count; i++) _dalvik_registers[i] = NULL; diff --git a/plugins/dalvik/register.h b/plugins/dalvik/register.h index 42206c8..fa3f2ab 100644 --- a/plugins/dalvik/register.h +++ b/plugins/dalvik/register.h @@ -29,6 +29,9 @@ #include <stdint.h> +#include <arch/register.h> + + /* ------------------------- GESTION UNITAIRE DES REGISTRES ------------------------- */ @@ -52,7 +55,7 @@ typedef struct _GDalvikRegisterClass GDalvikRegisterClass; GType g_dalvik_register_get_type(void); /* Crée une réprésentation de registre Dalvik. */ -GDalvikRegister *g_dalvik_register_new(uint16_t); +GArchRegister *g_dalvik_register_new(uint16_t); /* Fournit l'indice d'un registre Dalvik. */ uint16_t g_dalvik_register_get_index(const GDalvikRegister *); |