diff options
Diffstat (limited to 'plugins/dalvik/operands/args.c')
-rw-r--r-- | plugins/dalvik/operands/args.c | 108 |
1 files changed, 107 insertions, 1 deletions
diff --git a/plugins/dalvik/operands/args.c b/plugins/dalvik/operands/args.c index f35a11f..5224567 100644 --- a/plugins/dalvik/operands/args.c +++ b/plugins/dalvik/operands/args.c @@ -72,6 +72,17 @@ static void g_dalvik_args_operand_print(const GDalvikArgsOperand *, GBufferLine +/* --------------------- TRANSPOSITIONS VIA CACHE DES OPERANDES --------------------- */ + + +/* Charge un opérande depuis une mémoire tampon. */ +static bool g_dalvik_args_operand_unserialize(GDalvikArgsOperand *, GAsmStorage *, GBinFormat *, packed_buffer *); + +/* Sauvegarde un opérande dans une mémoire tampon. */ +static bool g_dalvik_args_operand_serialize(const GDalvikArgsOperand *, GAsmStorage *, packed_buffer *); + + + /* Indique le type défini par la GLib pour une liste d'arguments Dalvik. */ G_DEFINE_TYPE(GDalvikArgsOperand, g_dalvik_args_operand, G_TYPE_ARCH_OPERAND); @@ -102,6 +113,9 @@ static void g_dalvik_args_operand_class_init(GDalvikArgsOperandClass *klass) operand->compare = (operand_compare_fc)g_dalvik_args_operand_compare; 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; + } @@ -119,6 +133,8 @@ static void g_dalvik_args_operand_class_init(GDalvikArgsOperandClass *klass) static void g_dalvik_args_operand_init(GDalvikArgsOperand *operand) { + operand->args = NULL; + operand->count = 0; } @@ -161,6 +177,9 @@ static void g_dalvik_args_operand_dispose(GDalvikArgsOperand *operand) static void g_dalvik_args_operand_finalize(GDalvikArgsOperand *operand) { + if (operand->args != NULL) + free(operand->args); + G_OBJECT_CLASS(g_dalvik_args_operand_parent_class)->finalize(G_OBJECT(operand)); } @@ -280,7 +299,6 @@ GArchOperand *g_dalvik_args_operand_new(void) void g_dalvik_args_operand_add(GDalvikArgsOperand *operand, GArchOperand *arg) { - operand->count++; operand->args = (GArchOperand **)realloc(operand->args, operand->count * sizeof(GArchOperand *)); @@ -328,3 +346,91 @@ GArchOperand *g_dalvik_args_operand_get(const GDalvikArgsOperand *operand, size_ 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 *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); + + if (result) + result = extract_packed_buffer(pbuf, &count, sizeof(size_t), true); + + for (i = 0; i < count && result; i++) + { + arg = g_arch_operand_load(storage, format, pbuf); + + if (arg == NULL) + result = false; + + else + g_dalvik_args_operand_add(operand, arg); + + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : operand = opérande d'assemblage à consulter. * +* storage = mécanisme de sauvegarde à manipuler. * +* pbuf = zone tampon à remplir. * +* * +* Description : Sauvegarde un opérande dans une mémoire tampon. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool g_dalvik_args_operand_serialize(const GDalvikArgsOperand *operand, GAsmStorage *storage, packed_buffer *pbuf) +{ + bool result; /* Bilan à retourner */ + GArchOperandClass *parent; /* Classe parente à consulter */ + size_t i; /* Boucle de parcours */ + + parent = G_ARCH_OPERAND_CLASS(g_dalvik_args_operand_parent_class); + + result = parent->serialize(G_ARCH_OPERAND(operand), storage, pbuf); + + if (result) + result = extend_packed_buffer(pbuf, &operand->count, sizeof(size_t), true); + + for (i = 0; i < operand->count && result; i++) + result = g_arch_operand_store(operand->args[i], storage, pbuf); + + return result; + +} |