diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2010-05-13 12:32:03 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2010-05-13 12:32:03 (GMT) |
commit | 118a668adbf6ca9d4c549618e54f58330f46ce58 (patch) | |
tree | 10e75f1a7e83ab48aba82a5a595441a065a6037e /src/format/dex/method.c | |
parent | e56b4db3aae87f0458319019635dea4968a5c529 (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/method.c')
-rw-r--r-- | src/format/dex/method.c | 193 |
1 files changed, 193 insertions, 0 deletions
diff --git a/src/format/dex/method.c b/src/format/dex/method.c new file mode 100644 index 0000000..3a604d0 --- /dev/null +++ b/src/format/dex/method.c @@ -0,0 +1,193 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * method.c - manipulation des methodes 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 "method.h" + + +#include "dex-int.h" +#include "pool.h" + + + + + +/* Methode issue du code source (instance) */ +struct _GDexMethod +{ + GObject parent; /* A laisser en premier */ + + GBinRoutine *routine; /* Représentation interne */ + + code_item body; /* Corps de la méthode */ + off_t offset; /* Position du code */ + +}; + +/* Methode issue du code source (classe) */ +struct _GDexMethodClass +{ + GObjectClass parent; /* A laisser en premier */ + +}; + + +/* Procède à l'initialisation d'une methode issue du code. */ +static void g_dex_method_class_init(GDexMethodClass *); + +/* Procède à l'initialisation d'une methode issue du code. */ +static void g_dex_method_init(GDexMethod *); + + + + + + + + + + +/* Détermine le type d'une methode issue du code source. */ +G_DEFINE_TYPE(GDexMethod, g_dex_method, G_TYPE_OBJECT); + + + +/****************************************************************************** +* * +* Paramètres : class = classe de composant GLib à initialiser. * +* * +* Description : Procède à l'initialisation d'une methode issue du code. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_dex_method_class_init(GDexMethodClass *class) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : method = composant GLib à initialiser. * +* * +* Description : Procède à l'initialisation d'une methode issue du code. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_dex_method_init(GDexMethod *method) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : format = représentation interne du format DEX à consulter. * +* seed = graine des informations à extraire. * +* * +* Description : Crée une nouvelle représentation de methode issue de code. * +* * +* Retour : Composant GLib créé. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GDexMethod *g_dex_method_new(const GDexFormat *format, const encoded_method *seed) +{ + GDexMethod *result; /* Composant à retourner */ + off_t offset; /* Tête de lecture */ + code_item item; /* Corps de la méthode */ + + + GBinRoutine *routine; + + offset = seed->code_off; + + if (!read_dex_code_item(format, &offset, &item)) + return NULL; + + result = g_object_new(G_TYPE_DEX_METHOD, NULL); + + result->body = item; + + //printf(" method idx :: %d\n", seed->method_idx_diff); + //printf(" code size :: %d\n", item.insns_size); + + + routine = get_routine_from_dex_pool(format, seed->method_idx_diff); + + + + result->offset = seed->code_off + 4 * sizeof(uint16_t) + 2 *sizeof(uint32_t);/* TODO : faire plus propre ! */ + + + + g_binary_routine_set_address(routine, result->offset); + + + g_binary_format_add_routine(G_BIN_FORMAT(format), routine); + + + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : method = représentation interne du format DEX à consulter. * +* * +* Description : Fournit la zone binaire correspondant à la méthode. * +* * +* Retour : Zone binaire à analyser. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GBinPart *g_dex_method_as_part(const GDexMethod *method) +{ + GBinPart *result; /* Instance à retourner */ + + result = g_binary_part_new(); + + g_binary_part_set_name(result, "name"); + + g_binary_part_set_values(result, + method->offset, method->body.insns_size * sizeof(uint16_t), method->offset); + + return result; + +} + + + |