summaryrefslogtreecommitdiff
path: root/src/format/dex
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2017-05-16 21:56:55 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2017-05-16 21:56:55 (GMT)
commit4691a434a34a19317156a761967f719e408b73bb (patch)
tree1daaf5be5d4a9f52d492380c2862580129d2ad12 /src/format/dex
parent1996274a43883aa58e8c565f7698bc7c338a9ce0 (diff)
Merged routines into symbols.
Diffstat (limited to 'src/format/dex')
-rw-r--r--src/format/dex/class.c16
-rw-r--r--src/format/dex/method.c4
-rw-r--r--src/format/dex/method.h1
-rw-r--r--src/format/dex/pool.c36
-rw-r--r--src/format/dex/pool.h2
5 files changed, 39 insertions, 20 deletions
diff --git a/src/format/dex/class.c b/src/format/dex/class.c
index 897720a..eb2ba3f 100644
--- a/src/format/dex/class.c
+++ b/src/format/dex/class.c
@@ -196,11 +196,11 @@ GDexClass *g_dex_class_new(GDexFormat *format, const class_def_item *def)
vmpa2t addr; /* Tête de lecture générique */
class_data_item data; /* Contenu de la classe */
GDataType *ctype; /* Type créé par la classe */
+ GBinFormat *base; /* Autre version du format */
uleb128_t index; /* Conservation du dernier id */
uleb128_t i; /* Boucle de parcours */
GDexMethod *method; /* Méthode chargée */
GBinRoutine *routine; /* Version interne de méthode */
- GBinSymbol *symbol; /* Nouveau symbole construit */
result = g_object_new(G_TYPE_DEX_CLASS, NULL);
@@ -235,6 +235,8 @@ GDexClass *g_dex_class_new(GDexFormat *format, const class_def_item *def)
ctype = get_type_from_dex_pool(format, def->class_idx);
assert(ctype != NULL);
+ base = G_BIN_FORMAT(format);
+
index = 0;
result->dmethods_count = data.direct_methods_size;
@@ -255,10 +257,7 @@ GDexClass *g_dex_class_new(GDexFormat *format, const class_def_item *def)
g_object_ref(G_OBJECT(ctype));
g_binary_routine_set_namespace(routine, ctype, ".");
- symbol = g_binary_symbol_new(STP_ROUTINE);
- g_binary_symbol_attach_routine(symbol, routine);
-
- g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol);
+ g_binary_format_add_symbol(base, G_BIN_SYMBOL(routine));
}
@@ -284,10 +283,7 @@ GDexClass *g_dex_class_new(GDexFormat *format, const class_def_item *def)
g_object_ref(G_OBJECT(ctype));
g_binary_routine_set_namespace(routine, ctype, ".");
- symbol = g_binary_symbol_new(STP_ROUTINE);
- g_binary_symbol_attach_routine(symbol, routine);
-
- g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol);
+ g_binary_format_add_symbol(base, G_BIN_SYMBOL(routine));
}
@@ -493,7 +489,7 @@ const char *g_dex_class_get_source_file(const GDexClass *class, const GDexFormat
{
const char *result; /* Trouvaille à renvoyer */
- result = get_string_from_dex_pool(format, class->definition.source_file_idx);
+ result = get_string_from_dex_pool(format, class->definition.source_file_idx, NULL);
return result;
diff --git a/src/format/dex/method.c b/src/format/dex/method.c
index be99479..f487c0a 100644
--- a/src/format/dex/method.c
+++ b/src/format/dex/method.c
@@ -212,7 +212,7 @@ GDexMethod *g_dex_method_new_defined(GDexFormat *format, const encoded_method *s
result->offset = ins_offset;
init_mrange(&range, &addr, item.insns_size * sizeof(uint16_t));
- g_binary_routine_set_range(result->routine, &range);
+ g_binary_symbol_set_range(G_BIN_SYMBOL(result->routine), &range);
}
@@ -252,7 +252,7 @@ GDexMethod *g_dex_method_new_callable(GDexFormat *format, const method_id_item *
result = NULL;
- name = get_string_from_dex_pool(format, method_id->name_idx);
+ name = get_string_from_dex_pool(format, method_id->name_idx, NULL);
if (name == NULL) goto gdmne_exit;
routine = get_prototype_from_dex_pool(format, method_id->proto_idx);
diff --git a/src/format/dex/method.h b/src/format/dex/method.h
index e5b8634..47e90b8 100644
--- a/src/format/dex/method.h
+++ b/src/format/dex/method.h
@@ -30,6 +30,7 @@
#include "dex.h"
#include "dex_def.h"
+#include "../../analysis/routine.h"
diff --git a/src/format/dex/pool.c b/src/format/dex/pool.c
index 9a99cc8..0180b19 100644
--- a/src/format/dex/pool.c
+++ b/src/format/dex/pool.c
@@ -52,19 +52,29 @@
bool find_all_dex_strings(GDexFormat *format)
{
+ GBinFormat *base; /* Autre version du format */
uint32_t i; /* Boucle de parcours */
+ mrange_t range; /* Couverture associée */
const char *text; /* Texte issu du binaire */
GBinSymbol *symbol; /* Nouveau symbole construit */
+ char *label; /* Désignation de la chaîne */
+
+ base = G_BIN_FORMAT(format);
for (i = 0; i < format->header.string_ids_size; i++)
{
- text = get_string_from_dex_pool(format, i);
+ text = get_string_from_dex_pool(format, i, &range);
if (text == NULL) continue;
- symbol = g_binary_symbol_new(STP_STRING);
- g_binary_symbol_set_alt_label(symbol, text);
+ symbol = g_binary_symbol_new(&range, STP_STRING);
+
+ label = create_string_label(base, get_mrange_addr(&range), get_mrange_length(&range));
+
+ g_binary_symbol_set_alt_label(symbol, label);
- g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol);
+ free(label);
+
+ g_binary_format_add_symbol(base, symbol);
}
@@ -77,6 +87,7 @@ bool find_all_dex_strings(GDexFormat *format)
* *
* Paramètres : format = représentation interne du format DEX à consulter. *
* index = index du type recherchée. *
+* range = éventuelle couverture à renseigner ou NULL. [OUT] *
* *
* Description : Extrait une chaîne de caractères d'une table DEX. *
* *
@@ -86,12 +97,14 @@ bool find_all_dex_strings(GDexFormat *format)
* *
******************************************************************************/
-const char *get_string_from_dex_pool(const GDexFormat *format, uint32_t index)
+const char *get_string_from_dex_pool(const GDexFormat *format, uint32_t index, mrange_t *range)
{
off_t pos; /* Tête de lecture */
vmpa2t addr; /* Tête de lecture générique */
string_id_item str_id; /* Identifiant de chaîne */
string_data_item str_data; /* Description de chaîne */
+ vmpa2t start; /* Début de la chaîne */
+ phys_t diff; /* Avancée de tête de lecture */
if (index >= format->header.string_ids_size)
return NULL;
@@ -108,6 +121,15 @@ const char *get_string_from_dex_pool(const GDexFormat *format, uint32_t index)
if (!read_dex_string_data_item(format, &addr, &str_data))
return NULL;
+ if (range != NULL)
+ {
+ init_vmpa(&start, pos, VMPA_NO_VIRTUAL);
+ diff = compute_vmpa_diff(&start, &addr);
+
+ init_mrange(range, &start, diff);
+
+ }
+
return (const char *)str_data.data;
}
@@ -362,7 +384,7 @@ GBinVariable *get_field_from_dex_pool(GDexFormat *format, uint32_t index)
type = get_type_from_dex_pool(format, field_id.type_idx);
if (type == NULL) goto gffdp_error;
- name = get_string_from_dex_pool(format, field_id.name_idx);
+ name = get_string_from_dex_pool(format, field_id.name_idx, NULL);
if (name == NULL) goto gffdp_bad_name;
field = g_binary_variable_new(type);
@@ -452,7 +474,7 @@ GBinRoutine *get_prototype_from_dex_pool(GDexFormat *format, uint32_t index)
/* Nom de la méthode */
- name = get_string_from_dex_pool(format, proto_id.shorty_idx);
+ name = get_string_from_dex_pool(format, proto_id.shorty_idx, NULL);
/* Liste des arguments */
diff --git a/src/format/dex/pool.h b/src/format/dex/pool.h
index 68fecc3..207f88c 100644
--- a/src/format/dex/pool.h
+++ b/src/format/dex/pool.h
@@ -37,7 +37,7 @@
bool find_all_dex_strings(GDexFormat *);
/* Extrait une chaîne de caractères d'une table DEX. */
-const char *get_string_from_dex_pool(const GDexFormat *, uint32_t);
+const char *get_string_from_dex_pool(const GDexFormat *, uint32_t, mrange_t *);