summaryrefslogtreecommitdiff
path: root/src/arch/dalvik/operands/pool.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2016-12-18 15:32:27 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2016-12-18 15:32:27 (GMT)
commitb0bcf250999b2242019f137e38f52390a86e71cd (patch)
treef3436a3ddbbd4773005ecb891630a815ed001341 /src/arch/dalvik/operands/pool.c
parent6bde4016160057a22234d4ed698903dca52ce162 (diff)
Shared all Dalvik operands between all their users.
Diffstat (limited to 'src/arch/dalvik/operands/pool.c')
-rw-r--r--src/arch/dalvik/operands/pool.c194
1 files changed, 185 insertions, 9 deletions
diff --git a/src/arch/dalvik/operands/pool.c b/src/arch/dalvik/operands/pool.c
index e737a0b..4884867 100644
--- a/src/arch/dalvik/operands/pool.c
+++ b/src/arch/dalvik/operands/pool.c
@@ -32,10 +32,14 @@
#include "../../operand-int.h"
+#include "../../sharing/manager.h"
#include "../../../format/dex/pool.h"
+/* --------------------- MANIPULATION D'OPERANDES INDIVIDUELLES --------------------- */
+
+
/* Définition d'un opérande visant un élément de table de constantes Dalvik (instance) */
struct _GDalvikPoolOperand
{
@@ -68,11 +72,33 @@ static void g_dalvik_pool_operand_dispose(GDalvikPoolOperand *);
/* Procède à la libération totale de la mémoire. */
static void g_dalvik_pool_operand_finalize(GDalvikPoolOperand *);
+/* Initialise un nouvel objet partagé avec des informations. */
+static bool g_dalvik_pool_operand_do_init(GDalvikPoolOperand *, const GDalvikPoolOperand *);
+
+/* Indique l'objet partagé correspond à une description donnée. */
+static gboolean g_dalvik_pool_operand_compare_info(const GDalvikPoolOperand *, const GDalvikPoolOperand *);
+
+/* Compare un opérande avec un autre. */
+static bool g_dalvik_pool_operand_compare(const GDalvikPoolOperand *, const GDalvikPoolOperand *);
+
/* Traduit un opérande en version humainement lisible. */
static void g_dalvik_pool_operand_print(const GDalvikPoolOperand *, GBufferLine *, AsmSyntax);
+/* -------------------------- PARTAGES DE CONTENUS UNIQUES -------------------------- */
+
+
+/* Gestionnaire des partages d'instances */
+static GShareManager *_dalvik_pool_operand_manager = NULL;
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* MANIPULATION D'OPERANDES INDIVIDUELLES */
+/* ---------------------------------------------------------------------------------- */
+
+
/* Indique le type défini par la GLib pour un un élément de table de constantes Dalvik. */
G_DEFINE_TYPE(GDalvikPoolOperand, g_dalvik_pool_operand, G_TYPE_ARCH_OPERAND);
@@ -95,11 +121,16 @@ static void g_dalvik_pool_operand_class_init(GDalvikPoolOperandClass *klass)
GArchOperandClass *operand; /* Version de classe parente */
object = G_OBJECT_CLASS(klass);
- operand = G_ARCH_OPERAND_CLASS(klass);
object->dispose = (GObjectFinalizeFunc/* ! */)g_dalvik_pool_operand_dispose;
object->finalize = (GObjectFinalizeFunc)g_dalvik_pool_operand_finalize;
+ operand = G_ARCH_OPERAND_CLASS(klass);
+
+ operand->init = (init_shared_fc)g_dalvik_pool_operand_do_init;
+ operand->cmp_info = (compare_shared_info_fc)g_dalvik_pool_operand_compare_info;
+
+ operand->compare = (operand_compare_fc)g_dalvik_pool_operand_compare;
operand->print = (operand_print_fc)g_dalvik_pool_operand_print;
}
@@ -182,10 +213,13 @@ static void g_dalvik_pool_operand_finalize(GDalvikPoolOperand *operand)
GArchOperand *g_dalvik_pool_operand_new(GDexFormat *format, DalvikPoolType type, const GBinContent *content, vmpa2t *pos, MemoryDataSize size, SourceEndian endian)
{
- GDalvikPoolOperand *result; /* Structure à retourner */
+ GArchOperand *result; /* Structure à retourner */
uint8_t index8; /* Indice sur 8 bits */
uint16_t index16; /* Indice sur 16 bits */
bool test; /* Bilan de lecture */
+ GDalvikPoolOperand fake; /* Transport d'informations */
+
+ result = NULL;
switch (size)
{
@@ -201,17 +235,93 @@ GArchOperand *g_dalvik_pool_operand_new(GDexFormat *format, DalvikPoolType type,
}
if (!test)
- return NULL;
+ goto gdpon_exit;
+
+ fake.format = format;
+ fake.type = type;
+ fake.index = (size == MDS_8_BITS ? index8 : index16);
+
+ result = G_ARCH_OPERAND(g_share_manager_get(_dalvik_pool_operand_manager, &fake));
+
+ gdpon_exit:
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = objet partagé à initialiser. *
+* fake = coquille vide contenant les infos à enregistrer. *
+* *
+* Description : Initialise un nouvel objet partagé avec des informations. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_dalvik_pool_operand_do_init(GDalvikPoolOperand *operand, const GDalvikPoolOperand *fake)
+{
+ operand->format = fake->format;
+ g_object_ref(G_OBJECT(fake->format));
+
+ operand->type = fake->type;
+ operand->index = fake->index;
+
+ return true;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = objet partagé à consulter. *
+* fake = coquille vide contenant les infos à comparer. *
+* *
+* Description : Indique l'objet partagé correspond à une description donnée. *
+* *
+* Retour : TRUE si les détails centraux sont partagés, FALSE sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static gboolean g_dalvik_pool_operand_compare_info(const GDalvikPoolOperand *operand, const GDalvikPoolOperand *fake)
+{
+ gboolean result; /* Bilan à retourner */
+
+ result = g_dalvik_pool_operand_compare(operand, fake);
+
+ return result;
+
+}
+
- result = g_object_new(G_TYPE_DALVIK_POOL_OPERAND, NULL);
+/******************************************************************************
+* *
+* 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 : - *
+* *
+******************************************************************************/
- g_object_ref(G_OBJECT(format));
+static bool g_dalvik_pool_operand_compare(const GDalvikPoolOperand *a, const GDalvikPoolOperand *b)
+{
+ bool result; /* Bilan à renvoyer */
- result->format = format;
- result->type = type;
- result->index = (size == MDS_8_BITS ? index8 : index16);
+ result = (a->format == b->format);
+ result &= (a->type == b->type);
+ result &= (a->index == b->index);
- return G_ARCH_OPERAND(result);
+ return result;
}
@@ -413,3 +523,69 @@ uint32_t g_dalvik_pool_operand_get_index(const GDalvikPoolOperand *operand)
return operand->index;
}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* PARTAGES DE CONTENUS UNIQUES */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Met en place les mécanismes de partage des opérandes Dalvik. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool init_dalvik_pool_operand_sharing(void)
+{
+ _dalvik_pool_operand_manager = g_share_manager_new(G_TYPE_DALVIK_POOL_OPERAND);
+
+ return true;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Imprime des statistiques quant aux partages dans l'archi. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+#ifdef DEBUG_DUMP_STATS
+void dump_dalvik_pool_operand_share_stats(void)
+{
+ g_share_manager_dump_stats(_dalvik_pool_operand_manager);
+
+}
+#endif
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Supprime les mécanismes de partage des opérandes Dalvik. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void exit_dalvik_pool_operand_sharing(void)
+{
+ g_object_unref(G_OBJECT(_dalvik_pool_operand_manager));
+
+}