summaryrefslogtreecommitdiff
path: root/src/format
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2015-12-28 23:27:12 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2015-12-28 23:27:12 (GMT)
commitb57e8ef5522dcbe126157fc2c50fcf879aa7d743 (patch)
tree1ecfd9de39073fee3a2c1a4afa9ce5da574b26df /src/format
parent276b75e6e9ff99a930bd36045e55b1117bb29579 (diff)
Defined layers to register all kinds of binary portions.
Diffstat (limited to 'src/format')
-rw-r--r--src/format/dex/class.c8
-rw-r--r--src/format/dex/class.h2
-rwxr-xr-xsrc/format/dex/dex.c16
-rw-r--r--src/format/dex/method.c6
-rw-r--r--src/format/dex/method.h2
-rw-r--r--src/format/elf/elf.c24
-rw-r--r--src/format/executable-int.h4
-rw-r--r--src/format/executable.c89
-rw-r--r--src/format/executable.h8
9 files changed, 63 insertions, 96 deletions
diff --git a/src/format/dex/class.c b/src/format/dex/class.c
index 657461f..1dc3a40 100644
--- a/src/format/dex/class.c
+++ b/src/format/dex/class.c
@@ -309,7 +309,7 @@ GDexMethod *g_dex_class_get_method(const GDexClass *class, bool virtual, size_t
/******************************************************************************
* *
* Paramètres : class = informations chargées à consulter. *
-* raw = portion de binaire brut à raffiner. *
+* layer = couche de portions à raffiner. *
* *
* Description : Intègre la méthode en tant que portion de code. *
* *
@@ -319,15 +319,15 @@ GDexMethod *g_dex_class_get_method(const GDexClass *class, bool virtual, size_t
* *
******************************************************************************/
-void g_dex_class_include_as_portion(const GDexClass *class, GBinPortion *raw)
+void g_dex_class_include_as_portion(const GDexClass *class, GPortionLayer *layer)
{
size_t i; /* Boucle de parcours */
for (i = 0; i < class->dmethods_count; i++)
- g_dex_method_include_as_portion(class->direct_methods[i], raw);
+ g_dex_method_include_as_portion(class->direct_methods[i], layer);
for (i = 0; i < class->vmethods_count; i++)
- g_dex_method_include_as_portion(class->virtual_methods[i], raw);
+ g_dex_method_include_as_portion(class->virtual_methods[i], layer);
}
diff --git a/src/format/dex/class.h b/src/format/dex/class.h
index 77fa6ba..fb7cada 100644
--- a/src/format/dex/class.h
+++ b/src/format/dex/class.h
@@ -64,7 +64,7 @@ size_t g_dex_class_count_methods(const GDexClass *, bool);
GDexMethod *g_dex_class_get_method(const GDexClass *, bool, size_t);
/* Intègre la méthode en tant que portion de code. */
-void g_dex_class_include_as_portion(const GDexClass *, GBinPortion *);
+void g_dex_class_include_as_portion(const GDexClass *, GPortionLayer *);
/* Retrouve si possible la méthode associée à une adresse. */
GDexMethod *g_dex_class_find_method_by_address(const GDexClass *, vmpa_t);
diff --git a/src/format/dex/dex.c b/src/format/dex/dex.c
index afd9db1..ed2565f 100755
--- a/src/format/dex/dex.c
+++ b/src/format/dex/dex.c
@@ -27,6 +27,9 @@
#include <string.h>
+#include <i18n.h>
+
+
#include "dex-int.h"
#include "pool.h"
@@ -55,7 +58,7 @@ static void g_dex_format_finalize(GDexFormat *);
static const char *g_dex_format_get_target_machine(const GDexFormat *);
/* Etend la définition des portions au sein d'un binaire. */
-static void g_dex_format_refine_portions(const GDexFormat *, GBinPortion *);
+static void g_dex_format_refine_portions(const GDexFormat *, GPortionLayer *);
/* Fournit l'emplacement d'une section donnée. */
static bool g_dex_format_get_section_range_by_name(const GDexFormat *, const char *, mrange_t *);
@@ -302,7 +305,7 @@ static const char *g_dex_format_get_target_machine(const GDexFormat *format)
/******************************************************************************
* *
* Paramètres : format = informations chargées à consulter. *
-* raw = portion de binaire brut à raffiner. *
+* main = couche de portions principale à raffiner. *
* *
* Description : Etend la définition des portions au sein d'un binaire. *
* *
@@ -312,15 +315,20 @@ static const char *g_dex_format_get_target_machine(const GDexFormat *format)
* *
******************************************************************************/
-static void g_dex_format_refine_portions(const GDexFormat *format, GBinPortion *raw)
+static void g_dex_format_refine_portions(const GDexFormat *format, GPortionLayer *main)
{
+ GPortionLayer *layer; /* Couche à mettre en place */
size_t max; /* Nombre d'itérations prévues */
size_t i; /* Boucle de parcours */
+ layer = g_portion_layer_new(NO_LENGTH_YET, _("Code"));
+
+ g_portion_layer_attach_sub(main, layer);
+
max = g_dex_format_count_classes(format);
for (i = 0; i < max; i++)
- g_dex_class_include_as_portion(format->classes[i], raw);
+ g_dex_class_include_as_portion(format->classes[i], layer);
}
diff --git a/src/format/dex/method.c b/src/format/dex/method.c
index c68e9e1..9c911d1 100644
--- a/src/format/dex/method.c
+++ b/src/format/dex/method.c
@@ -294,7 +294,7 @@ GBinRoutine *g_dex_method_get_routine(const GDexMethod *method)
/******************************************************************************
* *
* Paramètres : method = représentation interne du format DEX à consulter. *
-* raw = portion de binaire brut à raffiner. *
+* layer = couche de portions à raffiner. *
* *
* Description : Intègre la méthode en tant que portion de code. *
* *
@@ -304,7 +304,7 @@ GBinRoutine *g_dex_method_get_routine(const GDexMethod *method)
* *
******************************************************************************/
-void g_dex_method_include_as_portion(const GDexMethod *method, GBinPortion *raw)
+void g_dex_method_include_as_portion(const GDexMethod *method, GPortionLayer *layer)
{
GBinPortion *new; /* Nouvelle portion définie */
char *desc; /* Description d'une portion */
@@ -327,7 +327,7 @@ void g_dex_method_include_as_portion(const GDexMethod *method, GBinPortion *raw)
g_binary_portion_set_rights(new, PAC_READ | PAC_EXEC);
- g_binary_portion_include(raw, new);
+ g_portion_layer_include(layer, new);
}
diff --git a/src/format/dex/method.h b/src/format/dex/method.h
index dee33cb..4d29bac 100644
--- a/src/format/dex/method.h
+++ b/src/format/dex/method.h
@@ -82,7 +82,7 @@ const code_item *g_dex_method_get_dex_body(const GDexMethod *);
GBinRoutine *g_dex_method_get_routine(const GDexMethod *);
/* Intègre la méthode en tant que portion de code. */
-void g_dex_method_include_as_portion(const GDexMethod *, GBinPortion *);
+void g_dex_method_include_as_portion(const GDexMethod *, GPortionLayer *);
/* Indique la position de la méthode au sein du binaire. */
off_t g_dex_method_get_offset(const GDexMethod *);
diff --git a/src/format/elf/elf.c b/src/format/elf/elf.c
index 3dc5d64..3491c71 100644
--- a/src/format/elf/elf.c
+++ b/src/format/elf/elf.c
@@ -67,7 +67,7 @@ static void g_elf_format_finalize(GElfFormat *);
static const char *g_elf_format_get_target_machine(const GElfFormat *);
/* Etend la définition des portions au sein d'un binaire. */
-static void g_elf_format_refine_portions(const GElfFormat *, GBinPortion *);
+static void g_elf_format_refine_portions(const GElfFormat *, GPortionLayer *);
/* Fournit l'emplacement correspondant à une position physique. */
static bool g_elf_format_translate_offset_into_vmpa(const GElfFormat *, phys_t, vmpa2t *);
@@ -352,7 +352,7 @@ static const char *g_elf_format_get_target_machine(const GElfFormat *format)
/******************************************************************************
* *
* Paramètres : format = informations chargées à consulter. *
-* raw = portion de binaire brut à raffiner. *
+* main = couche de portions principale à raffiner. *
* *
* Description : Etend la définition des portions au sein d'un binaire. *
* *
@@ -362,8 +362,9 @@ static const char *g_elf_format_get_target_machine(const GElfFormat *format)
* *
******************************************************************************/
-static void g_elf_format_refine_portions(const GElfFormat *format, GBinPortion *raw)
+static void g_elf_format_refine_portions(const GElfFormat *format, GPortionLayer *main)
{
+ GPortionLayer *layer; /* Couche à mettre en place */
uint16_t i; /* Boucle de parcours */
off_t offset; /* Début de part de programme */
elf_phdr phdr; /* En-tête de programme ELF */
@@ -381,7 +382,10 @@ static void g_elf_format_refine_portions(const GElfFormat *format, GBinPortion *
/* Côté segments basiques */
-#if 0
+ layer = g_portion_layer_new(NO_LENGTH_YET, _("Segment"));
+
+ g_portion_layer_attach_sub(main, layer);
+
for (i = 0; i < ELF_HDR(format, format->header, e_phnum); i++)
{
offset = ELF_HDR(format, format->header, e_phoff)
@@ -414,10 +418,9 @@ static void g_elf_format_refine_portions(const GElfFormat *format, GBinPortion *
g_binary_portion_set_rights(new, rights);
- g_binary_portion_include(raw, new);
+ g_portion_layer_include(layer, new);
}
-#endif
/* Inclusion des sections, si possible... */
@@ -425,6 +428,10 @@ static void g_elf_format_refine_portions(const GElfFormat *format, GBinPortion *
ELF_HDR(format, format->header, e_shstrndx),
&strings);
+ layer = g_portion_layer_new(NO_LENGTH_YET, _("Section"));
+
+ g_portion_layer_attach_sub(main, layer);
+
for (i = 0; i < ELF_HDR(format, format->header, e_shnum); i++)
{
if (!find_elf_section_by_index(format, i, &section))
@@ -432,9 +439,6 @@ static void g_elf_format_refine_portions(const GElfFormat *format, GBinPortion *
sh_flags = ELF_SHDR(format, section, sh_flags);
- printf("[section % 2hu] 0x%08x -> %x -> %d\n", i, sh_flags,
- sh_flags & SHF_ALLOC, (sh_flags & SHF_ALLOC) == 0);
-
if ((sh_flags & SHF_ALLOC) == 0)
continue;
@@ -466,7 +470,7 @@ static void g_elf_format_refine_portions(const GElfFormat *format, GBinPortion *
g_binary_portion_set_rights(new, rights);
- g_binary_portion_include(raw, new);
+ g_portion_layer_include(layer, new);
}
diff --git a/src/format/executable-int.h b/src/format/executable-int.h
index 4b86092..5e57133 100644
--- a/src/format/executable-int.h
+++ b/src/format/executable-int.h
@@ -36,7 +36,7 @@
typedef const char * (* get_target_machine_fc) (const GExeFormat *);
/* Etend la définition des portions au sein d'un binaire. */
-typedef void (* refine_portions_fc) (const GExeFormat *, GBinPortion *);
+typedef void (* refine_portions_fc) (const GExeFormat *, GPortionLayer *);
/* Fournit l'emplacement correspondant à une position physique. */
typedef bool (* translate_phys_fc) (const GExeFormat *, phys_t, vmpa2t *);
@@ -57,7 +57,7 @@ struct _GExeFormat
GDbgFormat **debugs; /* Informations de débogage */
size_t debugs_count; /* Nombre de ces informations */
- GBinPortion *portions; /* Morceaux binaires distincts */
+ GPortionLayer *layers; /* Couches de morceaux binaires*/
};
diff --git a/src/format/executable.c b/src/format/executable.c
index 325dc8b..fc34fa0 100644
--- a/src/format/executable.c
+++ b/src/format/executable.c
@@ -163,11 +163,6 @@ GDbgFormat *g_exe_format_get_debug_info(const GExeFormat *format, size_t index)
}
-
-
-
-
-
/******************************************************************************
* *
* Paramètres : format = informations chargées à consulter. *
@@ -191,89 +186,50 @@ const char *g_exe_format_get_target_machine(const GExeFormat *format)
* *
* Paramètres : format = description de l'exécutable à consulter. *
* *
-* Description : Décrit les différentes portions qui composent le binaire. *
+* Description : Fournit la première couche des portions composent le binaire.*
* *
-* Retour : Défintions de zones. *
+* Retour : Couche brute des différentes portions. *
* *
-* Remarques : - *
+* Remarques : Le compteur de références de l'instance renvoyée doit être *
+* décrémenté après usage. *
* *
******************************************************************************/
-GBinPortion *g_exe_format_get_portions(GExeFormat *format)
+GPortionLayer *g_exe_format_get_main_layer(GExeFormat *format)
{
+ GBinPortion *portion; /* Portion brute globale */
vmpa2t addr; /* Emplacement vide de sens */
phys_t length; /* Taille de portion globale */
+ GPortionLayer *layer; /* Couche à mettre en place */
- if (format->portions == NULL)
+ if (format->layers == NULL)
{
- format->portions = g_binary_portion_new(BPC_RAW);
+ /* Création d'une portion globale */
+
+ portion = g_binary_portion_new(BPC_RAW);
init_vmpa(&addr, 0, VMPA_NO_VIRTUAL);
length = g_binary_content_compute_size(G_BIN_FORMAT(format)->content);
- g_binary_portion_set_values(format->portions, &addr, length);
+ g_binary_portion_set_values(portion, &addr, length);
- G_EXE_FORMAT_GET_CLASS(format)->refine_portions(format, format->portions);
+ /* Création d'une couche de base brute */
- }
+ layer = g_portion_layer_new(length, NULL);
- return format->portions;
+ g_portion_layer_include(layer, portion);
-}
+ /* Remplissage */
+ G_EXE_FORMAT_GET_CLASS(format)->refine_portions(format, layer);
-/******************************************************************************
-* *
-* Paramètres : format = description de l'exécutable à consulter. *
-* level = étage des portions à considérer ou -1 pour tous. *
-* count = nombre de portions trouvées et renvoyées. [OUT] *
-* *
-* Description : Fournit une liste choisie de portions d'un binaire. *
-* *
-* Retour : Liste de définitins de zones à libérer après usage. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-GBinPortion **g_exe_format_get_portions_at_level(GExeFormat *format, unsigned int level, size_t *count)
-{
- GBinPortion **result; /* Liste à retourner */
-
- typedef struct _portions_list
- {
- unsigned int required;
- GBinPortion **portions;
- size_t length;
-
- } portions_list;
-
- portions_list list; /* Sauvegarde de la liste */
-
- bool visit_for_level(GBinPortion *portion, portions_list *list)
- {
- if (list->required == -1 || g_binary_portion_get_level(portion) == list->required)
- {
- list->portions = (GBinPortion **)realloc(list->portions, ++list->length * sizeof(GBinPortion *));
- list->portions[list->length - 1] = portion;
- }
-
- return true;
+ format->layers = layer;
}
- list.required = level;
- list.portions = NULL;
- list.length = 0;
+ g_object_ref(G_OBJECT(format->layers));
- g_binary_portion_visit(g_exe_format_get_portions(format), (visit_portion_fc)visit_for_level, &list);
-
- result = list.portions;
- *count = list.length;
-
- qsort(result, *count, sizeof(GBinPortion *), (__compar_fn_t)g_binary_portion_compare);
-
- return result;
+ return format->layers;
}
@@ -303,6 +259,7 @@ mrange_t *g_exe_format_get_x_ranges(GExeFormat *format, size_t *count)
} x_ranges;
x_ranges tmp; /* Sauvegarde de la liste */
+ GPortionLayer *layer; /* Couche première de portions */
bool visit_for_x(GBinPortion *portion, x_ranges *ranges)
{
@@ -324,7 +281,9 @@ mrange_t *g_exe_format_get_x_ranges(GExeFormat *format, size_t *count)
tmp.list = NULL;
tmp.length = 0;
- g_binary_portion_visit(g_exe_format_get_portions(format), (visit_portion_fc)visit_for_x, &tmp);
+ layer = g_exe_format_get_main_layer(format);
+ g_portion_layer_visit(format->layers, (visit_portion_fc)visit_for_x, &tmp);
+ g_object_unref(G_OBJECT(layer));
result = tmp.list;
*count = tmp.length;
diff --git a/src/format/executable.h b/src/format/executable.h
index 48a8139..4ca0194 100644
--- a/src/format/executable.h
+++ b/src/format/executable.h
@@ -62,15 +62,11 @@ size_t g_exe_format_count_debug_info(const GExeFormat *);
/* Fournit un format de débogage attaché à l'exécutable. */
GDbgFormat *g_exe_format_get_debug_info(const GExeFormat *, size_t);
-
/* Indique le type d'architecture visée par le format. */
const char *g_exe_format_get_target_machine(const GExeFormat *);
-/* Décrit les différentes portions qui composent le binaire. */
-GBinPortion *g_exe_format_get_portions(GExeFormat *);
-
-/* Fournit une liste choisie de portions d'un binaire. */
-GBinPortion **g_exe_format_get_portions_at_level(GExeFormat *, unsigned int, size_t *);
+/* Fournit la première couche des portions composent le binaire. */
+GPortionLayer *g_exe_format_get_main_layer(GExeFormat *);
/* Fournit les espaces mémoires des portions exécutables. */
mrange_t *g_exe_format_get_x_ranges(GExeFormat *format, size_t *count);