summaryrefslogtreecommitdiff
path: root/plugins/dexresolver/context.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/dexresolver/context.c')
-rw-r--r--plugins/dexresolver/context.c320
1 files changed, 320 insertions, 0 deletions
diff --git a/plugins/dexresolver/context.c b/plugins/dexresolver/context.c
new file mode 100644
index 0000000..0b863e9
--- /dev/null
+++ b/plugins/dexresolver/context.c
@@ -0,0 +1,320 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * context.h - prototypes pour les instances d'actions du présent greffon
+ *
+ * Copyright (C) 2010 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "context.h"
+
+
+#include <analysis/line_code.h>
+#include <arch/dalvik/operand.h>
+#include <glibext/delayed-int.h>
+#include <plugins/context-int.h>
+
+
+#include "operand.h"
+
+
+
+/* ---------------------------- REMPLACEMENT D'OPERANDES ---------------------------- */
+
+
+#define G_TYPE_DEX_RESOLVER_WORK g_dex_resolver_work_get_type()
+#define G_DEX_RESOLVER_WORK(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_dex_resolver_work_get_type(), GDelayedDisassembly))
+#define G_IS_DEX_RESOLVER_WORK(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_dex_resolver_work_get_type()))
+#define G_DEX_RESOLVER_WORK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DEX_RESOLVER_WORK, GDelayedDisassemblyClass))
+#define G_IS_DEX_RESOLVER_WORK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DEX_RESOLVER_WORK))
+#define G_DEX_RESOLVER_WORK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DEX_RESOLVER_WORK, GDelayedDisassemblyClass))
+
+
+/* Instance du greffon pour OpenIDA (instance) */
+typedef struct _GDexResolverWork
+{
+ GDelayedWork parent; /* A laisser en premier */
+
+ GOpenidaBinary *binary; /* Destinataire final */
+
+} GDexResolverWork;
+
+
+/* Instance du greffon pour OpenIDA (classe) */
+typedef struct _GDexResolverWorkClass
+{
+ GDelayedWorkClass parent; /* A laisser en premier */
+
+} GDexResolverWorkClass;
+
+
+/* Indique le type défini pour les tâches de résolutions différées. */
+static GType g_dex_resolver_work_get_type(void);
+
+/* Initialise la classe des résolutions d'opérandes différées. */
+static void g_dex_resolver_work_class_init(GDexResolverWorkClass *);
+
+/* Initialise une tâche de résolution d'opérandes différée. */
+static void g_dex_resolver_work_init(GDexResolverWork *);
+
+/* Crée une tâche de résolution d'opérandes différée. */
+static GDexResolverWork *g_dex_resolver_work_new(GOpenidaBinary *);
+
+/* Assure la résolution d'opérandes en différé. */
+static void g_dex_resolver_work_process(GDexResolverWork *, GtkExtStatusBar *);
+
+
+
+/* -------------------------- TACHE DIFFEREE DANS LE TEMPS -------------------------- */
+/* -------------------------- TACHE DIFFEREE DANS LE TEMPS -------------------------- */
+
+
+
+/* Instance du greffon pour OpenIDA (instance) */
+struct _GDexResolverContext
+{
+ GPluginContext parent; /* A laisser en premier */
+
+};
+
+
+/* Instance du greffon pour OpenIDA (classe) */
+struct _GDexResolverContextClass
+{
+ GPluginContextClass parent; /* A laisser en premier */
+
+};
+
+
+
+/* Initialise la classe des instances de greffon. */
+static void g_dex_resolver_context_class_init(GDexResolverContextClass *);
+
+/* Initialise une instance d'instance de greffon. */
+static void g_dex_resolver_context_init(GDexResolverContext *);
+
+
+
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* REMPLACEMENT D'OPERANDES */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour les tâches de résolutions différées. */
+G_DEFINE_TYPE(GDexResolverWork, g_dex_resolver_work, G_TYPE_DELAYED_WORK);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des résolutions d'opérandes différées. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dex_resolver_work_class_init(GDexResolverWorkClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : disass = instance à initialiser. *
+* *
+* Description : Initialise une tâche de résolution d'opérandes différée. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dex_resolver_work_init(GDexResolverWork *disass)
+{
+ G_DELAYED_WORK(disass)->run = (run_task_fc)g_dex_resolver_work_process;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = binaire chargé en attente des résultats. *
+* *
+* Description : Crée une tâche de résolution d'opérandes différée. *
+* *
+* Retour : Tâche créée. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GDexResolverWork *g_dex_resolver_work_new(GOpenidaBinary *binary)
+{
+ GDexResolverWork *result; /* Tâche à retourner */
+
+ result = g_object_new(G_TYPE_DEX_RESOLVER_WORK, NULL);
+
+ result->binary = binary;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : work = analyse à mener. *
+* statusbar = barre de statut à tenir informée. *
+* *
+* Description : Assure la résolution d'opérandes en différé. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dex_resolver_work_process(GDexResolverWork *work, GtkExtStatusBar *statusbar)
+{
+ GDexFormat *format; /* Format du binaire utilisé */
+ GRenderingLine *lines; /* Lignes désassemblées */
+ GRenderingLine *iter; /* Boucle de parcours */
+ GArchInstruction *instr; /* Instruction à ausculter */
+ size_t count; /* Quantité d'opérandes */
+ size_t i; /* Boucle de parcours */
+ const GArchOperand *op; /* Opérande à analyser */
+ GArchOperand *new; /* Nouvel opérande à afficher */
+
+ format = G_DEX_FORMAT(g_openida_binary_get_format(work->binary));
+
+ lines = g_openida_binary_get_lines(work->binary);
+
+ for (iter = lines;
+ iter != NULL;
+ iter = g_rendering_line_get_next_iter(lines, iter, NULL))
+ {
+ /* On ne traite que du code ici ! */
+ if (!G_IS_CODE_LINE(iter)) continue;
+
+ instr = g_code_line_get_instruction(G_CODE_LINE(iter));
+ count = g_arch_instruction_count_operands(instr);
+
+ for (i = 0; i < count; i++)
+ {
+ op = g_arch_instruction_get_operand(instr, i);
+
+ if (G_IS_DALVIK_POOL_OPERAND(op))
+ {
+ new = g_dalvik_hpool_operand_new(format, G_DALVIK_POOL_OPERAND(op));
+
+ if (new != NULL)
+ g_arch_instruction_replace_operand(instr, new, op);
+
+ }
+
+ }
+
+ }
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* REMPLACEMENT D'OPERANDES */
+/* REMPLACEMENT D'OPERANDES */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour une instance de greffon. */
+G_DEFINE_TYPE(GDexResolverContext, g_dex_resolver_context, G_TYPE_PLUGIN_CONTEXT);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des instances de greffon. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dex_resolver_context_class_init(GDexResolverContextClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : context = instance à initialiser. *
+* *
+* Description : Initialise une instance d'instance de greffon. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dex_resolver_context_init(GDexResolverContext *context)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = contenu binaire chargé à traiter. *
+* *
+* Description : Lance l'exécution d'une action du greffon. *
+* *
+* Retour : Instance d'exécution du greffon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GPluginContext *g_dex_resolver_context_new(GOpenidaBinary *binary)
+{
+ GPluginContext *result; /* Bilan d'exécution à renvoyer*/
+ GDexResolverWork *work; /* Tâche de parcours de lignes */
+
+ result = g_object_new(G_TYPE_DEX_RESOLVER_CONTEXT, NULL);
+
+ work = g_dex_resolver_work_new(binary);
+
+ g_signal_connect(work, "work-completed", G_CALLBACK(g_object_unref), NULL);
+
+ g_work_queue_schedule_work(get_work_queue(), G_DELAYED_WORK(work));
+
+ return result;
+
+}