diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2016-09-11 18:29:09 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2016-09-11 18:29:09 (GMT) |
commit | 29f3cf8c660c5ce51dbcdbd0c770a1d9831cf1a8 (patch) | |
tree | 49257065715c40b1af42c0dcd536fb85acc45a1c /src/format | |
parent | 49f75f22fe67ac356f05c7f81d3a78c48461655b (diff) |
Handled Dex classes used as marker interfaces and Dex virtual methods.
Diffstat (limited to 'src/format')
-rw-r--r-- | src/format/dex/class.c | 39 | ||||
-rw-r--r-- | src/format/dex/method.c | 66 | ||||
-rw-r--r-- | src/format/dex/method.h | 2 |
3 files changed, 83 insertions, 24 deletions
diff --git a/src/format/dex/class.c b/src/format/dex/class.c index 37fdd04..a88f3f2 100644 --- a/src/format/dex/class.c +++ b/src/format/dex/class.c @@ -39,6 +39,7 @@ struct _GDexClass GObject parent; /* A laisser en premier */ class_def_item definition; /* Définition de la classe */ + bool has_data; /* Indicateur de présence */ class_data_item data; /* Contenu de la classe */ GDexMethod **direct_methods; /* Méthodes propres */ @@ -199,14 +200,29 @@ GDexClass *g_dex_class_new(GDexFormat *format, const class_def_item *def) GBinRoutine *routine; /* Version interne de méthode */ GBinSymbol *symbol; /* Nouveau symbole construit */ + result = g_object_new(G_TYPE_DEX_CLASS, NULL); + + result->definition = *def; + result->has_data = (def->class_data_off != 0); + + /* Interface vide ? */ + if (!result->has_data) + { + result->dmethods_count = 0; + result->direct_methods = NULL; + + result->vmethods_count = 0; + result->virtual_methods = NULL; + + goto gdcn_done; + + } + init_vmpa(&addr, def->class_data_off, VMPA_NO_VIRTUAL); if (!read_dex_class_data_item(format, &addr, &data)) - return NULL; + goto gdcn_bad_item; - result = g_object_new(G_TYPE_DEX_CLASS, NULL); - - result->definition = *def; result->data = data; /** @@ -264,6 +280,7 @@ GDexClass *g_dex_class_new(GDexFormat *format, const class_def_item *def) return result; + gdcn_bad_item: gdcn_bad_method: g_object_unref(G_OBJECT(result)); @@ -306,7 +323,7 @@ const class_def_item *g_dex_class_get_definition(const GDexClass *class) const class_data_item *g_dex_class_get_data(const GDexClass *class) { - return &class->data; + return (class->has_data ? &class->data : NULL); } @@ -410,9 +427,20 @@ GDexMethod *g_dex_class_find_method_by_address(const GDexClass *class, vmpa_t ad { GDexMethod *result; /* Trouvaille à retourner */ size_t i; /* Boucle de parcours */ + phys_t offset; /* Emplacement de méthode */ result = NULL; +#if 0 /* FIXME */ + /* + +bool g_dex_method_get_offset(const GDexMethod *method, phys_t *offset) + + if (!g_exe_format_translate_offset_into_vmpa(G_EXE_FORMAT(format), method->offset, &addr)) + return; + + */ + for (i = 0; i < class->dmethods_count && result == NULL; i++) if (addr == (vmpa_t)g_dex_method_get_offset(class->direct_methods[i])) result = class->direct_methods[i]; @@ -420,6 +448,7 @@ GDexMethod *g_dex_class_find_method_by_address(const GDexClass *class, vmpa_t ad for (i = 0; i < class->vmethods_count && result == NULL; i++) if (addr == (vmpa_t)g_dex_method_get_offset(class->virtual_methods[i])) result = class->virtual_methods[i]; +#endif return result; diff --git a/src/format/dex/method.c b/src/format/dex/method.c index f91af0d..d633d15 100644 --- a/src/format/dex/method.c +++ b/src/format/dex/method.c @@ -46,6 +46,7 @@ struct _GDexMethod /* FIXME : méthode interne seulement */ encoded_method info; /* Propriétés de la méthode */ + bool has_body; /* Indication de présence */ code_item body; /* Corps de la méthode */ off_t offset; /* Position du code */ @@ -183,33 +184,50 @@ GDexMethod *g_dex_method_new_defined(GDexFormat *format, const encoded_method *s phys_t ins_offset; /* Position physique du code */ mrange_t range; /* Emplacement du code associé */ - init_vmpa(&addr, seed->code_off, VMPA_NO_VIRTUAL); - - if (!read_dex_code_item(format, &addr, &item)) - return NULL; - *last += seed->method_idx_diff; - ins_offset = seed->code_off + offsetof(code_item, insns); - - if (!g_exe_format_translate_offset_into_vmpa(G_EXE_FORMAT(format), ins_offset, &addr)) - return NULL; - result = get_method_from_dex_pool(format, *last); if (result == NULL) return NULL; result->info = *seed; - result->body = item; - result->offset = ins_offset; + result->has_body = (seed->code_off > 0); + + if (result->has_body) + { + init_vmpa(&addr, seed->code_off, VMPA_NO_VIRTUAL); + + if (!read_dex_code_item(format, &addr, &item)) + goto gdmnd_bad_code_item; + + ins_offset = seed->code_off + offsetof(code_item, insns); + + if (!g_exe_format_translate_offset_into_vmpa(G_EXE_FORMAT(format), ins_offset, &addr)) + goto gdmnd_bad_translation; + + result->body = item; + + result->offset = ins_offset; + + init_mrange(&range, &addr, item.insns_size * sizeof(uint16_t)); + g_binary_routine_set_range(result->routine, &range); - init_mrange(&range, &addr, item.insns_size * sizeof(uint16_t)); - g_binary_routine_set_range(result->routine, &range); + } return result; + gdmnd_bad_translation: + + reset_dex_code_item(&item); + + gdmnd_bad_code_item: + + g_object_unref(G_OBJECT(result)); + + return NULL; + } @@ -286,7 +304,7 @@ const encoded_method *g_dex_method_get_dex_info(const GDexMethod *method) const code_item *g_dex_method_get_dex_body(const GDexMethod *method) { - return &method->body; + return (method->has_body ? &method->body : NULL); } @@ -340,6 +358,9 @@ void g_dex_method_include_as_portion(const GDexMethod *method, const GDexFormat if (method->info.access_flags & ACC_NATIVE) return; + if (!method->has_body) + return; + if (!g_exe_format_translate_offset_into_vmpa(G_EXE_FORMAT(format), method->offset, &addr)) return; @@ -363,18 +384,27 @@ void g_dex_method_include_as_portion(const GDexMethod *method, const GDexFormat /****************************************************************************** * * * Paramètres : method = représentation interne du format DEX à consulter. * +* offset = position physique à renseigner. [OUT] * * * * Description : Indique la position de la méthode au sein du binaire. * * * -* Retour : Localisation dans le contenu binaire. * +* Retour : Validiter de la position dans le contenu binaire. * * * * Remarques : - * * * ******************************************************************************/ -off_t g_dex_method_get_offset(const GDexMethod *method) +bool g_dex_method_get_offset(const GDexMethod *method, phys_t *offset) { - return method->offset; + bool result; /* Indication à retourner */ + + result = method->has_body; + + if (result) + *offset = method->offset; + + return result; + } diff --git a/src/format/dex/method.h b/src/format/dex/method.h index c7e945d..68c6649 100644 --- a/src/format/dex/method.h +++ b/src/format/dex/method.h @@ -85,7 +85,7 @@ GBinRoutine *g_dex_method_get_routine(const GDexMethod *); void g_dex_method_include_as_portion(const GDexMethod *, const GDexFormat *, GPortionLayer *); /* Indique la position de la méthode au sein du binaire. */ -off_t g_dex_method_get_offset(const GDexMethod *); +bool g_dex_method_get_offset(const GDexMethod *method, phys_t *); /* Fournit des indications sur la nature d'une variable donnée. */ DexVariableIndex g_dex_method_get_variable(const GDexMethod *, uint32_t); |