summaryrefslogtreecommitdiff
path: root/src/format/dex/dex.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2010-05-13 12:32:03 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2010-05-13 12:32:03 (GMT)
commit118a668adbf6ca9d4c549618e54f58330f46ce58 (patch)
tree10e75f1a7e83ab48aba82a5a595441a065a6037e /src/format/dex/dex.c
parente56b4db3aae87f0458319019635dea4968a5c529 (diff)
Supported Dalvik VM / DEX (partially).
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@155 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/format/dex/dex.c')
-rwxr-xr-xsrc/format/dex/dex.c307
1 files changed, 307 insertions, 0 deletions
diff --git a/src/format/dex/dex.c b/src/format/dex/dex.c
new file mode 100755
index 0000000..5b68d5f
--- /dev/null
+++ b/src/format/dex/dex.c
@@ -0,0 +1,307 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * dex.c - support du format DEX
+ *
+ * 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "dex.h"
+
+
+#include <string.h>
+
+
+#include "dex-int.h"
+
+
+
+
+
+
+
+
+
+
+
+/* Initialise la classe des formats d'exécutables DEX. */
+static void g_dex_format_class_init(GDexFormatClass *);
+
+/* Initialise une instance de format d'exécutable DEX. */
+static void g_dex_format_init(GDexFormat *);
+
+/* Indique le type d'architecture visée par le format. */
+static FormatTargetMachine g_dex_format_get_target_machine(const GDexFormat *);
+
+/* Fournit l'adresse mémoire du point d'entrée du programme. */
+static vmpa_t g_dex_format_get_entry_point(const GDexFormat *);
+
+/* Fournit les références aux zones binaires à analyser. */
+static GBinPart **g_dex_format_get_parts(const GDexFormat *, size_t *);
+
+/* Fournit la position correspondant à une adresse virtuelle. */
+static bool g_dex_format_translate_address_into_offset(const GDexFormat *, vmpa_t, off_t *);
+
+/* Fournit l'adresse virtuelle correspondant à une position. */
+static bool g_dex_format_translate_offset_into_address(const GDexFormat *, off_t, vmpa_t *);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type de format recherché. *
+* content = contenu binaire à parcourir. *
+* length = taille du contenu en question. *
+* *
+* Description : Indique si le format peut être pris en charge ici. *
+* *
+* Retour : true si la réponse est positive, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool dex_is_matching(FormatType type, const uint8_t *content, off_t length)
+{
+ bool result; /* Bilan à faire connaître */
+
+ result = false;
+
+ if (length >= DEX_FILE_MAGIC_LEN)
+ result = (memcmp(content, DEX_FILE_MAGIC, DEX_FILE_MAGIC_LEN) == 0);
+
+ return result;
+
+}
+
+
+/* Indique le type défini pour un format d'exécutable DEX. */
+G_DEFINE_TYPE(GDexFormat, g_dex_format, G_TYPE_EXE_FORMAT);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des formats d'exécutables DEX. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dex_format_class_init(GDexFormatClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = instance à initialiser. *
+* *
+* Description : Initialise une instance de format d'exécutable DEX. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dex_format_init(GDexFormat *format)
+{
+ GExeFormat *exe_format; /* Format parent à constituer */
+
+ exe_format = G_EXE_FORMAT(format);
+
+ exe_format->get_machine = (get_target_machine_fc)g_dex_format_get_target_machine;
+ exe_format->get_entry_point = (get_entry_point_fc)g_dex_format_get_entry_point;
+ exe_format->get_parts = (get_parts_fc)g_dex_format_get_parts;
+
+ exe_format->translate_addr = (translate_addr_fc)g_dex_format_translate_address_into_offset;
+ exe_format->translate_off = (translate_off_fc)g_dex_format_translate_offset_into_address;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : content = contenu binaire à parcourir. *
+* length = taille du contenu en question. *
+* *
+* Description : Prend en charge un nouveau format DEX. *
+* *
+* Retour : Adresse de la structure mise en place ou NULL en cas d'échec.*
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GBinFormat *g_dex_format_new(const bin_t *content, off_t length)
+{
+ GDexFormat *result; /* Structure à retourner */
+ off_t offset; /* Tête de lecture */
+
+ result = g_object_new(G_TYPE_DEX_FORMAT, NULL);
+
+ g_binary_format_set_content(G_BIN_FORMAT(result), content, length);
+
+
+ offset = 0;
+
+ if (!read_dex_header(result, &offset, &result->header))
+ {
+ /* TODO */
+ return NULL;
+ }
+
+ /* TODO : vérifier l'en-tête ! */
+
+
+
+ if (!load_all_dex_classes(result))
+ {
+ g_object_unref(G_OBJECT(result));
+ return NULL;
+ }
+
+
+
+
+
+ return G_BIN_FORMAT(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = informations chargées à consulter. *
+* *
+* Description : Indique le type d'architecture visée par le format. *
+* *
+* Retour : Identifiant de l'architecture ciblée par le format. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static FormatTargetMachine g_dex_format_get_target_machine(const GDexFormat *format)
+{
+ return FTM_DALVIK;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = informations chargées à consulter. *
+* *
+* Description : Fournit l'adresse mémoire du point d'entrée du programme. *
+* *
+* Retour : Adresse de mémoire. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static vmpa_t g_dex_format_get_entry_point(const GDexFormat *format)
+{
+ return 0;//(format->is_32b ? format->header.e_entry.addr32 : format->header.e_entry.addr64);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = informations chargées à consulter. *
+* count = quantité de zones listées. [OUT] *
+* *
+* Description : Fournit les références aux zones binaires à analyser. *
+* *
+* Retour : Zones binaires à analyser. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GBinPart **g_dex_format_get_parts(const GDexFormat *format, size_t *count)
+{
+ GBinPart **result; /* Tableau à retourner */
+ size_t i; /* Boucle de parcours */
+
+ result = NULL;
+ *count = 0;
+
+ for (i = 0; i < format->classes_count; i++)
+ result = g_dex_class_get_parts(format->classes[i], result, count);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = description de l'exécutable à consulter. *
+* addr = adresse virtuelle à retrouver. *
+* pos = position correspondante. [OUT] *
+* *
+* Description : Fournit la position correspondant à une adresse virtuelle. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_dex_format_translate_address_into_offset(const GDexFormat *format, vmpa_t addr, off_t *pos)
+{
+ bool result; /* Bilan à retourner */
+
+ result = false;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = description de l'exécutable à consulter. *
+* pos = position dans le flux binaire à retrouver. *
+* addr = adresse virtuelle correspondante. [OUT] *
+* *
+* Description : Fournit l'adresse virtuelle correspondant à une position. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_dex_format_translate_offset_into_address(const GDexFormat *format, off_t pos, vmpa_t *addr)
+{
+ bool result; /* Bilan à retourner */
+
+ result = false;
+
+ return result;
+
+}