diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2015-12-28 23:27:12 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2015-12-28 23:27:12 (GMT) |
commit | b57e8ef5522dcbe126157fc2c50fcf879aa7d743 (patch) | |
tree | 1ecfd9de39073fee3a2c1a4afa9ce5da574b26df /src/format/executable.c | |
parent | 276b75e6e9ff99a930bd36045e55b1117bb29579 (diff) |
Defined layers to register all kinds of binary portions.
Diffstat (limited to 'src/format/executable.c')
-rw-r--r-- | src/format/executable.c | 89 |
1 files changed, 24 insertions, 65 deletions
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; |