summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog12
-rw-r--r--src/analysis/binary.c29
-rw-r--r--src/format/dex/class.c92
-rw-r--r--src/format/dex/class.h2
-rwxr-xr-xsrc/format/dex/dex.c2
-rw-r--r--src/format/dex/method.c31
-rw-r--r--src/format/dex/method.h5
7 files changed, 148 insertions, 25 deletions
diff --git a/ChangeLog b/ChangeLog
index 1379413..0d9ce37 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+10-06-02 Cyrille Bagard <nocbos@gmail.com>
+
+ * src/analysis/binary.c:
+ Insert all foudn routines in a better way.
+
+ * src/format/dex/class.c:
+ * src/format/dex/class.h:
+ * src/format/dex/dex.c:
+ * src/format/dex/method.c:
+ * src/format/dex/method.h:
+ Register all found routines.
+
10-05-23 Cyrille Bagard <nocbos@gmail.com>
* src/arch/dalvik/instruction.c:
diff --git a/src/analysis/binary.c b/src/analysis/binary.c
index 10acfb6..17fc172 100644
--- a/src/analysis/binary.c
+++ b/src/analysis/binary.c
@@ -356,6 +356,8 @@ static GRenderingLine *disassemble_binary_parts(GDelayedDisassembly *disass, GBi
done = 0;
+ k = 0;
+
for (i = 0; i < disass->count; i++)
{
g_binary_part_get_values(disass->parts[i], &pos, &len, &base);
@@ -375,6 +377,25 @@ static GRenderingLine *disassemble_binary_parts(GDelayedDisassembly *disass, GBi
line = g_code_line_new(addr, instr, options);
g_rendering_line_add_to_lines(&result, line);
+ /* Ajout des prototypes de fonctions */
+
+ printf("BASE == 0x%08llx\n", base);
+
+ for (; k < count; k++)
+ {
+ routine_offset = g_binary_routine_get_address(routines[k]);
+
+ if (routine_offset > addr) break;
+
+ routine_desc = g_binary_routine_to_string(routines[k]);
+
+ line = g_comment_line_new(routine_offset, routine_desc, options);
+ g_rendering_line_insert_into_lines(&result, line, true);
+
+ free(routine_desc);
+
+ }
+
if (pos < len)
gtk_extended_status_bar_update_activity(statusbar, id, (done + pos) * 1.0 / sum);
@@ -382,10 +403,12 @@ static GRenderingLine *disassemble_binary_parts(GDelayedDisassembly *disass, GBi
done += len;
gtk_extended_status_bar_update_activity(statusbar, id, done * 1.0 / sum);
-
+#if 0
/* Ajout des prototypes de fonctions */
- for (k = 0; k < count; k++)
+ printf("BASE == 0x%08llx\n", base);
+
+ for (; k < count; k++)
{
routine_offset = g_binary_routine_get_address(routines[k]);
@@ -399,7 +422,7 @@ static GRenderingLine *disassemble_binary_parts(GDelayedDisassembly *disass, GBi
free(routine_desc);
}
-
+#endif
}
return result;
diff --git a/src/format/dex/class.c b/src/format/dex/class.c
index 03431f0..23e08a0 100644
--- a/src/format/dex/class.c
+++ b/src/format/dex/class.c
@@ -66,6 +66,8 @@ static void g_dex_class_init(GDexClass *);
/* Crée une nouvelle représentation de classe issue de code. */
static GDexClass *g_dex_class_new(const GDexFormat *, off_t);
+/* Inscrit les méthodes d'une classe en tant que routines. */
+static void g_dex_class_register_method(const GDexClass *, GBinFormat *);
@@ -134,6 +136,7 @@ static GDexClass *g_dex_class_new(const GDexFormat *format, off_t offset)
GDexClass *result; /* Composant à retourner */
class_def_item def; /* Définition de la classe */
class_data_item data; /* Contenu de la classe */
+ uleb128_t index; /* Conservation du dernier id */
uleb128_t i; /* Boucle de parcours */
GDexMethod *method; /* Méthode chargée */
@@ -154,9 +157,11 @@ static GDexClass *g_dex_class_new(const GDexFormat *format, off_t offset)
result = g_object_new(G_TYPE_DEX_CLASS, NULL);
+ index = 0;
+
for (i = 0; i < data.direct_methods_size; i++)
{
- method = g_dex_method_new(format, &data.direct_methods[i]);
+ method = g_dex_method_new(format, &data.direct_methods[i], &index);
if (method != NULL)
{
@@ -170,11 +175,11 @@ static GDexClass *g_dex_class_new(const GDexFormat *format, off_t offset)
}
-
+ index = 0;
for (i = 0; i < data.virtual_methods_size; i++)
{
- method = g_dex_method_new(format, &data.virtual_methods[i]);
+ method = g_dex_method_new(format, &data.virtual_methods[i], &index);
if (method != NULL)
{
@@ -197,6 +202,49 @@ static GDexClass *g_dex_class_new(const GDexFormat *format, off_t offset)
/******************************************************************************
* *
+* Paramètres : class = informations chargées à consulter. *
+* format = format binaire à compléter. *
+* *
+* Description : Inscrit les méthodes d'une classe en tant que routines. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dex_class_register_method(const GDexClass *class, GBinFormat *format)
+{
+ size_t i; /* Boucle de parcours */
+ GBinRoutine *routine; /* Routine à inscrire */
+
+ for (i = 0; i < class->dmethods_count; i++)
+ {
+ routine = g_dex_method_get_routine(class->direct_methods[i]);
+ g_binary_format_add_routine(format, routine);
+
+ printf("routine @ 0x%08llx :: '%s'\n",
+ g_binary_routine_get_address(routine),
+ g_binary_routine_get_name(routine));
+
+ }
+
+ for (i = 0; i < class->vmethods_count; i++)
+ {
+ routine = g_dex_method_get_routine(class->virtual_methods[i]);
+ g_binary_format_add_routine(format, routine);
+
+ printf("routine @ 0x%08llx :: '%s'\n",
+ g_binary_routine_get_address(routine),
+ g_binary_routine_get_name(routine));
+
+ }
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : class = informations chargées à consulter. *
* parts = liste à venir compléter. *
* count = quantité de zones listées. [OUT] *
@@ -244,19 +292,6 @@ GBinPart **g_dex_class_get_parts(const GDexClass *class, GBinPart **parts, size_
-
-
-
-
-
-
-
-
-
-
-
-
-
/******************************************************************************
* *
* Paramètres : format = représentation interne du format DEX à compléter. *
@@ -296,3 +331,28 @@ bool load_all_dex_classes(GDexFormat *format)
return true;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = représentation interne du format DEX à compléter. *
+* *
+* Description : Enregistre toutes les méthodes des classes listées. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void register_all_dex_class_methods(GDexFormat *format)
+{
+ size_t i; /* Boucle de parcours */
+ GBinFormat *bformat; /* Autre version du format */
+
+ bformat = G_BIN_FORMAT(format);
+
+ for (i = 0; i < format->classes_count; i++)
+ g_dex_class_register_method(format->classes[i], bformat);
+
+}
diff --git a/src/format/dex/class.h b/src/format/dex/class.h
index d78e6e9..810f5e1 100644
--- a/src/format/dex/class.h
+++ b/src/format/dex/class.h
@@ -64,6 +64,8 @@ GBinPart **g_dex_class_get_parts(const GDexClass *, GBinPart **, size_t *);
/* Charge toutes les classes listées dans le contenu binaire. */
bool load_all_dex_classes(GDexFormat *);
+/* Enregistre toutes les méthodes des classes listées. */
+void register_all_dex_class_methods(GDexFormat *);
diff --git a/src/format/dex/dex.c b/src/format/dex/dex.c
index 5b68d5f..b87981f 100755
--- a/src/format/dex/dex.c
+++ b/src/format/dex/dex.c
@@ -181,7 +181,7 @@ GBinFormat *g_dex_format_new(const bin_t *content, off_t length)
return NULL;
}
-
+ register_all_dex_class_methods(result);
diff --git a/src/format/dex/method.c b/src/format/dex/method.c
index 3a604d0..4888c89 100644
--- a/src/format/dex/method.c
+++ b/src/format/dex/method.c
@@ -111,6 +111,7 @@ static void g_dex_method_init(GDexMethod *method)
* *
* Paramètres : format = représentation interne du format DEX à consulter. *
* seed = graine des informations à extraire. *
+* last = dernier indice utilisé (à mettre à jour). [OUT] *
* *
* Description : Crée une nouvelle représentation de methode issue de code. *
* *
@@ -120,7 +121,7 @@ static void g_dex_method_init(GDexMethod *method)
* *
******************************************************************************/
-GDexMethod *g_dex_method_new(const GDexFormat *format, const encoded_method *seed)
+GDexMethod *g_dex_method_new(const GDexFormat *format, const encoded_method *seed, uleb128_t *last)
{
GDexMethod *result; /* Composant à retourner */
off_t offset; /* Tête de lecture */
@@ -142,19 +143,22 @@ GDexMethod *g_dex_method_new(const GDexFormat *format, const encoded_method *see
//printf(" code size :: %d\n", item.insns_size);
- routine = get_routine_from_dex_pool(format, seed->method_idx_diff);
+ *last += seed->method_idx_diff;
+ routine = get_routine_from_dex_pool(format, *last);
+ printf(" method idx :: %lld\n", *last);
result->offset = seed->code_off + 4 * sizeof(uint16_t) + 2 *sizeof(uint32_t);/* TODO : faire plus propre ! */
+ printf(" method off :: 0x%08x\n", result->offset);
- g_binary_routine_set_address(routine, result->offset);
+ g_binary_routine_set_address(routine, result->offset);
- g_binary_format_add_routine(G_BIN_FORMAT(format), routine);
+ result->routine = routine;
return result;
@@ -166,6 +170,25 @@ GDexMethod *g_dex_method_new(const GDexFormat *format, const encoded_method *see
* *
* Paramètres : method = représentation interne du format DEX à consulter. *
* *
+* Description : Fournit la routine OpenIDA correspondant à la méthode. *
+* *
+* Retour : Instance de routine mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GBinRoutine *g_dex_method_get_routine(const GDexMethod *method)
+{
+ return method->routine;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : method = représentation interne du format DEX à consulter. *
+* *
* Description : Fournit la zone binaire correspondant à la méthode. *
* *
* Retour : Zone binaire à analyser. *
diff --git a/src/format/dex/method.h b/src/format/dex/method.h
index dd6f4b1..0f5a465 100644
--- a/src/format/dex/method.h
+++ b/src/format/dex/method.h
@@ -54,7 +54,10 @@ typedef struct _GDexMethodClass GDexMethodClass;
GType g_dex_method_get_type(void);
/* Crée une nouvelle représentation de methode issue de code. */
-GDexMethod *g_dex_method_new(const GDexFormat *, const encoded_method *);
+GDexMethod *g_dex_method_new(const GDexFormat *, const encoded_method *, uleb128_t *);
+
+/* Fournit la routine OpenIDA correspondant à la méthode. */
+GBinRoutine *g_dex_method_get_routine(const GDexMethod *);
/* Fournit la zone binaire correspondant à la méthode. */
GBinPart *g_dex_method_as_part(const GDexMethod *);