summaryrefslogtreecommitdiff
path: root/src/arch/dalvik/context.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2011-10-12 13:31:00 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2011-10-12 13:31:00 (GMT)
commit044b4d6d7ba4de50cd4d05b92621900e929e2231 (patch)
tree70167cbd5c90d0f8b2fc967add38272d21de1e4f /src/arch/dalvik/context.c
parente8d2795d9ec2c8845641863fc42ce39f9e92906b (diff)
Processed skipped instructions and used contexts.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@212 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/arch/dalvik/context.c')
-rw-r--r--src/arch/dalvik/context.c229
1 files changed, 229 insertions, 0 deletions
diff --git a/src/arch/dalvik/context.c b/src/arch/dalvik/context.c
new file mode 100644
index 0000000..67c1861
--- /dev/null
+++ b/src/arch/dalvik/context.c
@@ -0,0 +1,229 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * context.c - contexte lié à l'exécution d'un processeur
+ *
+ * Copyright (C) 2011 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "context.h"
+
+
+#include <malloc.h>
+#include <string.h>
+
+
+#include "../context-int.h"
+
+
+
+/* Mémorisation d'un saut dans le code */
+typedef struct _skipped_dalvik_area skipped_dalvik_area;
+
+
+/* ------------------------ MANIPULATION GLOBALE DU CONTEXTE ------------------------ */
+
+
+/* Définition d'un contexte pour processeur Dalkvik (instance) */
+struct _GDalvikContext
+{
+ GProcContext parent; /* A laisser en premier */
+
+ skipped_dalvik_area *skip; /* Liste de Zones à écarter */
+ size_t count; /* Taille de cette liste */
+
+};
+
+
+/* Définition d'un contexte pour processeur Dalkvik (classe) */
+struct _GDalvikContextClass
+{
+ GProcContextClass parent; /* A laisser en premier */
+
+};
+
+
+/* Initialise la classe des contextes de processeur Dalkvik. */
+static void g_dalvik_context_class_init(GDalvikContextClass *);
+
+/* Initialise une instance de contexte de processeur Dalkvik. */
+static void g_dalvik_context_init(GDalvikContext *);
+
+
+
+/* ------------------------- MEMORISATION DES SAUTS DE CODE ------------------------- */
+
+
+/* Mémorisation d'un saut dans le code */
+struct _skipped_dalvik_area
+{
+ vmpa_t start; /* Début de la zone concernée */
+ vmpa_t end; /* Fin de la zone concernée */
+
+};
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* MANIPULATION GLOBALE DU CONTEXTE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type définit par la GLib pour le contexte de processeur Dalkvik. */
+G_DEFINE_TYPE(GDalvikContext, g_dalvik_context, G_TYPE_PROC_CONTEXT);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des contextes de processeur Dalkvik. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dalvik_context_class_init(GDalvikContextClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : ctx = instance à initialiser. *
+* *
+* Description : Initialise une instance de contexte de processeur Dalkvik. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dalvik_context_init(GDalvikContext *ctx)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Crée un contexte pour l'exécution du processeur Dalvik. *
+* *
+* Retour : Contexte mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDalvikContext *g_dalvik_context_new(void)
+{
+ GDalvikContext *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_DALVIK_CONTEXT, NULL);
+
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* MEMORISATION DES SAUTS DE CODE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : ctx = instance à mettre à jour. *
+* start = début de la zone à écarter du traitement. *
+* end = fin de la zone à écarter du traitement. *
+* *
+* Description : Mémorise une nouvelle zone de code comme étant des données. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_dalvik_context_skip_new_area(GDalvikContext *ctx, vmpa_t start, vmpa_t end)
+{
+ ctx->skip = (skipped_dalvik_area *)realloc(ctx->skip,
+ ++ctx->count * sizeof(skipped_dalvik_area));
+
+ ctx->skip[ctx->count - 1].start = start;
+ ctx->skip[ctx->count - 1].end = end;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : ctx = instance à consulter. *
+* addr = adresse à mainupuler. *
+* *
+* Description : Indique si l'adresse est considérée comme zone de données. *
+* *
+* Retour : true si l'adresse est considérée comme zone de données. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_dalvik_context_have_to_skip(GDalvikContext *ctx, vmpa_t addr)
+{
+ bool result; /* verdict à retourner */
+ size_t i; /* Boucle de parcours */
+
+ result = false;
+
+ for (i = 0; i < ctx->count && !result; i++)
+ if (ctx->skip[i].start <= addr && addr < ctx->skip[i].end)
+ {
+ result = true;
+ ctx->skip[i].start += sizeof(uint16_t);
+
+ /* BUG_ON(ctx->skip[i].start > ctx->skip[i].end) */
+
+ if (ctx->skip[i].start >= ctx->skip[i].end)
+ {
+ if (i <= (ctx->count - 1))
+ memmove(&ctx->skip[i], &ctx->skip[i + 1], ctx->count - i - 1);
+
+ if (--ctx->count == 0)
+ ctx->skip = NULL;
+ else
+ ctx->skip = (skipped_dalvik_area *)realloc(ctx->skip,
+ ++ctx->count * sizeof(skipped_dalvik_area));
+
+ }
+
+ break;
+
+ }
+
+ return result;
+
+}