From 35f435585638fdf74377c3a9c7e7c2413995d4a7 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Tue, 10 Aug 2021 23:55:57 +0200 Subject: Prepare all Dalvik operands for a singleton status. --- plugins/dalvik/operands/args.c | 112 +++++++++++++++++++++++++++++++++++++++++ plugins/dalvik/operands/pool.c | 53 +++++++++++++++++++ src/arch/operands/immediate.c | 6 +-- src/arch/operands/register.c | 50 +++++++++++++++++- 4 files changed, 216 insertions(+), 5 deletions(-) diff --git a/plugins/dalvik/operands/args.c b/plugins/dalvik/operands/args.c index 6387092..2c7bc57 100644 --- a/plugins/dalvik/operands/args.c +++ b/plugins/dalvik/operands/args.c @@ -82,6 +82,20 @@ static void g_dalvik_args_operand_print(const GDalvikArgsOperand *, GBufferLine +/* ------------------------ CONTROLE DU VOLUME DES INSTANCES ------------------------ */ + + +/* Fournit une liste de candidats embarqués par un candidat. */ +static GArchOperand **g_dalvik_args_operand_list_inner_instances(const GDalvikArgsOperand *, size_t *); + +/* Met à jour une liste de candidats embarqués par un candidat. */ +static void g_dalvik_args_operand_update_inner_instances(GDalvikArgsOperand *, GArchOperand **, size_t); + +/* Fournit l'empreinte d'un candidat à une centralisation. */ +static guint g_dalvik_args_operand_hash(const GDalvikArgsOperand *); + + + /* --------------------- TRANSPOSITIONS VIA CACHE DES OPERANDES --------------------- */ @@ -127,6 +141,10 @@ static void g_dalvik_args_operand_class_init(GDalvikArgsOperandClass *klass) operand->print = (operand_print_fc)g_dalvik_args_operand_print; + operand->list_inner = (operand_list_inners_fc)g_dalvik_args_operand_list_inner_instances; + operand->update_inner = (operand_update_inners_fc)g_dalvik_args_operand_update_inner_instances; + operand->hash = (operand_hash_fc)g_dalvik_args_operand_hash; + operand->unserialize = (unserialize_operand_fc)g_dalvik_args_operand_unserialize; operand->serialize = (serialize_operand_fc)g_dalvik_args_operand_serialize; @@ -485,6 +503,100 @@ GArchOperand *g_dalvik_args_operand_get(const GDalvikArgsOperand *operand, size_ /* ---------------------------------------------------------------------------------- */ +/* CONTROLE DU VOLUME DES INSTANCES */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : operand = objet dont l'instance se veut unique. * +* count = quantité d'instances à l'unicité internes. * +* * +* Description : Fournit une liste de candidats embarqués par un candidat. * +* * +* Retour : Liste de candidats internes ou NULL si aucun. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GArchOperand **g_dalvik_args_operand_list_inner_instances(const GDalvikArgsOperand *operand, size_t *count) +{ + GArchOperand **result; /* Instances à retourner */ + size_t i; /* Boucle de parcours */ + + *count = operand->count; + + result = malloc(*count * sizeof(GArchOperand *)); + + for (i = 0; i < *count; i++) + { + result[i] = operand->args[i]; + g_object_ref(G_OBJECT(result[i])); + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : operand = objet dont l'instance se veut unique. * +* instances = liste de candidats internes devenus singletons. * +* count = quantité d'instances à l'unicité internes. * +* * +* Description : Met à jour une liste de candidats embarqués par un candidat. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_dalvik_args_operand_update_inner_instances(GDalvikArgsOperand *operand, GArchOperand **instances, size_t count) +{ + size_t i; /* Boucle de parcours */ + + assert(count == operand->count); + + for (i = 0; i < count; i++) + { + g_object_unref(G_OBJECT(operand->args[i])); + + operand->args[i] = instances[i]; + g_object_ref(G_OBJECT(instances[i])); + + } + +} + + +/****************************************************************************** +* * +* Paramètres : operand = objet dont l'instance se veut unique. * +* * +* Description : Fournit l'empreinte d'un candidat à une centralisation. * +* * +* Retour : Empreinte de l'élément représenté. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static guint g_dalvik_args_operand_hash(const GDalvikArgsOperand *operand) +{ + guint result; /* Valeur à retourner */ + + result = operand->count; + + return result; + +} + + + +/* ---------------------------------------------------------------------------------- */ /* TRANSPOSITIONS VIA CACHE DES OPERANDES */ /* ---------------------------------------------------------------------------------- */ diff --git a/plugins/dalvik/operands/pool.c b/plugins/dalvik/operands/pool.c index 89bee99..baab1f6 100644 --- a/plugins/dalvik/operands/pool.c +++ b/plugins/dalvik/operands/pool.c @@ -82,6 +82,14 @@ static void g_dalvik_pool_operand_print(const GDalvikPoolOperand *, GBufferLine +/* ------------------------ CONTROLE DU VOLUME DES INSTANCES ------------------------ */ + + +/* Fournit l'empreinte d'un candidat à une centralisation. */ +static guint g_dalvik_pool_operand_hash(const GDalvikPoolOperand *); + + + /* --------------------- TRANSPOSITIONS VIA CACHE DES OPERANDES --------------------- */ @@ -133,6 +141,8 @@ static void g_dalvik_pool_operand_class_init(GDalvikPoolOperandClass *klass) operand->compare = (operand_compare_fc)g_dalvik_pool_operand_compare; operand->print = (operand_print_fc)g_dalvik_pool_operand_print; + operand->hash = (operand_hash_fc)g_dalvik_pool_operand_hash; + operand->unserialize = (unserialize_operand_fc)g_dalvik_pool_operand_unserialize; operand->serialize = (serialize_operand_fc)g_dalvik_pool_operand_serialize; @@ -530,6 +540,49 @@ uint32_t g_dalvik_pool_operand_get_index(const GDalvikPoolOperand *operand) /* ---------------------------------------------------------------------------------- */ +/* CONTROLE DU VOLUME DES INSTANCES */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : operand = objet dont l'instance se veut unique. * +* * +* Description : Fournit l'empreinte d'un candidat à une centralisation. * +* * +* Retour : Empreinte de l'élément représenté. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static guint g_dalvik_pool_operand_hash(const GDalvikPoolOperand *operand) +{ + guint result; /* Valeur à retourner */ + DalvikPoolType type; /* Type porté par l'opérande */ + uint32_t index; /* Indice de l'élément */ + + result = (unsigned int)(unsigned long)operand->format; + +#if __SIZEOF_INT__ != __SIZEOF_LONG__ + result ^= ((unsigned long)operand->format) >> 32; +#endif + + type = g_dalvik_pool_operand_get_pool_type(operand); + + result ^= type; + + index = g_dalvik_pool_operand_get_index(operand); + + result ^= index; + + return result; + +} + + + +/* ---------------------------------------------------------------------------------- */ /* TRANSPOSITIONS VIA CACHE DES OPERANDES */ /* ---------------------------------------------------------------------------------- */ diff --git a/src/arch/operands/immediate.c b/src/arch/operands/immediate.c index 6e6925c..ec81cfe 100644 --- a/src/arch/operands/immediate.c +++ b/src/arch/operands/immediate.c @@ -156,7 +156,7 @@ static void g_imm_operand_print(const GImmOperand *, GBufferLine *); static char *g_imm_operand_build_tooltip(const GImmOperand *, const GLoadedBinary *); /* Fournit l'empreinte d'un candidat à une centralisation. */ -static guint g_arch_operand_hash(const GImmOperand *); +static guint g_imm_operand_hash(const GImmOperand *); /* Charge un opérande depuis une mémoire tampon. */ static bool g_imm_operand_unserialize(GImmOperand *, GAsmStorage *, GBinFormat *, packed_buffer_t *); @@ -262,7 +262,7 @@ static void g_imm_operand_class_init(GImmOperandClass *klass) operand->print = (operand_print_fc)g_imm_operand_print; operand->build_tooltip = (operand_build_tooltip_fc)g_imm_operand_build_tooltip; - operand->hash = (operand_hash_fc)g_arch_operand_hash; + operand->hash = (operand_hash_fc)g_imm_operand_hash; operand->unserialize = (unserialize_operand_fc)g_imm_operand_unserialize; operand->serialize = (serialize_operand_fc)g_imm_operand_serialize; @@ -1588,7 +1588,7 @@ void g_imm_operand_as_uleb128(const GImmOperand *operand, uleb128_t *val) * * ******************************************************************************/ -static guint g_arch_operand_hash(const GImmOperand *operand) +static guint g_imm_operand_hash(const GImmOperand *operand) { guint result; /* Valeur à retourner */ diff --git a/src/arch/operands/register.c b/src/arch/operands/register.c index 9a6de17..e457158 100644 --- a/src/arch/operands/register.c +++ b/src/arch/operands/register.c @@ -52,6 +52,14 @@ static void g_register_operand_print(const GRegisterOperand *, GBufferLine *); +/* ------------------------ CONTROLE DU VOLUME DES INSTANCES ------------------------ */ + + +/* Fournit l'empreinte d'un candidat à une centralisation. */ +static guint g_register_operand_hash(const GRegisterOperand *); + + + /* --------------------- TRANSPOSITIONS VIA CACHE DES OPERANDES --------------------- */ @@ -100,6 +108,8 @@ static void g_register_operand_class_init(GRegisterOperandClass *klass) operand->compare = (operand_compare_fc)g_register_operand_compare; operand->print = (operand_print_fc)g_register_operand_print; + operand->hash = (operand_hash_fc)g_register_operand_hash; + operand->unserialize = (unserialize_operand_fc)g_register_operand_unserialize; operand->serialize = (serialize_operand_fc)g_register_operand_serialize; @@ -229,8 +239,7 @@ GArchRegister *g_register_operand_get_register(const GRegisterOperand *operand) result = operand->reg; - if (result != NULL) - g_object_ref(G_OBJECT(result)); + g_object_ref(G_OBJECT(result)); return result; @@ -296,6 +305,43 @@ bool g_register_operand_is_written(const GRegisterOperand *operand) /* ---------------------------------------------------------------------------------- */ +/* CONTROLE DU VOLUME DES INSTANCES */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : operand = objet dont l'instance se veut unique. * +* * +* Description : Fournit l'empreinte d'un candidat à une centralisation. * +* * +* Retour : Empreinte de l'élément représenté. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static guint g_register_operand_hash(const GRegisterOperand *operand) +{ + guint result; /* Valeur à retourner */ + GArchRegister *reg; /* Registre visé par l'opérande*/ + + reg = g_register_operand_get_register(operand); + + result = g_arch_register_hash(reg); + + g_object_unref(G_OBJECT(reg)); + + if (g_register_operand_is_written(operand)) + result ^= 1; + + return result; + +} + + + +/* ---------------------------------------------------------------------------------- */ /* TRANSPOSITIONS VIA CACHE DES OPERANDES */ /* ---------------------------------------------------------------------------------- */ -- cgit v0.11.2-87-g4458