summaryrefslogtreecommitdiff
path: root/plugins/dalvik/register.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-05-28 17:37:46 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-05-28 17:37:46 (GMT)
commit9f5ed46de568d3db882c939c8ca9d0117bff3369 (patch)
tree9d2090cd640e54379dc1b982e03dc284b2d23ae7 /plugins/dalvik/register.c
parent2fd186a84cba4f39f6f1bb8bd34d52b4e1d4f814 (diff)
Relied on register objects as often as possible.
Diffstat (limited to 'plugins/dalvik/register.c')
-rw-r--r--plugins/dalvik/register.c134
1 files changed, 119 insertions, 15 deletions
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, &reg->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;