diff options
Diffstat (limited to 'plugins/dalvik/operands/args.c')
-rw-r--r-- | plugins/dalvik/operands/args.c | 321 |
1 files changed, 191 insertions, 130 deletions
diff --git a/plugins/dalvik/operands/args.c b/plugins/dalvik/operands/args.c index 6387092..64f8eea 100644 --- a/plugins/dalvik/operands/args.c +++ b/plugins/dalvik/operands/args.c @@ -32,11 +32,14 @@ #include <arch/operand-int.h> #include <common/sort.h> +#include <core/columns.h> #include <core/logs.h> -#include <gtkext/gtkblockdisplay.h> +/* -------------------------- DEFINITION D'UN NOUVEAU TYPE -------------------------- */ + + /* Définition d'un opérande visant une liste d'opérandes Dalvik (instance) */ struct _GDalvikArgsOperand { @@ -68,8 +71,13 @@ static void g_dalvik_args_operand_dispose(GDalvikArgsOperand *); /* Procède à la libération totale de la mémoire. */ static void g_dalvik_args_operand_finalize(GDalvikArgsOperand *); + + +/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */ + + /* Compare un opérande avec un autre. */ -static int g_dalvik_args_operand_compare(const GDalvikArgsOperand *, const GDalvikArgsOperand *); +static int g_dalvik_args_operand_compare(const GDalvikArgsOperand *, const GDalvikArgsOperand *, bool); /* Détermine le chemin conduisant à un opérande interne. */ static char *g_dalvik_args_operand_find_inner_operand_path(const GDalvikArgsOperand *, const GArchOperand *); @@ -80,17 +88,20 @@ static GArchOperand *g_dalvik_args_operand_get_inner_operand_from_path(const GDa /* Traduit un opérande en version humainement lisible. */ static void g_dalvik_args_operand_print(const GDalvikArgsOperand *, GBufferLine *); +/* 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); -/* --------------------- TRANSPOSITIONS VIA CACHE DES OPERANDES --------------------- */ - +/* Fournit l'empreinte d'un candidat à une centralisation. */ +static guint g_dalvik_args_operand_hash(const GDalvikArgsOperand *, bool); -/* Charge un opérande depuis une mémoire tampon. */ -static bool g_dalvik_args_operand_unserialize(GDalvikArgsOperand *, GAsmStorage *, GBinFormat *, packed_buffer_t *); -/* Sauvegarde un opérande dans une mémoire tampon. */ -static bool g_dalvik_args_operand_serialize(const GDalvikArgsOperand *, GAsmStorage *, packed_buffer_t *); +/* ---------------------------------------------------------------------------------- */ +/* DEFINITION D'UN NOUVEAU TYPE */ +/* ---------------------------------------------------------------------------------- */ /* Indique le type défini par la GLib pour une liste d'arguments Dalvik. */ @@ -127,8 +138,12 @@ static void g_dalvik_args_operand_class_init(GDalvikArgsOperandClass *klass) operand->print = (operand_print_fc)g_dalvik_args_operand_print; - operand->unserialize = (unserialize_operand_fc)g_dalvik_args_operand_unserialize; - operand->serialize = (serialize_operand_fc)g_dalvik_args_operand_serialize; + 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->load = g_arch_operand_load_generic_variadic; + operand->store = g_arch_operand_store_generic_variadic; } @@ -170,7 +185,7 @@ static void g_dalvik_args_operand_dispose(GDalvikArgsOperand *operand) size_t i; for (i = 0; i < operand->count; i++) - g_object_unref(G_OBJECT(operand->args[i])); + g_clear_object(&operand->args[i]); G_OBJECT_CLASS(g_dalvik_args_operand_parent_class)->dispose(G_OBJECT(operand)); @@ -201,8 +216,102 @@ static void g_dalvik_args_operand_finalize(GDalvikArgsOperand *operand) /****************************************************************************** * * -* Paramètres : a = premier opérande à consulter. * -* b = second opérande à consulter. * +* Paramètres : - * +* * +* Description : Crée un réceptacle pour opérandes Dalvik servant d'arguments.* +* * +* Retour : Opérande mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArchOperand *g_dalvik_args_operand_new(void) +{ + GArchOperand *result; /* Structure à retourner */ + + result = g_object_new(G_TYPE_DALVIK_ARGS_OPERAND, NULL); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : operand = opérande à compléter. * +* arg = nouvel argument pour un appel. * +* * +* Description : Ajoute un élément à la liste d'arguments Dalvik. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_dalvik_args_operand_add(GDalvikArgsOperand *operand, GArchOperand *arg) +{ + operand->count++; + operand->args = realloc(operand->args, operand->count * sizeof(GArchOperand *)); + + operand->args[operand->count - 1] = arg; + +} + + +/****************************************************************************** +* * +* Paramètres : operand = opérande à compléter. * +* * +* Description : Fournit le nombre d'arguments pris en charge. * +* * +* Retour : Nombre positif ou nul. * +* * +* Remarques : - * +* * +******************************************************************************/ + +size_t g_dalvik_args_count(const GDalvikArgsOperand *operand) +{ + return operand->count; + +} + + +/****************************************************************************** +* * +* Paramètres : operand = opérande à compléter. * +* index = indice de l'argument recherché. * +* * +* Description : Founit un élément de la liste d'arguments Dalvik. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArchOperand *g_dalvik_args_operand_get(const GDalvikArgsOperand *operand, size_t index) +{ + assert(index < operand->count); + + return operand->args[index]; + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* IMPLEMENTATION DES FONCTIONS DE CLASSE */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : a = premier opérande à consulter. * +* b = second opérande à consulter. * +* lock = précise le besoin en verrouillage. * * * * Description : Compare un opérande avec un autre. * * * @@ -212,10 +321,13 @@ static void g_dalvik_args_operand_finalize(GDalvikArgsOperand *operand) * * ******************************************************************************/ -static int g_dalvik_args_operand_compare(const GDalvikArgsOperand *a, const GDalvikArgsOperand *b) +static int g_dalvik_args_operand_compare(const GDalvikArgsOperand *a, const GDalvikArgsOperand *b, bool lock) { int result; /* Bilan à renvoyer */ + operand_extra_data_t *ea; /* Données insérées à consulter*/ + operand_extra_data_t *eb; /* Données insérées à consulter*/ size_t i; /* Boucle de parcours */ + GArchOperandClass *class; /* Classe parente normalisée */ /* Création de l'objet... */ if (b == NULL) @@ -223,11 +335,32 @@ static int g_dalvik_args_operand_compare(const GDalvikArgsOperand *a, const GDal else { + ea = GET_ARCH_OP_EXTRA(G_ARCH_OPERAND(a)); + eb = GET_ARCH_OP_EXTRA(G_ARCH_OPERAND(b)); + + if (lock) + { + LOCK_GOBJECT_EXTRA(ea); + LOCK_GOBJECT_EXTRA(eb); + } + result = sort_unsigned_long(a->count, b->count); for (i = 0; i < a->count && result == 0; i++) result = g_arch_operand_compare(a->args[i], b->args[i]); + if (result == 0) + { + class = G_ARCH_OPERAND_CLASS(g_dalvik_args_operand_parent_class); + result = class->compare(G_ARCH_OPERAND(a), G_ARCH_OPERAND(b), false); + } + + if (lock) + { + UNLOCK_GOBJECT_EXTRA(eb); + UNLOCK_GOBJECT_EXTRA(ea); + } + } return result; @@ -398,75 +531,44 @@ static void g_dalvik_args_operand_print(const GDalvikArgsOperand *operand, GBuff /****************************************************************************** * * -* Paramètres : - * +* Paramètres : operand = objet dont l'instance se veut unique. * +* count = quantité d'instances à l'unicité internes. * * * -* Description : Crée un réceptacle pour opérandes Dalvik servant d'arguments.* +* Description : Fournit une liste de candidats embarqués par un candidat. * * * -* Retour : Opérande mis en place. * +* Retour : Liste de candidats internes ou NULL si aucun. * * * * Remarques : - * * * ******************************************************************************/ -GArchOperand *g_dalvik_args_operand_new(void) +static GArchOperand **g_dalvik_args_operand_list_inner_instances(const GDalvikArgsOperand *operand, size_t *count) { - GArchOperand *result; /* Structure à retourner */ - - result = g_object_new(G_TYPE_DALVIK_ARGS_OPERAND, NULL); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : operand = opérande à compléter. * -* arg = nouvel argument pour un appel. * -* * -* Description : Ajoute un élément à la liste d'arguments Dalvik. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void g_dalvik_args_operand_add(GDalvikArgsOperand *operand, GArchOperand *arg) -{ - operand->count++; - operand->args = (GArchOperand **)realloc(operand->args, operand->count * sizeof(GArchOperand *)); - - operand->args[operand->count - 1] = arg; + GArchOperand **result; /* Instances à retourner */ + size_t i; /* Boucle de parcours */ -} + *count = operand->count; + result = malloc(*count * sizeof(GArchOperand *)); -/****************************************************************************** -* * -* Paramètres : operand = opérande à compléter. * -* * -* Description : Fournit le nombre d'arguments pris en charge. * -* * -* Retour : Nombre positif ou nul. * -* * -* Remarques : - * -* * -******************************************************************************/ + for (i = 0; i < *count; i++) + { + result[i] = operand->args[i]; + g_object_ref(G_OBJECT(result[i])); + } -size_t g_dalvik_args_count(const GDalvikArgsOperand *operand) -{ - return operand->count; + return result; } /****************************************************************************** * * -* Paramètres : operand = opérande à compléter. * -* index = indice de l'argument recherché. * +* 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 : Founit un élément de la liste d'arguments Dalvik. * +* Description : Met à jour une liste de candidats embarqués par un candidat. * * * * Retour : - * * * @@ -474,97 +576,56 @@ size_t g_dalvik_args_count(const GDalvikArgsOperand *operand) * * ******************************************************************************/ -GArchOperand *g_dalvik_args_operand_get(const GDalvikArgsOperand *operand, size_t index) +static void g_dalvik_args_operand_update_inner_instances(GDalvikArgsOperand *operand, GArchOperand **instances, size_t count) { - assert(index < operand->count); - - return operand->args[index]; - -} - - - -/* ---------------------------------------------------------------------------------- */ -/* 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_args_operand_unserialize(GDalvikArgsOperand *operand, GAsmStorage *storage, GBinFormat *format, packed_buffer_t *pbuf) -{ - bool result; /* Bilan à retourner */ - GArchOperandClass *parent; /* Classe parente à consulter */ - size_t count; /* Nombre d'opérandes à charger*/ size_t i; /* Boucle de parcours */ - GArchOperand *arg; /* Nouvel argument à intégrer */ - parent = G_ARCH_OPERAND_CLASS(g_dalvik_args_operand_parent_class); - - result = parent->unserialize(G_ARCH_OPERAND(operand), storage, format, pbuf); + for (i = 0; i < count; i++) + g_object_unref(G_OBJECT(operand->args[i])); - if (result) - result = extract_packed_buffer(pbuf, &count, sizeof(size_t), true); + operand->count = count; + operand->args = realloc(operand->args, operand->count * sizeof(GArchOperand *)); - for (i = 0; i < count && result; i++) + for (i = 0; i < count; i++) { - arg = g_arch_operand_load(storage, format, pbuf); - - if (arg == NULL) - result = false; - - else - g_dalvik_args_operand_add(operand, arg); - + operand->args[i] = instances[i]; + g_object_ref(G_OBJECT(instances[i])); } - return result; - } /****************************************************************************** * * -* Paramètres : operand = opérande d'assemblage à consulter. * -* storage = mécanisme de sauvegarde à manipuler. * -* pbuf = zone tampon à remplir. * +* Paramètres : operand = objet dont l'instance se veut unique. * +* lock = précise le besoin en verrouillage. * * * -* Description : Sauvegarde un opérande dans une mémoire tampon. * +* Description : Fournit l'empreinte d'un candidat à une centralisation. * * * -* Retour : Bilan de l'opération. * +* Retour : Empreinte de l'élément représenté. * * * * Remarques : - * * * ******************************************************************************/ -static bool g_dalvik_args_operand_serialize(const GDalvikArgsOperand *operand, GAsmStorage *storage, packed_buffer_t *pbuf) +static guint g_dalvik_args_operand_hash(const GDalvikArgsOperand *operand, bool lock) { - bool result; /* Bilan à retourner */ - GArchOperandClass *parent; /* Classe parente à consulter */ - size_t i; /* Boucle de parcours */ + guint result; /* Valeur à retourner */ + operand_extra_data_t *extra; /* Données insérées à consulter*/ + GArchOperandClass *class; /* Classe parente normalisée */ + + extra = GET_ARCH_OP_EXTRA(G_ARCH_OPERAND(operand)); - parent = G_ARCH_OPERAND_CLASS(g_dalvik_args_operand_parent_class); + if (lock) + LOCK_GOBJECT_EXTRA(extra); - result = parent->serialize(G_ARCH_OPERAND(operand), storage, pbuf); + class = G_ARCH_OPERAND_CLASS(g_dalvik_args_operand_parent_class); + result = class->hash(G_ARCH_OPERAND(operand), false); - if (result) - result = extend_packed_buffer(pbuf, &operand->count, sizeof(size_t), true); + result ^= operand->count; - for (i = 0; i < operand->count && result; i++) - result = g_arch_operand_store(operand->args[i], storage, pbuf); + if (lock) + UNLOCK_GOBJECT_EXTRA(extra); return result; |