summaryrefslogtreecommitdiff
path: root/plugins/dalvik
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2020-08-22 17:57:19 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2020-08-22 17:59:06 (GMT)
commitf94210f2617968774277078a8db9097c56029039 (patch)
treeb65eb802595a4496e931fe124010ad6f7b995272 /plugins/dalvik
parent1e4bc888ff02d21b8fe4a45c70298624f35e758a (diff)
Defined paths to access to the instruction operands.
Diffstat (limited to 'plugins/dalvik')
-rw-r--r--plugins/dalvik/operands/args.c137
1 files changed, 136 insertions, 1 deletions
diff --git a/plugins/dalvik/operands/args.c b/plugins/dalvik/operands/args.c
index a536e8c..4b87e5e 100644
--- a/plugins/dalvik/operands/args.c
+++ b/plugins/dalvik/operands/args.c
@@ -26,10 +26,13 @@
#include <assert.h>
#include <malloc.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <arch/operand-int.h>
#include <common/sort.h>
+#include <core/logs.h>
#include <gtkext/gtkblockdisplay.h>
@@ -68,6 +71,12 @@ static void g_dalvik_args_operand_finalize(GDalvikArgsOperand *);
/* Compare un opérande avec un autre. */
static int g_dalvik_args_operand_compare(const GDalvikArgsOperand *, const GDalvikArgsOperand *);
+/* Détermine le chemin conduisant à un opérande interne. */
+static char *g_dalvik_args_operand_find_inner_operand_path(const GDalvikArgsOperand *, const GArchOperand *);
+
+/* Obtient l'opérande correspondant à un chemin donné. */
+static GArchOperand *g_dalvik_args_operand_get_inner_operand_from_path(const GDalvikArgsOperand *, const char *);
+
/* Traduit un opérande en version humainement lisible. */
static void g_dalvik_args_operand_print(const GDalvikArgsOperand *, GBufferLine *);
@@ -106,12 +115,16 @@ static void g_dalvik_args_operand_class_init(GDalvikArgsOperandClass *klass)
GArchOperandClass *operand; /* Version de classe parente */
object = G_OBJECT_CLASS(klass);
- operand = G_ARCH_OPERAND_CLASS(klass);
object->dispose = (GObjectFinalizeFunc/* ! */)g_dalvik_args_operand_dispose;
object->finalize = (GObjectFinalizeFunc)g_dalvik_args_operand_finalize;
+ operand = G_ARCH_OPERAND_CLASS(klass);
+
operand->compare = (operand_compare_fc)g_dalvik_args_operand_compare;
+ operand->find_inner = (find_inner_operand_fc)g_dalvik_args_operand_find_inner_operand_path;
+ operand->get_inner = (get_inner_operand_fc)g_dalvik_args_operand_get_inner_operand_from_path;
+
operand->print = (operand_print_fc)g_dalvik_args_operand_print;
operand->unserialize = (unserialize_operand_fc)g_dalvik_args_operand_unserialize;
@@ -224,6 +237,128 @@ static int g_dalvik_args_operand_compare(const GDalvikArgsOperand *a, const GDal
/******************************************************************************
* *
+* Paramètres : operand = opérande à consulter. *
+* target = instruction à venir retrouver. *
+* *
+* Description : Détermine le chemin conduisant à un opérande interne. *
+* *
+* Retour : Chemin d'accès à l'opérande ou NULL en cas d'absence. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *g_dalvik_args_operand_find_inner_operand_path(const GDalvikArgsOperand *operand, const GArchOperand *target)
+{
+ char *result; /* Chemin à retourner */
+ size_t i; /* Boucle de parcours */
+ int ret; /* Bilan d'une construction */
+ char *sub_path; /* Sous-chemin emprunté */
+
+ result = NULL;
+
+ /* Première passe : accès direct */
+
+ for (i = 0; i < operand->count && result == NULL; i++)
+ {
+ if (operand->args[i] == target)
+ {
+ ret = asprintf(&result, "%zu", i);
+ if (ret == -1)
+ {
+ LOG_ERROR_N("asprintf");
+ result = NULL;
+ }
+ }
+
+ }
+
+ /* Seconde passe : accès profond */
+
+ for (i = 0; i < operand->count && result == NULL; i++)
+ {
+ sub_path = g_arch_operand_find_inner_operand_path(operand->args[i], target);
+
+ if (sub_path != NULL)
+ {
+ ret = asprintf(&result, "%zu:%s", i, sub_path);
+ if (ret == -1)
+ {
+ LOG_ERROR_N("asprintf");
+ result = NULL;
+ }
+
+ free(sub_path);
+
+ }
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à consulter. *
+* path = chemin d'accès à un opérande à retrouver. *
+* *
+* Description : Obtient l'opérande correspondant à un chemin donné. *
+* *
+* Retour : Opérande trouvé ou NULL en cas d'échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GArchOperand *g_dalvik_args_operand_get_inner_operand_from_path(const GDalvikArgsOperand *operand, const char *path)
+{
+ GArchOperand *result; /* Opérande trouvée à renvoyer */
+ size_t index; /* Indice de l'opérande visé */
+ char *end; /* Poursuite du parcours ? */
+ GArchOperand *found; /* Opérande trouvé */
+
+ result = NULL;
+
+ /* Recherche au premier niveau */
+
+ index = strtoul(path, &end, 10);
+
+ if ((index == ULONG_MAX && errno == ERANGE) || (index == 0 && errno == EINVAL))
+ {
+ LOG_ERROR_N("strtoul");
+ goto done;
+ }
+
+ if (index >= operand->count)
+ goto done;
+
+ found = operand->args[index];
+ if (found == NULL) goto done;
+
+ if (*end == '\0')
+ {
+ result = found;
+ g_object_ref(G_OBJECT(result));
+ goto done;
+ }
+
+ /* Recherche en profondeur */
+
+ assert(*end == ':');
+
+ result = g_arch_operand_get_inner_operand_from_path(found, end + 1);
+
+ done:
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : operand = opérande à traiter. *
* line = ligne tampon où imprimer l'opérande donné. *
* *