diff options
Diffstat (limited to 'src/format/dex/method.c')
-rw-r--r-- | src/format/dex/method.c | 66 |
1 files changed, 48 insertions, 18 deletions
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; + } |