summaryrefslogtreecommitdiff
path: root/src/arch/dalvik/operands/pool.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/dalvik/operands/pool.c')
-rw-r--r--src/arch/dalvik/operands/pool.c172
1 files changed, 109 insertions, 63 deletions
diff --git a/src/arch/dalvik/operands/pool.c b/src/arch/dalvik/operands/pool.c
index fa7ed54..d97c93b 100644
--- a/src/arch/dalvik/operands/pool.c
+++ b/src/arch/dalvik/operands/pool.c
@@ -74,10 +74,13 @@ static void g_dalvik_pool_operand_dispose(GDalvikPoolOperand *);
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 *);
+static bool g_dalvik_pool_operand_apply_template(GDalvikPoolOperand *, const GDalvikPoolOperand *);
+
+/* Réalise une copie minimale d'un contenu partagé. */
+static void g_dalvik_pool_operand_define_template(const GDalvikPoolOperand *, GDalvikPoolOperand *);
/* Compare un opérande avec un autre. */
-static int g_dalvik_pool_operand_compare(const GDalvikPoolOperand * const *, const GDalvikPoolOperand * const *);
+static int 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);
@@ -91,6 +94,10 @@ static void g_dalvik_pool_operand_print(const GDalvikPoolOperand *, GBufferLine
static GShareManager *_dalvik_pool_operand_manager = NULL;
+/* Fournit le gestionnaire de partages attribué à un type. */
+static GShareManager *get_dalvik_pool_operand_share_manager(void);
+
+
/* ---------------------------------------------------------------------------------- */
/* MANIPULATION D'OPERANDES INDIVIDUELLES */
@@ -125,7 +132,11 @@ static void g_dalvik_pool_operand_class_init(GDalvikPoolOperandClass *klass)
operand = G_ARCH_OPERAND_CLASS(klass);
- operand->init = (operand_do_init_fc)g_dalvik_pool_operand_do_init;
+ operand->get_manager = (get_operand_manager_fc)get_dalvik_pool_operand_share_manager;
+
+ operand->apply_template = (apply_operand_template_fc)g_dalvik_pool_operand_apply_template;
+ operand->define_template = (define_operand_template_fc)g_dalvik_pool_operand_define_template;
+ operand->free_template = (free_operand_template_fc)NULL;
operand->compare = (operand_compare_fc)g_dalvik_pool_operand_compare;
operand->print = (operand_print_fc)g_dalvik_pool_operand_print;
@@ -193,82 +204,47 @@ static void g_dalvik_pool_operand_finalize(GDalvikPoolOperand *operand)
/******************************************************************************
* *
-* Paramètres : format = format du fichier contenant le code. *
-* type = type de table visée avec la référence. *
-* content = flux de données à analyser. *
-* pos = position courante dans ce flux. [OUT] *
-* size = taille de l'opérande, et donc du registre. *
-* endian = ordre des bits dans la source. *
+* Paramètres : operand = objet partagé à initialiser. *
+* template = information à utiliser pour la mise en place. *
* *
-* Description : Crée un opérande visant un élément constant Dalvik. *
+* Description : Initialise un nouvel objet partagé avec des informations. *
* *
-* Retour : Opérande mis en place. *
+* Retour : Bilan de l'opération. *
* *
* Remarques : - *
* *
******************************************************************************/
-GArchOperand *g_dalvik_pool_operand_new(GDexFormat *format, DalvikPoolType type, const GBinContent *content, vmpa2t *pos, MemoryDataSize size, SourceEndian endian)
+static bool g_dalvik_pool_operand_apply_template(GDalvikPoolOperand *operand, const GDalvikPoolOperand *template)
{
- 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 */
+ g_dalvik_pool_operand_define_template(template, operand);
- result = NULL;
+ g_object_ref(G_OBJECT(operand->format));
- switch (size)
- {
- case MDS_8_BITS:
- test = g_binary_content_read_u8(content, pos, &index8);
- break;
- case MDS_16_BITS:
- test = g_binary_content_read_u16(content, pos, endian, &index16);
- break;
- default:
- test = false;
- break;
- }
-
- if (!test)
- 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, (GSharedInstance *)&fake));
-
- gdpon_exit:
-
- return result;
+ return true;
}
/******************************************************************************
* *
-* Paramètres : operand = objet partagé à initialiser. *
-* fake = coquille vide contenant les infos à enregistrer. *
+* Paramètres : operand = objet partagé à consulter. *
+* template = informations à retrouver intégralement. *
* *
-* Description : Initialise un nouvel objet partagé avec des informations. *
+* Description : Réalise une copie minimale d'un contenu partagé. *
* *
-* Retour : Bilan de l'opération. *
+* Retour : - *
* *
* Remarques : - *
* *
******************************************************************************/
-static bool g_dalvik_pool_operand_do_init(GDalvikPoolOperand *operand, const GDalvikPoolOperand *fake)
+static void g_dalvik_pool_operand_define_template(const GDalvikPoolOperand *operand, GDalvikPoolOperand *template)
{
- operand->format = fake->format;
- g_object_ref(G_OBJECT(fake->format));
-
- operand->type = fake->type;
- operand->index = fake->index;
+ template->format = operand->format;
- return true;
+ template->type = operand->type;
+ template->index = operand->index;
}
@@ -286,22 +262,17 @@ static bool g_dalvik_pool_operand_do_init(GDalvikPoolOperand *operand, const GDa
* *
******************************************************************************/
-static int g_dalvik_pool_operand_compare(const GDalvikPoolOperand * const *a, const GDalvikPoolOperand * const *b)
+static int g_dalvik_pool_operand_compare(const GDalvikPoolOperand *a, const GDalvikPoolOperand *b)
{
int result; /* Bilan à renvoyer */
- const GDalvikPoolOperand *_a; /* Accès rapide à l'élément A */
- const GDalvikPoolOperand *_b; /* Accès rapide à l'élément B */
-
- _a = *a;
- _b = *b;
- result = sort_unsigned_long((unsigned long)_a->format, (unsigned long)_b->format);
+ result = sort_unsigned_long((unsigned long)a->format, (unsigned long)b->format);
if (result == 0)
- result = sort_unsigned_long(_a->type, _b->type);
+ result = sort_unsigned_long(a->type, b->type);
if (result == 0)
- result = sort_unsigned_long(_a->index, _b->index);
+ result = sort_unsigned_long(a->index, b->index);
return result;
@@ -471,6 +442,62 @@ static void g_dalvik_pool_operand_print(const GDalvikPoolOperand *operand, GBuff
/******************************************************************************
* *
+* Paramètres : format = format du fichier contenant le code. *
+* type = type de table visée avec la référence. *
+* content = flux de données à analyser. *
+* pos = position courante dans ce flux. [OUT] *
+* size = taille de l'opérande, et donc du registre. *
+* endian = ordre des bits dans la source. *
+* *
+* Description : Crée un opérande visant un élément constant Dalvik. *
+* *
+* Retour : Opérande mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchOperand *g_dalvik_pool_operand_new(GDexFormat *format, DalvikPoolType type, const GBinContent *content, vmpa2t *pos, MemoryDataSize size, SourceEndian endian)
+{
+ 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)
+ {
+ case MDS_8_BITS:
+ test = g_binary_content_read_u8(content, pos, &index8);
+ break;
+ case MDS_16_BITS:
+ test = g_binary_content_read_u16(content, pos, endian, &index16);
+ break;
+ default:
+ test = false;
+ break;
+ }
+
+ if (!test)
+ goto gdpon_exit;
+
+ fake.format = format;
+ fake.type = type;
+ fake.index = (size == MDS_8_BITS ? index8 : index16);
+
+ result = G_ARCH_OPERAND(g_share_manager_build(_dalvik_pool_operand_manager, (GSharedInstance *)&fake));
+
+ gdpon_exit:
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : operand = opérande à consulter. *
* *
* Description : Indique la nature de la table de constantes visée ici. *
@@ -517,6 +544,25 @@ uint32_t g_dalvik_pool_operand_get_index(const GDalvikPoolOperand *operand)
* *
* Paramètres : - *
* *
+* Description : Fournit le gestionnaire de partages attribué à un type. *
+* *
+* Retour : Gestionnaire de partages en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GShareManager *get_dalvik_pool_operand_share_manager(void)
+{
+ return _dalvik_pool_operand_manager;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
* Description : Met en place les mécanismes de partage des opérandes Dalvik. *
* *
* Retour : Bilan de l'opération. *