diff options
Diffstat (limited to 'src/format')
-rw-r--r-- | src/format/Makefile.am | 24 | ||||
-rw-r--r-- | src/format/executable-int.c | 155 | ||||
-rw-r--r-- | src/format/executable-int.h | 54 | ||||
-rw-r--r-- | src/format/executable.c | 445 | ||||
-rw-r--r-- | src/format/executable.h | 84 | ||||
-rw-r--r-- | src/format/flat-int.h | 10 | ||||
-rw-r--r-- | src/format/flat.c | 125 | ||||
-rw-r--r-- | src/format/flat.h | 27 | ||||
-rw-r--r-- | src/format/known-int.h | 18 | ||||
-rw-r--r-- | src/format/known.c | 92 | ||||
-rw-r--r-- | src/format/known.h | 33 | ||||
-rw-r--r-- | src/format/program-int.h (renamed from src/format/format-int.h) | 65 | ||||
-rw-r--r-- | src/format/program.c (renamed from src/format/format.c) | 318 | ||||
-rw-r--r-- | src/format/program.h (renamed from src/format/format.h) | 122 |
14 files changed, 730 insertions, 842 deletions
diff --git a/src/format/Makefile.am b/src/format/Makefile.am index 305cd92..3ffe24e 100644 --- a/src/format/Makefile.am +++ b/src/format/Makefile.am @@ -1,23 +1,25 @@ noinst_LTLIBRARIES = libformat.la +# debuggable-int.h \ +# debuggable.h debuggable.c \ +# executable-int.c \ +# preload-int.h \ +# preload.h preload.c \ +# strsym.h strsym.c \ +# symiter.h symiter.c \ +# symbol-int.h \ +# symbol.h symbol.c + libformat_la_SOURCES = \ - debuggable-int.h \ - debuggable.h debuggable.c \ - executable-int.h executable-int.c \ + executable-int.h \ executable.h executable.c \ flat-int.h \ flat.h flat.c \ - format-int.h \ - format.h format.c \ known-int.h \ known.h known.c \ - preload-int.h \ - preload.h preload.c \ - strsym.h strsym.c \ - symiter.h symiter.c \ - symbol-int.h \ - symbol.h symbol.c + program-int.h \ + program.h program.c libformat_la_CFLAGS = $(TOOLKIT_CFLAGS) $(LIBXML_CFLAGS) diff --git a/src/format/executable-int.c b/src/format/executable-int.c deleted file mode 100644 index 0e94e74..0000000 --- a/src/format/executable-int.c +++ /dev/null @@ -1,155 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * executable-int.c - code utile aux formats d'exécutables - * - * Copyright (C) 2015-2018 Cyrille Bagard - * - * This file is part of Chrysalide. - * - * Chrysalide is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Chrysalide is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Chrysalide. If not, see <http://www.gnu.org/licenses/>. - */ - - -#include "executable-int.h" - - - -/****************************************************************************** -* * -* Paramètres : format = description de l'exécutable à consulter. * -* off = position physique à retrouver. * -* pos = position correspondante. [OUT] * -* * -* Description : Fournit l'emplacement correspondant à une position physique. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool g_exe_format_without_virt_translate_offset_into_vmpa(const GExeFormat *format, phys_t off, vmpa2t *pos) -{ - init_vmpa(pos, off, VMPA_NO_VIRTUAL); - - return true; - -} - - -/****************************************************************************** -* * -* Paramètres : format = description de l'exécutable à consulter. * -* addr = adresse virtuelle à retrouver. * -* pos = position correspondante. [OUT] * -* * -* Description : Fournit l'emplacement correspondant à une adresse virtuelle. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool g_exe_format_without_virt_translate_address_into_vmpa(const GExeFormat *format, virt_t addr, vmpa2t *pos) -{ - /** - * S'il n'y a pas de notion de mémoire virtuelle, positions physiques et - * adresses virtuelles se confondent. - * - * On reste néanmoins cohérent, et on n'utilise donc pas d'adresse virtuelle. - * - * Les sauts dans le code renvoient de façon transparente vers des positions - * physiques. - */ - - init_vmpa(pos, addr, VMPA_NO_VIRTUAL); - - return true; - -} - - -/****************************************************************************** -* * -* Paramètres : format = description de l'exécutable à consulter. * -* off = position physique à retrouver. * -* pos = position correspondante. [OUT] * -* * -* Description : Fournit l'emplacement correspondant à une position physique. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool g_exe_format_translate_offset_into_vmpa_using_portions(GExeFormat *format, phys_t off, vmpa2t *pos) -{ - bool result; /* Bilan à retourner */ - GBinPortion *portions; /* Liste de découpages */ - - portions = g_exe_format_get_portions(format); - - if (portions == NULL) - result = false; - - else - { - result = g_binary_portion_translate_offset_into_vmpa(portions, off, pos); - - g_object_unref(G_OBJECT(portions)); - - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : format = description de l'exécutable à consulter. * -* addr = adresse virtuelle à retrouver. * -* pos = position correspondante. [OUT] * -* * -* Description : Fournit l'emplacement correspondant à une adresse virtuelle. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool g_exe_format_translate_address_into_vmpa_using_portions(GExeFormat *format, virt_t addr, vmpa2t *pos) -{ - bool result; /* Bilan à retourner */ - GBinPortion *portions; /* Liste de découpages */ - - portions = g_exe_format_get_portions(format); - - if (portions == NULL) - result = false; - - else - { - result = g_binary_portion_translate_address_into_vmpa(portions, addr, pos); - - g_object_unref(G_OBJECT(portions)); - - } - - return result; - -} diff --git a/src/format/executable-int.h b/src/format/executable-int.h index 8722795..1ca1bdb 100644 --- a/src/format/executable-int.h +++ b/src/format/executable-int.h @@ -2,7 +2,7 @@ /* Chrysalide - Outil d'analyse de fichiers binaires * executable-int.h - prototypes de code utile aux formats d'exécutables * - * Copyright (C) 2009-2019 Cyrille Bagard + * Copyright (C) 2009-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -28,79 +28,65 @@ #include "executable.h" -#include "format-int.h" +#include "program-int.h" /* Indique le type d'architecture visée par le format. */ -typedef const char * (* get_target_machine_fc) (const GExeFormat *); +typedef char * (* get_target_machine_fc) (const GExecutableFormat *); /* Fournit l'adresse principale associée à un format. */ -typedef bool (* get_main_addr_fc) (GExeFormat *, vmpa2t *); +typedef bool (* get_main_addr_fc) (GExecutableFormat *, vmpa2t *); /* Etend la définition des portions au sein d'un binaire. */ -typedef void (* refine_portions_fc) (GExeFormat *); +typedef bool (* refine_portions_fc) (GExecutableFormat *); /* Fournit l'emplacement correspondant à une position physique. */ -typedef bool (* translate_phys_fc) (GExeFormat *, phys_t, vmpa2t *); +typedef bool (* translate_phys_fc) (GExecutableFormat *, phys_t, vmpa2t *); /* Fournit l'emplacement correspondant à une adresse virtuelle. */ -typedef bool (* translate_virt_fc) (GExeFormat *, virt_t, vmpa2t *); - -/* Fournit l'emplacement d'une section donnée. */ -typedef bool (* get_range_by_name_fc) (const GExeFormat *, const char *, mrange_t *); - +typedef bool (* translate_virt_fc) (GExecutableFormat *, virt_t, vmpa2t *); /* Format d'exécutable générique (instance) */ -struct _GExeFormat +struct _GExecutableFormat { - GBinFormat parent; /* A laisser en premier */ + GProgramFormat parent; /* A laisser en premier */ - GDbgFormat **debugs; /* Informations de débogage */ - size_t debugs_count; /* Nombre de ces informations */ - - GBinPortion **user_portions; /* Couches de morceaux binaires*/ - size_t user_count; /* Nombre de ces portions */ - GBinPortion *portions; /* Couches de morceaux binaires*/ - GMutex mutex; /* Accès à l'arborescence */ + GBinaryPortion *portions; /* Couches de morceaux binaires*/ }; /* Format d'exécutable générique (classe) */ -struct _GExeFormatClass +struct _GExecutableFormatClass { - GBinFormatClass parent; /* A laisser en premier */ + GProgramFormatClass parent; /* A laisser en premier */ get_target_machine_fc get_machine; /* Architecture ciblée */ + get_main_addr_fc get_main_addr; /* Obtention d'adresse première*/ refine_portions_fc refine_portions; /* Décrit les portions binaires*/ translate_phys_fc translate_phys; /* Correspondance phys -> vmpa */ translate_virt_fc translate_virt; /* Correspondance virt -> vmpa */ - get_range_by_name_fc get_range_by_name; /* Emplacement de sections */ - }; -/* Crée les portions potentiellement utiles aux traductions. */ -void g_executable_format_setup_portions(GExeFormat *, GtkStatusStack *); +/* Met en place un nouveau contenu binaire à analyser. */ +bool g_executable_format_create(GExecutableFormat *, GBinContent *); -/* Effectue les ultimes opérations de chargement d'un binaire. */ -bool g_executable_format_complete_loading(GExeFormat *, wgroup_id_t, GtkStatusStack *); +/* Fournit l'emplacement correspondant à une position physique. */ +bool g_executable_format_translate_offset_into_vmpa_without_virt(const GExecutableFormat *, phys_t, vmpa2t *); /* Fournit l'emplacement correspondant à une position physique. */ -bool g_exe_format_without_virt_translate_offset_into_vmpa(const GExeFormat *, phys_t, vmpa2t *); +bool g_executable_format_translate_offset_into_vmpa_with_portions(GExecutableFormat *, phys_t, vmpa2t *); /* Fournit l'emplacement correspondant à une adresse virtuelle. */ -bool g_exe_format_without_virt_translate_address_into_vmpa(const GExeFormat *, virt_t, vmpa2t *); - -/* Fournit l'emplacement correspondant à une position physique. */ -bool g_exe_format_translate_offset_into_vmpa_using_portions(GExeFormat *, phys_t, vmpa2t *); +bool g_executable_format_translate_address_into_vmpa_without_virt(const GExecutableFormat *, virt_t, vmpa2t *); /* Fournit l'emplacement correspondant à une adresse virtuelle. */ -bool g_exe_format_translate_address_into_vmpa_using_portions(GExeFormat *, virt_t, vmpa2t *); +bool g_executable_format_translate_address_into_vmpa_with_portions(GExecutableFormat *, virt_t, vmpa2t *); diff --git a/src/format/executable.c b/src/format/executable.c index 26c418e..d0fc3e2 100644 --- a/src/format/executable.c +++ b/src/format/executable.c @@ -27,35 +27,48 @@ #include <assert.h> #include <malloc.h> #include <stdio.h> -#include <stdlib.h> #include <i18n.h> #include "executable-int.h" -#include "format.h" #include "../core/logs.h" -#include "../plugins/pglist.h" +/* ------------------------- GESTION D'UN FORMAT EXECUTABLE ------------------------- */ + + /* Initialise la classe des formats d'exécutables génériques. */ -static void g_executable_format_class_init(GExeFormatClass *); +static void g_executable_format_class_init(GExecutableFormatClass *); /* Initialise une instance de format d'exécutable générique. */ -static void g_executable_format_init(GExeFormat *); +static void g_executable_format_init(GExecutableFormat *); /* Supprime toutes les références externes. */ -static void g_executable_format_dispose(GExeFormat *); +static void g_executable_format_dispose(GExecutableFormat *); /* Procède à la libération totale de la mémoire. */ -static void g_executable_format_finalize(GExeFormat *); +static void g_executable_format_finalize(GExecutableFormat *); + + + +/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */ + + +/* Assure l'interprétation d'un format en différé. */ +static bool g_executable_format_analyze(GExecutableFormat *); + +/* ---------------------------------------------------------------------------------- */ +/* GESTION D'UN FORMAT EXECUTABLE */ +/* ---------------------------------------------------------------------------------- */ + /* Indique le type défini pour un format d'exécutable générique. */ -G_DEFINE_TYPE(GExeFormat, g_executable_format, G_TYPE_BIN_FORMAT); +G_DEFINE_TYPE(GExecutableFormat, g_executable_format, G_TYPE_PROGRAM_FORMAT); /****************************************************************************** @@ -70,15 +83,20 @@ G_DEFINE_TYPE(GExeFormat, g_executable_format, G_TYPE_BIN_FORMAT); * * ******************************************************************************/ -static void g_executable_format_class_init(GExeFormatClass *klass) +static void g_executable_format_class_init(GExecutableFormatClass *klass) { GObjectClass *object; /* Autre version de la classe */ + GKnownFormatClass *known; /* Version de format connu */ object = G_OBJECT_CLASS(klass); object->dispose = (GObjectFinalizeFunc/* ! */)g_executable_format_dispose; object->finalize = (GObjectFinalizeFunc)g_executable_format_finalize; + known = G_KNOWN_FORMAT_CLASS(klass); + + known->analyze = (known_analyze_fc)g_executable_format_analyze; + } @@ -94,9 +112,9 @@ static void g_executable_format_class_init(GExeFormatClass *klass) * * ******************************************************************************/ -static void g_executable_format_init(GExeFormat *format) +static void g_executable_format_init(GExecutableFormat *format) { - g_mutex_init(&format->mutex); + format->portions = NULL; } @@ -113,20 +131,10 @@ static void g_executable_format_init(GExeFormat *format) * * ******************************************************************************/ -static void g_executable_format_dispose(GExeFormat *format) +static void g_executable_format_dispose(GExecutableFormat *format) { - size_t i; /* Boucle de parcours */ - - for (i = 0; i < format->debugs_count; i++) - g_clear_object(&format->debugs[i]); - - for (i = 0; i < format->user_count; i++) - g_clear_object(&format->user_portions[i]); - g_clear_object(&format->portions); - g_mutex_clear(&format->mutex); - G_OBJECT_CLASS(g_executable_format_parent_class)->dispose(G_OBJECT(format)); } @@ -144,14 +152,8 @@ static void g_executable_format_dispose(GExeFormat *format) * * ******************************************************************************/ -static void g_executable_format_finalize(GExeFormat *format) +static void g_executable_format_finalize(GExecutableFormat *format) { - if (format->debugs != NULL) - free(format->debugs); - - if (format->user_portions != NULL) - free(format->user_portions); - G_OBJECT_CLASS(g_executable_format_parent_class)->finalize(G_OBJECT(format)); } @@ -159,79 +161,66 @@ static void g_executable_format_finalize(GExeFormat *format) /****************************************************************************** * * -* Paramètres : format = informations chargées à compléter. * -* info = informations de débogage à lier. * +* Paramètres : format = description du format à initialiser pleinement. * +* content = contenu binaire à parcourir. * * * -* Description : Rajoute des informations de débogage à un exécutable. * +* Description : Met en place un nouveau contenu binaire à analyser. * * * -* Retour : - * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -void g_exe_format_add_debug_info(GExeFormat *format, GDbgFormat *info) +bool g_executable_format_create(GExecutableFormat *format, GBinContent *content) { - const char *desc; /* Description humaine associée*/ + bool result; /* Bilan à retourner */ + vmpa2t addr; /* Emplacement vide de sens */ + phys_t length; /* Taille de portion globale */ - desc = g_known_format_get_description(G_KNOWN_FORMAT(info)); + result = g_program_format_create(G_PROGRAM_FORMAT(format), content); + if (!result) goto exit; - if (desc == NULL) - log_simple_message(LMT_WARNING, _("Unnamed debug information")); - else - log_variadic_message(LMT_INFO, _("Found debug information: %s"), desc); + /* Définition de portions */ - format->debugs = realloc(format->debugs, ++format->debugs_count * sizeof(GDbgFormat *)); - - format->debugs[format->debugs_count - 1] = info; + /** + * Avant de lire l'entête du format, on ne sait pas où on se trouve ! + */ + init_vmpa(&addr, 0, VMPA_NO_VIRTUAL); -} + length = g_binary_content_compute_size(G_KNOWN_FORMAT(format)->content); + format->portions = g_binary_portion_new(&addr, length); -/****************************************************************************** -* * -* Paramètres : format = informations chargées à consulter. * -* * -* Description : Compte le nombre de formats de débogage liés à l'exécutable. * -* * -* Retour : Nombre de formats de débogage attachés. * -* * -* Remarques : - * -* * -******************************************************************************/ + exit: -size_t g_exe_format_count_debug_info(const GExeFormat *format) -{ - return format->debugs_count; + return result; } /****************************************************************************** * * -* Paramètres : format = informations chargées à consulter. * -* index = indice des informations à transmettre. * +* Paramètres : format = description du format exécutable à consulter. * * * -* Description : Fournit un format de débogage attaché à l'exécutable. * +* Description : Indique le type d'architecture visée par le format. * * * -* Retour : Informations de débogage attachées. * +* Retour : Identifiant de l'architecture ciblée par le format. * * * * Remarques : - * * * ******************************************************************************/ -GDbgFormat *g_exe_format_get_debug_info(const GExeFormat *format, size_t index) +char *g_executable_format_get_target_machine(const GExecutableFormat *format) { - GDbgFormat *result; /* Format à retourner */ + char *result; /* Désignation à retourner */ + GExecutableFormatClass *class; /* Classe de l'instance */ - if (index >= format->debugs_count) - result = NULL; + class = G_EXECUTABLE_FORMAT_GET_CLASS(format); - else - { - result = format->debugs[index]; - g_object_ref(G_OBJECT(result)); - } + result = class->get_machine(format); + + //assert(result != NULL); return result; @@ -240,56 +229,96 @@ GDbgFormat *g_exe_format_get_debug_info(const GExeFormat *format, size_t index) /****************************************************************************** * * -* Paramètres : format = informations chargées à consulter. * +* Paramètres : format = description de l'exécutable à consulter. * +* addr = adresse principale trouvée si possible. [OUT] * * * -* Description : Indique le type d'architecture visée par le format. * +* Description : Fournit l'adresse principale associée à un format. * * * -* Retour : Identifiant de l'architecture ciblée par le format. * +* Retour : Validité de l'adresse transmise. * * * * Remarques : - * * * ******************************************************************************/ -const char *g_exe_format_get_target_machine(const GExeFormat *format) +bool g_executable_format_get_main_address(GExecutableFormat *format, vmpa2t *addr) { - return G_EXE_FORMAT_GET_CLASS(format)->get_machine(format); + bool result; /* Bilan à retourner */ + GExecutableFormatClass *class; /* Classe de l'instance */ + + class = G_EXECUTABLE_FORMAT_GET_CLASS(format); + + result = class->get_main_addr(format, addr); + + return result; } /****************************************************************************** * * -* Paramètres : format = description de l'exécutable à consulter. * -* addr = adresse principale trouvée si possible. [OUT] * +* Paramètres : format = description de l'exécutable à modifier. * +* portion = portion à inclure dans les définitions du format. * +* origin = source de définition de la portion fournie. * * * -* Description : Fournit l'adresse principale associée à un format. * +* Description : Procède à l'enregistrement d'une portion dans un format. * * * -* Retour : Bilan des recherches. * +* Retour : Bilan de l'opération : true si inclusion, false sinon. * * * * Remarques : - * * * ******************************************************************************/ -bool g_exe_format_get_main_address(GExeFormat *format, vmpa2t *addr) +bool g_executable_format_include_portion(GExecutableFormat *format, GBinaryPortion *portion, const vmpa2t *origin) { bool result; /* Bilan à retourner */ - GBinFormat *base; /* Version d'instance parente */ + phys_t available; /* Taille totale du bianire */ + const mrange_t *range; /* Emplacement de la portion */ + phys_t start; /* Début de zone de la portion */ + vmpa2t no_origin; /* Emplacement inconnu */ + char *msg; /* Description d'une erreur */ + phys_t remaining; /* Taille maximale envisageable*/ + bool truncated; /* Modification faite ? */ result = false; - if (G_EXE_FORMAT_GET_CLASS(format)->get_main_addr != NULL) - result = G_EXE_FORMAT_GET_CLASS(format)->get_main_addr(format, addr); + available = g_binary_content_compute_size(G_KNOWN_FORMAT(format)->content); + + range = g_binary_portion_get_range(portion); + + start = get_phy_addr(get_mrange_addr(range)); + + if (get_mrange_length(range) == 0) + log_variadic_message(LMT_BAD_BINARY, _("The binary portion '%s' is empty and thus useless... Discarding!"), + g_binary_portion_get_desc(portion)); - if (!result) + else if (start >= available) { - base = G_BIN_FORMAT(format); + if (origin == NULL) + { + init_vmpa(&no_origin, VMPA_NO_PHYSICAL, VMPA_NO_VIRTUAL); + origin = &no_origin; + } - g_rw_lock_reader_lock(&base->pt_lock); + asprintf(&msg, _("Defined binary portion '%s' is out of the file scope... Discarding!"), + g_binary_portion_get_desc(portion)); - if (base->pt_count[DPL_ENTRY_POINT] > 0) - result = g_exe_format_translate_address_into_vmpa(format, base->start_points[DPL_ENTRY_POINT][0], addr); + //g_binary_format_add_error(G_BIN_FORMAT(format), BFE_STRUCTURE, origin, msg); - g_rw_lock_reader_unlock(&base->pt_lock); + free(msg); + + } + + else + { + remaining = available - start; + + truncated = g_binary_portion_limit_range(portion, remaining); + + if (truncated) + log_variadic_message(LMT_BAD_BINARY, _("Truncated binary portion '%s' to fit the binary content size!"), + g_binary_portion_get_desc(portion)); + + result = g_binary_portion_include(format->portions, portion); } @@ -300,54 +329,39 @@ bool g_exe_format_get_main_address(GExeFormat *format, vmpa2t *addr) /****************************************************************************** * * -* Paramètres : format = instance à traiter. * -* status = barre de statut à tenir informée. * +* Paramètres : format = description de l'exécutable à consulter. * * * -* Description : Crée les portions potentiellement utiles aux traductions. * +* Description : Fournit la première couche des portions composent le binaire.* * * -* Retour : - * +* Retour : Arborescence des différentes portions binaires. * * * -* Remarques : - * +* Remarques : Le compteur de références de l'instance renvoyée doit être * +* décrémenté après usage. * * * ******************************************************************************/ -void g_executable_format_setup_portions(GExeFormat *format, GtkStatusStack *status) +GBinaryPortion *g_executable_format_get_portions(GExecutableFormat *format) { - vmpa2t addr; /* Emplacement vide de sens */ - phys_t length; /* Taille de portion globale */ - GExeFormatClass *class; /* Classe de l'instance */ - size_t i; /* Boucle de parcours */ - - /** - * Avant de lire l'entête du format, on ne sait pas où on se trouve ! - */ - init_vmpa(&addr, 0, VMPA_NO_VIRTUAL); + GBinaryPortion *result; /* Instance à retourner */ - length = g_binary_content_compute_size(G_KNOWN_FORMAT(format)->content); - - format->portions = g_binary_portion_new(BPC_RAW, &addr, length); + result = format->portions; - class = G_EXE_FORMAT_GET_CLASS(format); + assert(result != NULL); - if (class->refine_portions != NULL) - class->refine_portions(format); + ref_object(result); - for (i = 0; i < format->user_count; i++) - { - g_object_ref(G_OBJECT(format->user_portions[i])); - g_exe_format_include_portion(format, format->user_portions[i], NULL); - } + return result; } /****************************************************************************** * * -* Paramètres : format = instance à traiter. * -* gid = groupe de travail dédié. * -* status = barre de statut à tenir informée. * +* Paramètres : format = description de l'exécutable à consulter. * +* off = position physique à retrouver. * +* pos = position correspondante. [OUT] * * * -* Description : Effectue les ultimes opérations de chargement d'un binaire. * +* Description : Fournit l'emplacement correspondant à une position physique. * * * * Retour : Bilan de l'opération. * * * @@ -355,28 +369,14 @@ void g_executable_format_setup_portions(GExeFormat *format, GtkStatusStack *stat * * ******************************************************************************/ -bool g_executable_format_complete_loading(GExeFormat *format, wgroup_id_t gid, GtkStatusStack *status) +bool g_executable_format_translate_offset_into_vmpa(GExecutableFormat *format, phys_t off, vmpa2t *pos) { - bool result; /* Bilan à faire remonter */ - size_t count; /* Qté d'infos supplémentaires */ - size_t i; /* Boucle de parcours */ - GDbgFormat *dbg; /* Informations de débogage */ - - result = true; - - attach_debug_format(format); - - count = g_exe_format_count_debug_info(format); - - for (i = 0; i < count && result; i++) - { - dbg = g_exe_format_get_debug_info(format, i); - - result = g_known_format_analyze(G_KNOWN_FORMAT(dbg), gid, status); + bool result; /* Bilan à retourner */ + GExecutableFormatClass *class; /* Classe de l'instance */ - g_object_unref(G_OBJECT(dbg)); + class = G_EXECUTABLE_FORMAT_GET_CLASS(format); - } + result = class->translate_phys(format, off, pos); return result; @@ -385,105 +385,52 @@ bool g_executable_format_complete_loading(GExeFormat *format, wgroup_id_t gid, G /****************************************************************************** * * -* Paramètres : format = description de l'exécutable à modifier. * -* portion = portion à inclure dans les définitions du format. * +* Paramètres : format = description de l'exécutable à consulter. * +* off = position physique à retrouver. * +* pos = position correspondante. [OUT] * * * -* Description : Enregistre une portion artificielle pour le format. * +* Description : Fournit l'emplacement correspondant à une position physique. * * * -* Retour : - * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -void g_exe_format_register_user_portion(GExeFormat *format, GBinPortion *portion) +bool g_executable_format_translate_offset_into_vmpa_without_virt(const GExecutableFormat *format, phys_t off, vmpa2t *pos) { - g_mutex_lock(&format->mutex); + init_vmpa(pos, off, VMPA_NO_VIRTUAL); - format->user_portions = realloc(format->user_portions, ++format->user_count * sizeof(GBinPortion *)); - - format->user_portions[format->user_count - 1] = portion; - - g_mutex_unlock(&format->mutex); + return true; } /****************************************************************************** * * -* Paramètres : format = description de l'exécutable à modifier. * -* portion = portion à inclure dans les définitions du format. * -* origin = source de définition de la portion fournie. * +* Paramètres : format = description de l'exécutable à consulter. * +* off = position physique à retrouver. * +* pos = position correspondante. [OUT] * * * -* Description : Procède à l'enregistrement d'une portion dans un format. * +* Description : Fournit l'emplacement correspondant à une position physique. * * * -* Retour : - * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -void g_exe_format_include_portion(GExeFormat *format, GBinPortion *portion, const vmpa2t *origin) +bool g_executable_format_translate_offset_into_vmpa_with_portions(GExecutableFormat *format, phys_t off, vmpa2t *pos) { - phys_t available; /* Taille totale du bianire */ - const mrange_t *range; /* Emplacement de la portion */ - phys_t start; /* Début de zone de la portion */ - vmpa2t no_origin; /* Emplacement inconnu */ - char *msg; /* Description d'une erreur */ - phys_t remaining; /* Taille maximale envisageable*/ - bool truncated; /* Modification faite ? */ - - available = g_binary_content_compute_size(G_KNOWN_FORMAT(format)->content); - - range = g_binary_portion_get_range(portion); - - start = get_phy_addr(get_mrange_addr(range)); - - if (get_mrange_length(range) == 0) - { - log_variadic_message(LMT_BAD_BINARY, _("The binary portion '%s' is empty and thus useless... Discarding!"), - g_binary_portion_get_desc(portion)); - - g_object_unref(G_OBJECT(portion)); - - } - - else if (start >= available) - { - if (origin == NULL) - { - init_vmpa(&no_origin, VMPA_NO_PHYSICAL, VMPA_NO_VIRTUAL); - origin = &no_origin; - } - - asprintf(&msg, _("Defined binary portion '%s' is out of the file scope... Discarding!"), - g_binary_portion_get_desc(portion)); - - g_binary_format_add_error(G_BIN_FORMAT(format), BFE_STRUCTURE, origin, msg); - - free(msg); - - g_object_unref(G_OBJECT(portion)); + bool result; /* Bilan à retourner */ - } + if (format->portions == NULL) + result = false; else - { - remaining = available - start; - - truncated = g_binary_portion_limit_range(portion, remaining); - - if (truncated) - log_variadic_message(LMT_BAD_BINARY, _("Truncated binary portion '%s' to fit the binary content size!"), - g_binary_portion_get_desc(portion)); + result = g_binary_portion_translate_offset_into_vmpa(format->portions, off, pos); - g_mutex_lock(&format->mutex); - - g_binary_portion_include(format->portions, portion); - - g_mutex_unlock(&format->mutex); - - } + return result; } @@ -491,28 +438,25 @@ void g_exe_format_include_portion(GExeFormat *format, GBinPortion *portion, cons /****************************************************************************** * * * Paramètres : format = description de l'exécutable à consulter. * +* addr = adresse virtuelle à retrouver. * +* pos = position correspondante. [OUT] * * * -* Description : Fournit la première couche des portions composent le binaire.* +* Description : Fournit l'emplacement correspondant à une adresse virtuelle. * * * -* Retour : Arborescence des différentes portions binaires. * +* Retour : Bilan de l'opération. * * * -* Remarques : Le compteur de références de l'instance renvoyée doit être * -* décrémenté après usage. * +* Remarques : - * * * ******************************************************************************/ -GBinPortion *g_exe_format_get_portions(GExeFormat *format) +bool g_executable_format_translate_address_into_vmpa(GExecutableFormat *format, virt_t addr, vmpa2t *pos) { - GBinPortion *result; /* Instance à retourner */ - - g_mutex_lock(&format->mutex); - - result = format->portions; + bool result; /* Bilan à retourner */ + GExecutableFormatClass *class; /* Classe de l'instance */ - if (result != NULL) - g_object_ref(G_OBJECT(result)); + class = G_EXECUTABLE_FORMAT_GET_CLASS(format); - g_mutex_unlock(&format->mutex); + result = class->translate_virt(format, addr, pos); return result; @@ -522,10 +466,10 @@ GBinPortion *g_exe_format_get_portions(GExeFormat *format) /****************************************************************************** * * * Paramètres : format = description de l'exécutable à consulter. * -* off = position physique à retrouver. * +* addr = adresse virtuelle à retrouver. * * pos = position correspondante. [OUT] * * * -* Description : Fournit l'emplacement correspondant à une position physique. * +* Description : Fournit l'emplacement correspondant à une adresse virtuelle. * * * * Retour : Bilan de l'opération. * * * @@ -533,13 +477,21 @@ GBinPortion *g_exe_format_get_portions(GExeFormat *format) * * ******************************************************************************/ -bool g_exe_format_translate_offset_into_vmpa(GExeFormat *format, phys_t off, vmpa2t *pos) +bool g_executable_format_translate_address_into_vmpa_without_virt(const GExecutableFormat *format, virt_t addr, vmpa2t *pos) { - bool result; /* Bilan à retourner */ + /** + * S'il n'y a pas de notion de mémoire virtuelle, positions physiques et + * adresses virtuelles se confondent. + * + * On reste néanmoins cohérent, et on n'utilise donc pas d'adresse virtuelle. + * + * Les sauts dans le code renvoient de façon transparente vers des positions + * physiques. + */ - result = G_EXE_FORMAT_GET_CLASS(format)->translate_phys(format, off, pos); + init_vmpa(pos, addr, VMPA_NO_VIRTUAL); - return result; + return true; } @@ -558,24 +510,32 @@ bool g_exe_format_translate_offset_into_vmpa(GExeFormat *format, phys_t off, vmp * * ******************************************************************************/ -bool g_exe_format_translate_address_into_vmpa(GExeFormat *format, virt_t addr, vmpa2t *pos) +bool g_executable_format_translate_address_into_vmpa_with_portions(GExecutableFormat *format, virt_t addr, vmpa2t *pos) { bool result; /* Bilan à retourner */ - result = G_EXE_FORMAT_GET_CLASS(format)->translate_virt(format, addr, pos); + if (format->portions == NULL) + result = false; + + else + result = g_binary_portion_translate_address_into_vmpa(format->portions, addr, pos); return result; } + +/* ---------------------------------------------------------------------------------- */ +/* IMPLEMENTATION DES FONCTIONS DE CLASSE */ +/* ---------------------------------------------------------------------------------- */ + + /****************************************************************************** * * -* Paramètres : format = description de l'exécutable à consulter. * -* name = nom de la section recherchée. * -* range = emplacement en mémoire à renseigner. [OUT] * +* Paramètres : format = format chargé dont l'analyse est lancée. * * * -* Description : Fournit l'emplacement d'une section donnée. * +* Description : Assure l'interprétation d'un format en différé. * * * * Retour : Bilan de l'opération. * * * @@ -583,18 +543,17 @@ bool g_exe_format_translate_address_into_vmpa(GExeFormat *format, virt_t addr, v * * ******************************************************************************/ -bool g_exe_format_get_section_range_by_name(const GExeFormat *format, const char *name, mrange_t *range) +static bool g_executable_format_analyze(GExecutableFormat *format) { bool result; /* Bilan à retourner */ - GExeFormatClass *class; /* Classe de l'instance */ + GExecutableFormatClass *class; /* Classe de l'instance */ - class = G_EXE_FORMAT_GET_CLASS(format); - - if (class->get_range_by_name == NULL) - result = false; + class = G_EXECUTABLE_FORMAT_GET_CLASS(format); + if (class->refine_portions != NULL) + result = class->refine_portions(format); else - result = class->get_range_by_name(format, name, range); + result = true; return result; diff --git a/src/format/executable.h b/src/format/executable.h index 4f5abc7..da71d66 100644 --- a/src/format/executable.h +++ b/src/format/executable.h @@ -2,7 +2,7 @@ /* Chrysalide - Outil d'analyse de fichiers binaires * executable.h - prototypes pour le support des formats d'exécutables * - * Copyright (C) 2009-2019 Cyrille Bagard + * Copyright (C) 2009-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -25,88 +25,56 @@ #define _FORMAT_EXECUTABLE_H -#include <glib-object.h> +#include <stdbool.h> -#include "debuggable.h" -#include "../glibext/gbinportion.h" +#include "../glibext/helpers.h" +#include "../glibext/portion.h" -#define G_TYPE_EXE_FORMAT g_executable_format_get_type() -#define G_EXE_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_EXE_FORMAT, GExeFormat)) -#define G_IS_EXE_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_EXE_FORMAT)) -#define G_EXE_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_EXE_FORMAT, GExeFormatClass)) -#define G_IS_EXE_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_EXE_FORMAT)) -#define G_EXE_FORMAT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_EXE_FORMAT, GExeFormatClass)) +#define G_TYPE_EXECUTABLE_FORMAT (g_executable_format_get_type()) +DECLARE_GTYPE(GExecutableFormat, g_executable_format, G, EXECUTABLE_FORMAT); -/* Format d'exécutable générique (instance) */ -typedef struct _GExeFormat GExeFormat; - -/* Format d'exécutable générique (classe) */ -typedef struct _GExeFormatClass GExeFormatClass; - - -/* Indique le type défini pour un format d'exécutable générique. */ -GType g_executable_format_get_type(void); - -/* Rajoute des informations de débogage à un exécutable. */ -void g_exe_format_add_debug_info(GExeFormat *, GDbgFormat *); - -/* Compte le nombre de formats de débogage liés à l'exécutable. */ -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 *); +char *g_executable_format_get_target_machine(const GExecutableFormat *); /* Fournit l'adresse principale associée à un format. */ -bool g_exe_format_get_main_address(GExeFormat *, vmpa2t *); - -/* Enregistre une portion artificielle pour le format. */ -void g_exe_format_register_user_portion(GExeFormat *, GBinPortion *); +bool g_executable_format_get_main_address(GExecutableFormat *, vmpa2t *); /* Procède à l'enregistrement d'une portion dans un format. */ -void g_exe_format_include_portion(GExeFormat *, GBinPortion *, const vmpa2t *); +bool g_executable_format_include_portion(GExecutableFormat *, GBinaryPortion *, const vmpa2t *); /* Fournit la première couche des portions composent le binaire. */ -GBinPortion *g_exe_format_get_portions(GExeFormat *); - -/* Fournit les espaces mémoires des portions exécutables. */ -mrange_t *g_exe_format_get_x_ranges(GExeFormat *, size_t *); +GBinaryPortion *g_executable_format_get_portions(GExecutableFormat *); /* Fournit l'emplacement correspondant à une position physique. */ -bool g_exe_format_translate_offset_into_vmpa(GExeFormat *, phys_t, vmpa2t *); +bool g_executable_format_translate_offset_into_vmpa(GExecutableFormat *, phys_t, vmpa2t *); /* Fournit l'emplacement correspondant à une position physique. */ -bool g_exe_format_translate_address_into_vmpa(GExeFormat *, virt_t, vmpa2t *); +bool g_executable_format_translate_address_into_vmpa(GExecutableFormat *, virt_t, vmpa2t *); -#define g_exe_format_translate_offset_into_address(fmt, off, addr) \ - ({ \ - bool __result; \ - vmpa2t __pos; \ - __result = g_exe_format_translate_offset_into_vmpa(fmt, off, &__pos); \ - *addr = get_virt_addr(&__pos); \ - __result; \ +#define g_executable_format_translate_offset_into_address(fmt, off, addr) \ + ({ \ + bool __result; \ + vmpa2t __pos; \ + __result = g_executable_format_translate_offset_into_vmpa(fmt, off, &__pos); \ + *addr = get_virt_addr(&__pos); \ + __result; \ }) -#define g_exe_format_translate_address_into_offset(fmt, addr, off) \ - ({ \ - bool __result; \ - vmpa2t __pos; \ - __result = g_exe_format_translate_address_into_vmpa(fmt, addr, &__pos); \ - *off = get_phy_addr(&__pos); \ - __result; \ +#define g_executable_format_translate_address_into_offset(fmt, addr, off) \ + ({ \ + bool __result; \ + vmpa2t __pos; \ + __result = g_executable_format_translate_address_into_vmpa(fmt, addr, &__pos); \ + *off = get_phy_addr(&__pos); \ + __result; \ }) -/* Fournit l'emplacement d'une section donnée. */ -bool g_exe_format_get_section_range_by_name(const GExeFormat *, const char *, mrange_t *); - - #endif /* _FORMAT_EXECUTABLE_H */ diff --git a/src/format/flat-int.h b/src/format/flat-int.h index d785e5f..f858ba3 100644 --- a/src/format/flat-int.h +++ b/src/format/flat-int.h @@ -2,7 +2,7 @@ /* Chrysalide - Outil d'analyse de fichiers binaires * flat-int.h - prototypes de code utile aux formats d'exécutables à plat * - * Copyright (C) 2018 Cyrille Bagard + * Copyright (C) 2018-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -35,7 +35,7 @@ /* Format d'exécutable à plat (instance) */ struct _GFlatFormat { - GExeFormat parent; /* A laisser en premier */ + GExecutableFormat parent; /* A laisser en premier */ char *machine; /* Architecture imposée */ SourceEndian endian; /* Boutisme imposé */ @@ -45,10 +45,14 @@ struct _GFlatFormat /* Format d'exécutable à plat (classe) */ struct _GFlatFormatClass { - GExeFormatClass parent; /* A laisser en premier */ + GExecutableFormatClass parent; /* A laisser en premier */ }; +/* Met en place une nouvelle instance de format à plat. */ +bool g_flat_format_create(GFlatFormat *, GBinContent *, const char *, SourceEndian); + + #endif /* _FORMAT_FLAT_INT_H */ diff --git a/src/format/flat.c b/src/format/flat.c index 6b8b074..51f37fa 100644 --- a/src/format/flat.c +++ b/src/format/flat.c @@ -2,7 +2,7 @@ /* Chrysalide - Outil d'analyse de fichiers binaires * flat.c - support des formats à plat * - * Copyright (C) 2018-2019 Cyrille Bagard + * Copyright (C) 2018-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -32,6 +32,9 @@ +/* ------------------------- DEFINITION D'UN NOUVEAU FORMAT ------------------------- */ + + /* Initialise la classe des formats d'exécutables à plat. */ static void g_flat_format_class_init(GFlatFormatClass *); @@ -44,28 +47,39 @@ static void g_flat_format_dispose(GFlatFormat *); /* Procède à la libération totale de la mémoire. */ static void g_flat_format_finalize(GFlatFormat *); + + +/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */ + + /* Indique la désignation interne du format. */ static char *g_flat_format_get_key(const GFlatFormat *); /* Fournit une description humaine du format. */ static char *g_flat_format_get_description(const GFlatFormat *); -/* Assure l'interprétation d'un format en différé. */ -static bool g_flat_format_analyze(GFlatFormat *, wgroup_id_t, GtkStatusStack *); - /* Informe quant au boutisme utilisé. */ static SourceEndian g_flat_format_get_endianness(const GFlatFormat *); /* Indique le type d'architecture visée par le format. */ -static const char *g_flat_format_get_target_machine(const GFlatFormat *); +static char *g_flat_format_get_target_machine(const GFlatFormat *); + +#if 0 /* Fournit l'adresse principale associée à un format à plat. */ static bool g_flat_format_get_main_address(GFlatFormat *, vmpa2t *); +#endif + + + +/* ---------------------------------------------------------------------------------- */ +/* DEFINITION D'UN NOUVEAU FORMAT */ +/* ---------------------------------------------------------------------------------- */ /* Indique le type défini pour un format d'exécutable à plat. */ -G_DEFINE_TYPE(GFlatFormat, g_flat_format, G_TYPE_EXE_FORMAT); +G_DEFINE_TYPE(GFlatFormat, g_flat_format, G_TYPE_EXECUTABLE_FORMAT); /****************************************************************************** @@ -84,8 +98,8 @@ static void g_flat_format_class_init(GFlatFormatClass *klass) { GObjectClass *object; /* Autre version de la classe */ GKnownFormatClass *known; /* Version de format connu */ - GBinFormatClass *fmt; /* Version en format basique */ - GExeFormatClass *exe; /* Version en exécutable */ + GProgramFormatClass *prgm; /* Version en format basique */ + GExecutableFormatClass *exe; /* Version en exécutable */ object = G_OBJECT_CLASS(klass); @@ -97,19 +111,18 @@ static void g_flat_format_class_init(GFlatFormatClass *klass) known->get_key = (known_get_key_fc)g_flat_format_get_key; known->get_desc = (known_get_desc_fc)g_flat_format_get_description; - known->analyze = (known_analyze_fc)g_flat_format_analyze; - - fmt = G_BIN_FORMAT_CLASS(klass); + prgm = G_PROGRAM_FORMAT_CLASS(klass); - fmt->get_endian = (format_get_endian_fc)g_flat_format_get_endianness; + prgm->get_endian = (program_get_endian_fc)g_flat_format_get_endianness; - exe = G_EXE_FORMAT_CLASS(klass); + exe = G_EXECUTABLE_FORMAT_CLASS(klass); exe->get_machine = (get_target_machine_fc)g_flat_format_get_target_machine; +#if 0 exe->get_main_addr = (get_main_addr_fc)g_flat_format_get_main_address; - - exe->translate_phys = (translate_phys_fc)g_exe_format_translate_offset_into_vmpa_using_portions; - exe->translate_virt = (translate_virt_fc)g_exe_format_translate_address_into_vmpa_using_portions; +#endif + exe->translate_phys = g_executable_format_translate_offset_into_vmpa_with_portions; + exe->translate_virt = g_executable_format_translate_address_into_vmpa_with_portions; } @@ -178,8 +191,10 @@ static void g_flat_format_finalize(GFlatFormat *format) /****************************************************************************** * * * Paramètres : content = contenu binaire à parcourir. * +* machine = architecture déterminée pour le code. * + endian = boutisme à observer pour les données. * * * -* Description : Prend en charge un nouveau format à plat. * +* Description : Crée une nouvelle instance de format à plat. * * * * Retour : Adresse de la structure mise en place ou NULL en cas d'échec.* * * @@ -187,62 +202,72 @@ static void g_flat_format_finalize(GFlatFormat *format) * * ******************************************************************************/ -GExeFormat *g_flat_format_new(GBinContent *content, const char *machine, SourceEndian endian) +GFlatFormat *g_flat_format_new(GBinContent *content, const char *machine, SourceEndian endian) { GFlatFormat *result; /* Structure à retourner */ result = g_object_new(G_TYPE_FLAT_FORMAT, NULL); - g_known_format_set_content(G_KNOWN_FORMAT(result), content); + if (!g_flat_format_create(result, content, machine, endian)) + g_clear_object(&result); - result->machine = strdup(machine); - result->endian = endian; - - return G_EXE_FORMAT(result); + return result; } /****************************************************************************** * * -* Paramètres : format = description de l'exécutable à consulter. * +* Paramètres : format = description du format connu à consulter. * +* content = contenu binaire à parcourir. * +* machine = architecture déterminée pour le code. * + endian = boutisme à observer pour les données. * * * -* Description : Indique la désignation interne du format. * +* Description : Met en place une nouvelle instance de format à plat. * * * -* Retour : Désignation du format. * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -static char *g_flat_format_get_key(const GFlatFormat *format) +bool g_flat_format_create(GFlatFormat *format, GBinContent *content, const char *machine, SourceEndian endian) { - char *result; /* Désignation à retourner */ + bool result; /* Bilan à retourner */ - result = strdup("flat"); + result = g_executable_format_create(G_EXECUTABLE_FORMAT(format), content); + + format->machine = strdup(machine); + format->endian = endian; return result; } + +/* ---------------------------------------------------------------------------------- */ +/* IMPLEMENTATION DES FONCTIONS DE CLASSE */ +/* ---------------------------------------------------------------------------------- */ + + /****************************************************************************** * * * Paramètres : format = description de l'exécutable à consulter. * * * -* Description : Fournit une description humaine du format. * +* Description : Indique la désignation interne du format. * * * -* Retour : Description du format. * +* Retour : Désignation du format. * * * * Remarques : - * * * ******************************************************************************/ -static char *g_flat_format_get_description(const GFlatFormat *format) +static char *g_flat_format_get_key(const GFlatFormat *format) { char *result; /* Désignation à retourner */ - result = strdup("Flat executable format"); + result = strdup("flat"); return result; @@ -251,25 +276,21 @@ static char *g_flat_format_get_description(const GFlatFormat *format) /****************************************************************************** * * -* Paramètres : format = format chargé dont l'analyse est lancée. * -* gid = groupe de travail dédié. * -* status = barre de statut à tenir informée. * +* Paramètres : format = description de l'exécutable à consulter. * * * -* Description : Assure l'interprétation d'un format en différé. * +* Description : Fournit une description humaine du format. * * * -* Retour : Bilan de l'opération. * +* Retour : Description du format. * * * * Remarques : - * * * ******************************************************************************/ -static bool g_flat_format_analyze(GFlatFormat *format, wgroup_id_t gid, GtkStatusStack *status) +static char *g_flat_format_get_description(const GFlatFormat *format) { - bool result; /* Bilan à retourner */ - - result = true; + char *result; /* Désignation à retourner */ - g_executable_format_setup_portions(G_EXE_FORMAT(format), status); + result = strdup("Flat executable format"); return result; @@ -290,14 +311,18 @@ static bool g_flat_format_analyze(GFlatFormat *format, wgroup_id_t gid, GtkStatu static SourceEndian g_flat_format_get_endianness(const GFlatFormat *format) { - return format->endian; + SourceEndian result; /* Valeur à retourner */ + + result = format->endian; + + return result; } /****************************************************************************** * * -* Paramètres : format = informations chargées à consulter. * +* Paramètres : format = description du format exécutable à consulter. * * * * Description : Indique le type d'architecture visée par le format. * * * @@ -307,17 +332,17 @@ static SourceEndian g_flat_format_get_endianness(const GFlatFormat *format) * * ******************************************************************************/ -static const char *g_flat_format_get_target_machine(const GFlatFormat *format) +static char *g_flat_format_get_target_machine(const GFlatFormat *format) { - const char *result; /* Identifiant à retourner */ + char *result; /* Identifiant à retourner */ - result = format->machine; + result = strdup(format->machine); return result; } - +#if 0 /****************************************************************************** * * * Paramètres : format = description de l'exécutable à consulter. * @@ -350,3 +375,5 @@ static bool g_flat_format_get_main_address(GFlatFormat *format, vmpa2t *addr) return result; } + +#endif diff --git a/src/format/flat.h b/src/format/flat.h index 83c5e3c..2168221 100644 --- a/src/format/flat.h +++ b/src/format/flat.h @@ -2,7 +2,7 @@ /* Chrysalide - Outil d'analyse de fichiers binaires * flat.h - prototypes pour le support des formats à plat * - * Copyright (C) 2018 Cyrille Bagard + * Copyright (C) 2018-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -25,34 +25,19 @@ #define _FORMAT_FLAT_H -#include <glib-object.h> - - -#include "executable.h" #include "../analysis/content.h" +#include "../glibext/helpers.h" -#define G_TYPE_FLAT_FORMAT g_flat_format_get_type() -#define G_FLAT_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_FLAT_FORMAT, GFlatFormat)) -#define G_IS_FLAT_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_FLAT_FORMAT)) -#define G_FLAT_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_FLAT_FORMAT, GFlatFormatClass)) -#define G_IS_FLAT_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_FLAT_FORMAT)) -#define G_FLAT_FORMAT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_FLAT_FORMAT, GFlatFormatClass)) - - -/* Format d'exécutable à plat (instance) */ -typedef struct _GFlatFormat GFlatFormat; +#define G_TYPE_FLAT_FORMAT (g_flat_format_get_type()) -/* Format d'exécutable à plat (classe) */ -typedef struct _GFlatFormatClass GFlatFormatClass; +DECLARE_GTYPE(GFlatFormat, g_flat_format, G, FLAT_FORMAT); -/* Indique le type défini pour un format d'exécutable à plat. */ -GType g_flat_format_get_type(void); -/* Prend en charge un nouveau format à plat. */ -GExeFormat *g_flat_format_new(GBinContent *, const char *, SourceEndian); +/* Crée une nouvelle instance de format à plat. */ +GFlatFormat *g_flat_format_new(GBinContent *, const char *, SourceEndian); diff --git a/src/format/known-int.h b/src/format/known-int.h index 3328a96..75d0dab 100644 --- a/src/format/known-int.h +++ b/src/format/known-int.h @@ -2,7 +2,7 @@ /* Chrysalide - Outil d'analyse de fichiers binaires * known-int.h - prototypes utiles aux formats binaires reconnus * - * Copyright (C) 2019 Cyrille Bagard + * Copyright (C) 2019-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -26,7 +26,7 @@ #include "known.h" -#include "../analysis/storage/storage.h" +//#include "../analysis/storage/storage.h" @@ -37,16 +37,15 @@ typedef char * (* known_get_key_fc) (const GKnownFormat *); typedef char * (* known_get_desc_fc) (const GKnownFormat *); /*Assure l'interprétation d'un format en différé. */ -typedef bool (* known_analyze_fc) (GKnownFormat *, wgroup_id_t, GtkStatusStack *); - -/* Réalise un traitement post-désassemblage. */ -typedef void (* known_complete_analysis_fc) (GKnownFormat *, wgroup_id_t, GtkStatusStack *); +typedef bool (* known_analyze_fc) (GKnownFormat *); +#if 0 /* Charge un format depuis une mémoire tampon. */ typedef bool (* load_known_fc) (GKnownFormat *, GObjectStorage *, packed_buffer_t *); /* Sauvegarde un format dans une mémoire tampon. */ typedef bool (* store_known_fc) (GKnownFormat *, GObjectStorage *, packed_buffer_t *); +#endif /* Format binaire générique (instance) */ @@ -67,13 +66,18 @@ struct _GKnownFormatClass known_get_desc_fc get_desc; /* Désignation humaine */ known_analyze_fc analyze; /* Interprétation du format */ - known_complete_analysis_fc complete; /* Terminaison d'analyse */ +#if 0 load_known_fc load; /* Chargement depuis un tampon */ store_known_fc store; /* Conservation dans un tampon */ +#endif }; +/* Met en place un nouveau contenu binaire à analyser. */ +bool g_known_format_create(GKnownFormat *, GBinContent *); + + #endif /* _FORMAT_KNOWN_INT_H */ diff --git a/src/format/known.c b/src/format/known.c index 7512ae1..bc03793 100644 --- a/src/format/known.c +++ b/src/format/known.c @@ -2,7 +2,7 @@ /* Chrysalide - Outil d'analyse de fichiers binaires * format.c - support des différents formats binaires reconnus * - * Copyright (C) 2019 Cyrille Bagard + * Copyright (C) 2019-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -28,8 +28,8 @@ #include "known-int.h" -#include "../analysis/storage/serialize-int.h" -#include "../plugins/pglist.h" +//#include "../analysis/storage/serialize-int.h" +//#include "../plugins/pglist.h" @@ -43,7 +43,7 @@ static void g_known_format_class_init(GKnownFormatClass *); static void g_known_format_init(GKnownFormat *); /* Procède à l'initialisation de l'interface de sérialisation. */ -static void g_known_format_serializable_init(GSerializableObjectInterface *); +//static void g_known_format_serializable_init(GSerializableObjectInterface *); /* Supprime toutes les références externes. */ static void g_known_format_dispose(GKnownFormat *); @@ -56,6 +56,7 @@ static void g_known_format_finalize(GKnownFormat *); /* -------------------- CONSERVATION ET RECHARGEMENT DES DONNEES -------------------- */ +#if 0 /* Charge un format depuis une mémoire tampon. */ static bool _g_known_format_load(GKnownFormat *, GObjectStorage *, packed_buffer_t *); @@ -67,7 +68,7 @@ static bool _g_known_format_store(GKnownFormat *, GObjectStorage *, packed_buffe /* Sauvegarde un format dans une mémoire tampon. */ static bool g_known_format_store(GKnownFormat *, GObjectStorage *, packed_buffer_t *); - +#endif /* ---------------------------------------------------------------------------------- */ @@ -76,8 +77,9 @@ static bool g_known_format_store(GKnownFormat *, GObjectStorage *, packed_buffer /* Indique le type défini pour un format binaire générique. */ -G_DEFINE_TYPE_WITH_CODE(GKnownFormat, g_known_format, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE(G_TYPE_SERIALIZABLE_OBJECT, g_known_format_serializable_init)); +//G_DEFINE_TYPE_WITH_CODE(GKnownFormat, g_known_format, G_TYPE_OBJECT, +// G_IMPLEMENT_INTERFACE(G_TYPE_SERIALIZABLE_OBJECT, g_known_format_serializable_init)); +G_DEFINE_TYPE(GKnownFormat, g_known_format, G_TYPE_OBJECT); /****************************************************************************** @@ -101,8 +103,10 @@ static void g_known_format_class_init(GKnownFormatClass *klass) object->dispose = (GObjectFinalizeFunc/* ! */)g_known_format_dispose; object->finalize = (GObjectFinalizeFunc)g_known_format_finalize; + /* klass->load = (load_known_fc)_g_known_format_load; klass->store = (store_known_fc)_g_known_format_store; + */ } @@ -126,6 +130,7 @@ static void g_known_format_init(GKnownFormat *format) } +#if 0 /****************************************************************************** * * * Paramètres : iface = interface GLib à initialiser. * @@ -144,6 +149,7 @@ static void g_known_format_serializable_init(GSerializableObjectInterface *iface iface->store = (store_serializable_object_cb)g_known_format_store; } +#endif /****************************************************************************** @@ -188,24 +194,27 @@ static void g_known_format_finalize(GKnownFormat *format) /****************************************************************************** * * -* Paramètres : format = description du format connu à consulter. * +* Paramètres : format = description du format à initialiser pleinement. * * content = contenu binaire à parcourir. * * * -* Description : Définit le contenu binaire à analyser. * +* Description : Met en place un nouveau contenu binaire à analyser. * * * -* Retour : - * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -void g_known_format_set_content(GKnownFormat *format, GBinContent *content) +bool g_known_format_create(GKnownFormat *format, GBinContent *content) { - assert(format->content == NULL); + bool result; /* Bilan à retourner */ - g_object_ref_sink(G_OBJECT(content)); + result = true; format->content = content; + ref_object(content); + + return result; } @@ -251,8 +260,13 @@ GBinContent *g_known_format_get_content(const GKnownFormat *format) char *g_known_format_get_key(const GKnownFormat *format) { char *result; /* Désignation à retourner */ + GKnownFormatClass *class; /* Classe de l'instance */ + + class = G_KNOWN_FORMAT_GET_CLASS(format); - result = G_KNOWN_FORMAT_GET_CLASS(format)->get_key(format); + result = class->get_key(format); + + //assert(result != NULL); return result; @@ -274,8 +288,13 @@ char *g_known_format_get_key(const GKnownFormat *format) char *g_known_format_get_description(const GKnownFormat *format) { char *result; /* Description à retourner */ + GKnownFormatClass *class; /* Classe de l'instance */ + + class = G_KNOWN_FORMAT_GET_CLASS(format); + + result = class->get_desc(format); - result = G_KNOWN_FORMAT_GET_CLASS(format)->get_desc(format); + //assert(result != NULL); return result; @@ -285,8 +304,6 @@ char *g_known_format_get_description(const GKnownFormat *format) /****************************************************************************** * * * Paramètres : format = format chargé dont l'analyse est lancée. * -* gid = groupe de travail dédié. * -* status = barre de statut à tenir informée. * * * * Description : Assure l'interprétation d'un format en différé. * * * @@ -296,60 +313,30 @@ char *g_known_format_get_description(const GKnownFormat *format) * * ******************************************************************************/ -bool g_known_format_analyze(GKnownFormat *format, wgroup_id_t gid, GtkStatusStack *status) +bool g_known_format_analyze(GKnownFormat *format) { bool result; /* Bilan à retourner */ GKnownFormatClass *class; /* Classe de l'instance */ - handle_known_format_analysis(PGA_FORMAT_ANALYSIS_STARTED, format, gid, status); + //handle_known_format_analysis(PGA_FORMAT_ANALYSIS_STARTED, format, gid, status); class = G_KNOWN_FORMAT_GET_CLASS(format); - result = class->analyze(format, gid, status); + result = class->analyze(format); - handle_known_format_analysis(PGA_FORMAT_ANALYSIS_ENDED, format, gid, status); + //handle_known_format_analysis(PGA_FORMAT_ANALYSIS_ENDED, format, gid, status); return result; } -/****************************************************************************** -* * -* Paramètres : format = description de l'exécutable à manipuler. * -* gid = groupe de travail dédié. * -* status = barre de statut à tenir informée. * -* * -* Description : Réalise un traitement post-désassemblage. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void g_known_format_complete_analysis(GKnownFormat *format, wgroup_id_t gid, GtkStatusStack *status) -{ - GKnownFormatClass *class; /* Classe de l'instance */ - - handle_known_format_analysis(PGA_FORMAT_POST_ANALYSIS_STARTED, format, gid, status); - - class = G_KNOWN_FORMAT_GET_CLASS(format); - - if (class->complete != NULL) - class->complete(format, gid, status); - - handle_known_format_analysis(PGA_FORMAT_POST_ANALYSIS_ENDED, format, gid, status); - -} - - /* ---------------------------------------------------------------------------------- */ /* CONSERVATION ET RECHARGEMENT DES DONNEES */ /* ---------------------------------------------------------------------------------- */ - +#if 0 /****************************************************************************** * * * Paramètres : operand = élément GLib à constuire. * @@ -468,3 +455,4 @@ static bool g_known_format_store(GKnownFormat *format, GObjectStorage *storage, return result; } +#endif diff --git a/src/format/known.h b/src/format/known.h index dcc8669..41236df 100644 --- a/src/format/known.h +++ b/src/format/known.h @@ -2,7 +2,7 @@ /* Chrysalide - Outil d'analyse de fichiers binaires * format.h - prototypes pour le support des différents formats binaires reconnus * - * Copyright (C) 2019 Cyrille Bagard + * Copyright (C) 2019-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -25,37 +25,17 @@ #define _FORMAT_KNOWN_H -#include <glib-object.h> -#include <stdbool.h> - - #include "../analysis/content.h" -#include "../glibext/delayed.h" -#include "../glibext/notifier.h" - +#include "../glibext/helpers.h" -#define G_TYPE_KNOWN_FORMAT g_known_format_get_type() -#define G_KNOWN_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_KNOWN_FORMAT, GKnownFormat)) -#define G_IS_KNOWN_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_KNOWN_FORMAT)) -#define G_KNOWN_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_KNOWN_FORMAT, GKnownFormatClass)) -#define G_IS_KNOWN_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_KNOWN_FORMAT)) -#define G_KNOWN_FORMAT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_KNOWN_FORMAT, GKnownFormatClass)) +#define G_TYPE_KNOWN_FORMAT (g_known_format_get_type()) -/* Format binaire générique (instance) */ -typedef struct _GKnownFormat GKnownFormat; +DECLARE_GTYPE(GKnownFormat, g_known_format, G, KNOWN_FORMAT); -/* Format binaire générique (classe) */ -typedef struct _GKnownFormatClass GKnownFormatClass; -/* Indique le type défini pour un format binaire générique. */ -GType g_known_format_get_type(void); - -/* Définit le contenu binaire à analyser. */ -void g_known_format_set_content(GKnownFormat *, GBinContent *); - /* Fournit une référence vers le contenu binaire analysé. */ GBinContent *g_known_format_get_content(const GKnownFormat *); @@ -66,10 +46,7 @@ char *g_known_format_get_key(const GKnownFormat *); char *g_known_format_get_description(const GKnownFormat *); /* Assure l'interprétation d'un format en différé. */ -bool g_known_format_analyze(GKnownFormat *, wgroup_id_t, GtkStatusStack *); - -/* Réalise un traitement post-désassemblage. */ -void g_known_format_complete_analysis(GKnownFormat *, wgroup_id_t, GtkStatusStack *); +bool g_known_format_analyze(GKnownFormat *); diff --git a/src/format/format-int.h b/src/format/program-int.h index f18bb24..8464fe4 100644 --- a/src/format/format-int.h +++ b/src/format/program-int.h @@ -1,8 +1,8 @@ /* Chrysalide - Outil d'analyse de fichiers binaires - * format-int.h - prototypes utiles aux formats binaires + * program-int.h - prototypes internes pour le support des différents formats de programmes * - * Copyright (C) 2009-2018 Cyrille Bagard + * Copyright (C) 2009-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -21,14 +21,59 @@ */ -#ifndef _FORMAT_FORMAT_INT_H -#define _FORMAT_FORMAT_INT_H +#ifndef _FORMAT_PROGRAM_INT_H +#define _FORMAT_PROGRAM_INT_H -#include "format.h" +#include "program.h" #include "known-int.h" + + + +/* Indique le boutisme employé par le format binaire analysé. */ +typedef SourceEndian (* program_get_endian_fc) (const GProgramFormat *); + +/* Fournit l'emplacement d'une section donnée. */ +typedef bool (* find_range_by_name_fc) (const GProgramFormat *, const char *, mrange_t *); + + +/* Format de programme générique (instance) */ +struct _GProgramFormat +{ + GKnownFormat parent; /* A laisser en premier */ + +}; + +/* Format de programme générique (classe) */ +struct _GProgramFormatClass +{ + GKnownFormatClass parent; /* A laisser en premier */ + + program_get_endian_fc get_endian; /* Boutisme employé */ + find_range_by_name_fc find_range_by_name; /* Emplacement de sections */ + +}; + + +/* Met en place un nouveau contenu binaire à analyser. */ +bool g_program_format_create(GProgramFormat *, GBinContent *); + + + + + + + + + + + + + +#if 0 + #include "preload.h" #include "../glibext/objhole.h" #include "../mangling/demangler.h" @@ -38,9 +83,6 @@ /* ------------------------ TRAITEMENT INDIVIDUEL DE FORMATS ------------------------ */ -/* Indique le boutisme employé par le format binaire analysé. */ -typedef SourceEndian (* format_get_endian_fc) (const GBinFormat *); - /* Rythme des allocations pour les entrées de code */ #define EXTRA_POINT_BLOCK 20 @@ -120,8 +162,6 @@ struct _GBinFormatClass { GKnownFormatClass parent; /* A laisser en premier */ - format_get_endian_fc get_endian; /* Boutisme employé */ - /* Signaux */ void (* symbol_added) (GBinFormat *, GBinSymbol *); @@ -156,5 +196,8 @@ GDataType *g_binary_format_decode_type(const GBinFormat *, const char *); GBinRoutine *g_binary_format_decode_routine(const GBinFormat *, const char *); +#endif + + -#endif /* _FORMAT_FORMAT_INT_H */ +#endif /* _FORMAT_PROGRAM_INT_H */ diff --git a/src/format/format.c b/src/format/program.c index d126236..9b9df81 100644 --- a/src/format/format.c +++ b/src/format/program.c @@ -1,8 +1,8 @@ /* Chrysalide - Outil d'analyse de fichiers binaires - * format.c - support des différents formats binaires + * program.c - support des différents formats de programmes * - * Copyright (C) 2009-2020 Cyrille Bagard + * Copyright (C) 2009-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -21,40 +21,45 @@ */ -#include "format.h" +#include "program.h" -#include <assert.h> -#include <malloc.h> -#include <string.h> +//#include <assert.h> +//#include <malloc.h> +//#include <string.h> -#include "format-int.h" +#include "program-int.h" + +/* #include "preload.h" #include "../arch/processor.h" #include "../common/sort.h" #include "../core/demanglers.h" #include "../plugins/pglist.h" +*/ /* Initialise la classe des formats binaires génériques. */ -static void g_binary_format_class_init(GBinFormatClass *); +static void g_program_format_class_init(GProgramFormatClass *); /* Initialise une instance de format binaire générique. */ -static void g_binary_format_init(GBinFormat *); +static void g_program_format_init(GProgramFormat *); /* Supprime toutes les références externes. */ -static void g_binary_format_dispose(GBinFormat *); +static void g_program_format_dispose(GProgramFormat *); /* Procède à la libération totale de la mémoire. */ -static void g_binary_format_finalize(GBinFormat *); +static void g_program_format_finalize(GProgramFormat *); + +#if 0 /* Charge les plages de couvertures depuis une mémoire tampon. */ -static bool g_binary_format_load_start_points(GBinFormat *, packed_buffer_t *); +static bool g_program_format_load_start_points(GProgramFormat *, packed_buffer_t *); /* Sauvegarde les points de départ enregistrés pour un format. */ -static bool g_binary_format_store_start_points(GBinFormat *, packed_buffer_t *); +static bool g_program_format_store_start_points(GProgramFormat *, packed_buffer_t *); @@ -62,13 +67,13 @@ static bool g_binary_format_store_start_points(GBinFormat *, packed_buffer_t *); /* Retire un symbole de la collection du format binaire. */ -static void _g_binary_format_remove_symbol(GBinFormat *, size_t); +static void _g_program_format_remove_symbol(GProgramFormat *, size_t); /* Recherche le symbole associé à une adresse. */ -static bool _g_binary_format_find_symbol(const GBinFormat *, const vmpa2t *, __compar_fn_t, size_t *, GBinSymbol **); +static bool _g_program_format_find_symbol(const GProgramFormat *, const vmpa2t *, __compar_fn_t, size_t *, GBinSymbol **); /* Recherche un symbole particulier. */ -static bool __g_binary_format_find_symbol(const GBinFormat *, const void *, __compar_fn_t, size_t *, GBinSymbol **); +static bool __g_program_format_find_symbol(const GProgramFormat *, const void *, __compar_fn_t, size_t *, GBinSymbol **); @@ -76,10 +81,10 @@ static bool __g_binary_format_find_symbol(const GBinFormat *, const void *, __co /* Charge les erreurs de chargement depuis une mémoire tampon. */ -static bool g_binary_format_load_errors(GBinFormat *, packed_buffer_t *); +static bool g_program_format_load_errors(GProgramFormat *, packed_buffer_t *); /* Sauvegarde les erreurs de chargement dans une mémoire tampon. */ -static bool g_binary_format_store_errors(GBinFormat *, packed_buffer_t *); +static bool g_program_format_store_errors(GProgramFormat *, packed_buffer_t *); @@ -87,17 +92,18 @@ static bool g_binary_format_store_errors(GBinFormat *, packed_buffer_t *); /* Charge un format depuis une mémoire tampon. */ -static bool g_binary_format_load(GBinFormat *, GObjectStorage *, packed_buffer_t *); +static bool g_program_format_load(GProgramFormat *, GObjectStorage *, packed_buffer_t *); /* Sauvegarde un format dans une mémoire tampon. */ -static bool g_binary_format_store(GBinFormat *, GObjectStorage *, packed_buffer_t *); +static bool g_program_format_store(GProgramFormat *, GObjectStorage *, packed_buffer_t *); +#endif /* Indique le type défini pour un format binaire générique. */ -G_DEFINE_TYPE(GBinFormat, g_binary_format, G_TYPE_KNOWN_FORMAT); +G_DEFINE_TYPE(GProgramFormat, g_program_format, G_TYPE_KNOWN_FORMAT); /****************************************************************************** @@ -112,25 +118,27 @@ G_DEFINE_TYPE(GBinFormat, g_binary_format, G_TYPE_KNOWN_FORMAT); * * ******************************************************************************/ -static void g_binary_format_class_init(GBinFormatClass *klass) +static void g_program_format_class_init(GProgramFormatClass *klass) { GObjectClass *object; /* Autre version de la classe */ - GKnownFormatClass *known; /* Version de classe parente */ + //GKnownFormatClass *known; /* Version de classe parente */ object = G_OBJECT_CLASS(klass); - object->dispose = (GObjectFinalizeFunc/* ! */)g_binary_format_dispose; - object->finalize = (GObjectFinalizeFunc)g_binary_format_finalize; + object->dispose = (GObjectFinalizeFunc/* ! */)g_program_format_dispose; + object->finalize = (GObjectFinalizeFunc)g_program_format_finalize; + +#if 0 known = G_KNOWN_FORMAT_CLASS(klass); - known->load = (load_known_fc)g_binary_format_load; - known->store = (load_known_fc)g_binary_format_store; + known->load = (load_known_fc)g_program_format_load; + known->store = (load_known_fc)g_program_format_store; g_signal_new("symbol-added", G_TYPE_BIN_FORMAT, G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(GBinFormatClass, symbol_added), + G_STRUCT_OFFSET(GProgramFormatClass, symbol_added), NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, G_TYPE_OBJECT); @@ -138,11 +146,13 @@ static void g_binary_format_class_init(GBinFormatClass *klass) g_signal_new("symbol-removed", G_TYPE_BIN_FORMAT, G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(GBinFormatClass, symbol_removed), + G_STRUCT_OFFSET(GProgramFormatClass, symbol_removed), NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, G_TYPE_OBJECT); +#endif + } @@ -158,8 +168,10 @@ static void g_binary_format_class_init(GBinFormatClass *klass) * * ******************************************************************************/ -static void g_binary_format_init(GBinFormat *format) +static void g_program_format_init(GProgramFormat *format) { + +#if 0 fmt_extra_data_t *extra; /* Données insérées à modifier */ extra = GET_BIN_FORMAT_EXTRA(format); @@ -184,6 +196,8 @@ static void g_binary_format_init(GBinFormat *format) g_atomic_int_set(&format->error_locked, 0); #endif +#endif + } @@ -199,8 +213,10 @@ static void g_binary_format_init(GBinFormat *format) * * ******************************************************************************/ -static void g_binary_format_dispose(GBinFormat *format) +static void g_program_format_dispose(GProgramFormat *format) { +#if 0 + size_t i; /* Boucle de parcours */ g_rw_lock_clear(&format->pt_lock); @@ -216,7 +232,10 @@ static void g_binary_format_dispose(GBinFormat *format) g_mutex_clear(&format->error_mutex); - G_OBJECT_CLASS(g_binary_format_parent_class)->dispose(G_OBJECT(format)); +#endif + + + G_OBJECT_CLASS(g_program_format_parent_class)->dispose(G_OBJECT(format)); } @@ -233,8 +252,10 @@ static void g_binary_format_dispose(GBinFormat *format) * * ******************************************************************************/ -static void g_binary_format_finalize(GBinFormat *format) +static void g_program_format_finalize(GProgramFormat *format) { +#if 0 + DisassPriorityLevel i; /* Boucle de parcours #1 */ size_t k; /* Boucle de parcours #2 */ @@ -255,13 +276,43 @@ static void g_binary_format_finalize(GBinFormat *format) } - G_OBJECT_CLASS(g_binary_format_parent_class)->finalize(G_OBJECT(format)); +#endif + + + + G_OBJECT_CLASS(g_program_format_parent_class)->finalize(G_OBJECT(format)); } /****************************************************************************** * * +* Paramètres : format = description du format à initialiser pleinement. * +* content = contenu binaire à parcourir. * +* * +* Description : Met en place un nouveau contenu binaire à analyser. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool g_program_format_create(GProgramFormat *format, GBinContent *content) +{ + bool result; /* Bilan à retourner */ + + result = g_known_format_create(G_KNOWN_FORMAT(format), content); + + return result; + +} + + +#if 0 + +/****************************************************************************** +* * * Paramètres : format = format à venir modifier. * * flag = drapeau d'information complémentaire à planter. * * * @@ -273,7 +324,7 @@ static void g_binary_format_finalize(GBinFormat *format) * * ******************************************************************************/ -bool g_binary_format_set_flag(GBinFormat *format, FormatFlag flag) +bool g_program_format_set_flag(GProgramFormat *format, FormatFlag flag) { bool result; /* Bilan à retourner */ fmt_extra_data_t *extra; /* Données insérées à modifier */ @@ -306,7 +357,7 @@ bool g_binary_format_set_flag(GBinFormat *format, FormatFlag flag) * * ******************************************************************************/ -bool g_binary_format_unset_flag(GBinFormat *format, FormatFlag flag) +bool g_program_format_unset_flag(GProgramFormat *format, FormatFlag flag) { bool result; /* Bilan à retourner */ fmt_extra_data_t *extra; /* Données insérées à modifier */ @@ -339,7 +390,7 @@ bool g_binary_format_unset_flag(GBinFormat *format, FormatFlag flag) * * ******************************************************************************/ -bool g_binary_format_has_flag(const GBinFormat *format, FormatFlag flag) +bool g_program_format_has_flag(const GProgramFormat *format, FormatFlag flag) { bool result; /* Bilan à retourner */ fmt_extra_data_t *extra; /* Données insérées à modifier */ @@ -369,7 +420,7 @@ bool g_binary_format_has_flag(const GBinFormat *format, FormatFlag flag) * * ******************************************************************************/ -FormatFlag g_binary_format_get_flags(const GBinFormat *format) +FormatFlag g_program_format_get_flags(const GProgramFormat *format) { FormatFlag result; /* Fanions à retourner */ fmt_extra_data_t *extra; /* Données insérées à modifier */ @@ -386,6 +437,8 @@ FormatFlag g_binary_format_get_flags(const GBinFormat *format) } +#endif + /****************************************************************************** * * @@ -399,11 +452,14 @@ FormatFlag g_binary_format_get_flags(const GBinFormat *format) * * ******************************************************************************/ -SourceEndian g_binary_format_get_endianness(const GBinFormat *format) +SourceEndian g_program_format_get_endianness(const GProgramFormat *format) { SourceEndian result; /* Boutisme à retourner */ + GProgramFormatClass *class; /* Classe de l'instance */ + + class = G_PROGRAM_FORMAT_GET_CLASS(format); - result = G_BIN_FORMAT_GET_CLASS(format)->get_endian(format); + result = class->get_endian(format); return result; @@ -412,6 +468,40 @@ SourceEndian g_binary_format_get_endianness(const GBinFormat *format) /****************************************************************************** * * +* Paramètres : format = description du programme à consulter. * +* name = nom de la section recherchée. * +* range = emplacement en mémoire à renseigner. [OUT] * +* * +* Description : Fournit l'emplacement d'une section donnée. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool g_program_format_find_section_range_by_name(const GProgramFormat *format, const char *name, mrange_t *range) +{ + bool result; /* Bilan à retourner */ + GProgramFormatClass *class; /* Classe de l'instance */ + + class = G_PROGRAM_FORMAT_GET_CLASS(format); + + if (class->find_range_by_name == NULL) + result = false; + + else + result = class->find_range_by_name(format, name, range); + + return result; + +} + + +#if 0 + +/****************************************************************************** +* * * Paramètres : format = description de l'exécutable à compléter. * * pt = point de l'espace mémoire à considérer. * * level = indication de priorité et d'origine de l'adresse. * @@ -424,7 +514,7 @@ SourceEndian g_binary_format_get_endianness(const GBinFormat *format) * * ******************************************************************************/ -void g_binary_format_register_code_point(GBinFormat *format, virt_t pt, DisassPriorityLevel level) +void g_program_format_register_code_point(GProgramFormat *format, virt_t pt, DisassPriorityLevel level) { assert(level < DPL_COUNT); @@ -459,7 +549,7 @@ void g_binary_format_register_code_point(GBinFormat *format, virt_t pt, DisassPr * * ******************************************************************************/ -static bool g_binary_format_load_start_points(GBinFormat *format, packed_buffer_t *pbuf) +static bool g_program_format_load_start_points(GProgramFormat *format, packed_buffer_t *pbuf) { bool result; /* Bilan à retourner */ DisassPriorityLevel i; /* Boucle de parcours #1 */ @@ -512,7 +602,7 @@ static bool g_binary_format_load_start_points(GBinFormat *format, packed_buffer_ * * ******************************************************************************/ -static bool g_binary_format_store_start_points(GBinFormat *format, packed_buffer_t *pbuf) +static bool g_program_format_store_start_points(GProgramFormat *format, packed_buffer_t *pbuf) { bool result; /* Bilan à retourner */ DisassPriorityLevel i; /* Boucle de parcours #1 */ @@ -555,7 +645,7 @@ static bool g_binary_format_store_start_points(GBinFormat *format, packed_buffer * * ******************************************************************************/ -void g_binary_format_preload_disassembling_context(GBinFormat *format, GProcContext *ctx, GtkStatusStack *status) +void g_program_format_preload_disassembling_context(GProgramFormat *format, GProcContext *ctx, GtkStatusStack *status) { g_preload_info_copy(format->info, G_PRELOAD_INFO(ctx)); @@ -576,7 +666,7 @@ void g_binary_format_preload_disassembling_context(GBinFormat *format, GProcCont * * ******************************************************************************/ -void g_binary_format_activate_disassembling_context(GBinFormat *format, GProcContext *ctx, GtkStatusStack *status) +void g_program_format_activate_disassembling_context(GProgramFormat *format, GProcContext *ctx, GtkStatusStack *status) { DisassPriorityLevel i; /* Boucle de parcours #1 */ size_t k; /* Boucle de parcours #2 */ @@ -610,7 +700,7 @@ void g_binary_format_activate_disassembling_context(GBinFormat *format, GProcCon * * ******************************************************************************/ -GCompDemangler *g_binary_format_get_demangler(const GBinFormat *format) +GCompDemangler *g_program_format_get_demangler(const GProgramFormat *format) { GCompDemangler *result; /* Décodeur à retourner */ @@ -637,7 +727,7 @@ GCompDemangler *g_binary_format_get_demangler(const GBinFormat *format) * * ******************************************************************************/ -GDataType *g_binary_format_decode_type(const GBinFormat *format, const char *desc) +GDataType *g_program_format_decode_type(const GProgramFormat *format, const char *desc) { GDataType *result; /* Construction à remonter */ GCompDemangler *demangler; /* Accès plus lisible */ @@ -667,7 +757,7 @@ GDataType *g_binary_format_decode_type(const GBinFormat *format, const char *des * * ******************************************************************************/ -GBinRoutine *g_binary_format_decode_routine(const GBinFormat *format, const char *desc) +GBinRoutine *g_program_format_decode_routine(const GProgramFormat *format, const char *desc) { GBinRoutine *result; /* Construction à remonter */ GCompDemangler *demangler; /* Accès plus lisible */ @@ -708,7 +798,7 @@ GBinRoutine *g_binary_format_decode_routine(const GBinFormat *format, const char * * ******************************************************************************/ -void g_binary_format_lock_unlock_symbols_rd(GBinFormat *format, bool state) +void g_program_format_lock_unlock_symbols_rd(GProgramFormat *format, bool state) { #ifndef NDEBUG gint test; /* Test de valeur courante */ @@ -746,7 +836,7 @@ void g_binary_format_lock_unlock_symbols_rd(GBinFormat *format, bool state) * * ******************************************************************************/ -void g_binary_format_lock_unlock_symbols_wr(GBinFormat *format, bool state) +void g_program_format_lock_unlock_symbols_wr(GProgramFormat *format, bool state) { if (state) { @@ -778,7 +868,7 @@ void g_binary_format_lock_unlock_symbols_wr(GBinFormat *format, bool state) * * ******************************************************************************/ #ifndef NDEBUG -void g_binary_format_check_for_symbols_lock(const GBinFormat *format) +void g_program_format_check_for_symbols_lock(const GProgramFormat *format) { assert(g_atomic_int_get(&format->sym_locked) > 0); @@ -798,7 +888,7 @@ void g_binary_format_check_for_symbols_lock(const GBinFormat *format) * * ******************************************************************************/ -unsigned int g_binary_format_get_symbols_stamp(const GBinFormat *format) +unsigned int g_program_format_get_symbols_stamp(const GProgramFormat *format) { return format->sym_stamp; @@ -817,7 +907,7 @@ unsigned int g_binary_format_get_symbols_stamp(const GBinFormat *format) * * ******************************************************************************/ -size_t g_binary_format_count_symbols(const GBinFormat *format) +size_t g_program_format_count_symbols(const GProgramFormat *format) { assert(g_atomic_int_get(&format->sym_locked) > 0); @@ -839,7 +929,7 @@ size_t g_binary_format_count_symbols(const GBinFormat *format) * * ******************************************************************************/ -GBinSymbol *g_binary_format_get_symbol(const GBinFormat *format, size_t index) +GBinSymbol *g_program_format_get_symbol(const GProgramFormat *format, size_t index) { GBinSymbol *result; /* Symbole à retourner */ @@ -877,7 +967,7 @@ GBinSymbol *g_binary_format_get_symbol(const GBinFormat *format, size_t index) * * ******************************************************************************/ -bool g_binary_format_add_symbol(GBinFormat *format, GBinSymbol *symbol) +bool g_program_format_add_symbol(GProgramFormat *format, GBinSymbol *symbol) { bool result; /* Statut d'ajout à retourner */ #ifndef NDEBUG @@ -887,7 +977,7 @@ bool g_binary_format_add_symbol(GBinFormat *format, GBinSymbol *symbol) size_t index; /* Indice du point d'insertion */ /** - * Pour que les fonctions de recherche basées sur _g_binary_format_find_symbol() + * Pour que les fonctions de recherche basées sur _g_program_format_find_symbol() * fassent bien leur office, il faut que les symboles soient triés. * * Cependant, les localisations à satisfaire lors d'une recherche recontrent @@ -912,7 +1002,7 @@ bool g_binary_format_add_symbol(GBinFormat *format, GBinSymbol *symbol) assert(has_phys_addr(addr) || g_binary_symbol_get_status(symbol) == SSS_DYNAMIC); #endif - g_binary_format_lock_unlock_symbols_wr(format, true); + g_program_format_lock_unlock_symbols_wr(format, true); /** * Avec tous les traitements parallèles, il est possible que plusieurs chemins d'exécution @@ -939,7 +1029,7 @@ bool g_binary_format_add_symbol(GBinFormat *format, GBinSymbol *symbol) else g_object_unref(G_OBJECT(symbol)); - g_binary_format_lock_unlock_symbols_wr(format, false); + g_program_format_lock_unlock_symbols_wr(format, false); if (result) g_signal_emit_by_name(format, "symbol-added", symbol); @@ -963,7 +1053,7 @@ bool g_binary_format_add_symbol(GBinFormat *format, GBinSymbol *symbol) * * ******************************************************************************/ -bool g_binary_format_add_symbols(GBinFormat *format, GBinSymbol **symbols, size_t count) +bool g_program_format_add_symbols(GProgramFormat *format, GBinSymbol **symbols, size_t count) { bool result; /* Statut d'ajout à retourner */ #ifndef NDEBUG @@ -977,7 +1067,7 @@ bool g_binary_format_add_symbols(GBinFormat *format, GBinSymbol **symbols, size_ size_t index; /* Indice du point d'insertion */ /** - * Pour que les fonctions de recherche basées sur _g_binary_format_find_symbol() + * Pour que les fonctions de recherche basées sur _g_program_format_find_symbol() * fassent bien leur office, il faut que les symboles soient triés. * * Cependant, les localisations à satisfaire lors d'une recherche recontrent @@ -1014,7 +1104,7 @@ bool g_binary_format_add_symbols(GBinFormat *format, GBinSymbol **symbols, size_ } #endif - g_binary_format_lock_unlock_symbols_wr(format, true); + g_program_format_lock_unlock_symbols_wr(format, true); /** * Avec tous les traitements parallèles, il est possible que plusieurs chemins d'exécution @@ -1042,7 +1132,7 @@ bool g_binary_format_add_symbols(GBinFormat *format, GBinSymbol **symbols, size_ } - g_binary_format_lock_unlock_symbols_wr(format, false); + g_program_format_lock_unlock_symbols_wr(format, false); if (result) for (i = 0; i < count; i++) @@ -1066,7 +1156,7 @@ bool g_binary_format_add_symbols(GBinFormat *format, GBinSymbol **symbols, size_ * * ******************************************************************************/ -static void _g_binary_format_remove_symbol(GBinFormat *format, size_t index) +static void _g_program_format_remove_symbol(GProgramFormat *format, size_t index) { assert(g_atomic_int_get(&format->sym_locked) == 1); @@ -1096,22 +1186,22 @@ static void _g_binary_format_remove_symbol(GBinFormat *format, size_t index) * * ******************************************************************************/ -void g_binary_format_remove_symbol(GBinFormat *format, GBinSymbol *symbol) +void g_program_format_remove_symbol(GProgramFormat *format, GBinSymbol *symbol) { bool found; /* Jeton de présence */ size_t index; /* Indice du point de retrait */ g_object_ref(G_OBJECT(symbol)); - g_binary_format_lock_unlock_symbols_wr(format, true); + g_program_format_lock_unlock_symbols_wr(format, true); found = bsearch_index(&symbol, format->symbols, format->sym_count, sizeof(GBinSymbol *), (__compar_fn_t)g_binary_symbol_cmp, &index); if (found) - _g_binary_format_remove_symbol(format, index); + _g_program_format_remove_symbol(format, index); - g_binary_format_lock_unlock_symbols_wr(format, false); + g_program_format_lock_unlock_symbols_wr(format, false); if (found) g_signal_emit_by_name(format, "symbol-removed", symbol); @@ -1135,7 +1225,7 @@ void g_binary_format_remove_symbol(GBinFormat *format, GBinSymbol *symbol) * * ******************************************************************************/ -bool g_binary_format_find_symbol_by_label(GBinFormat *format, const char *label, GBinSymbol **symbol) +bool g_program_format_find_symbol_by_label(GProgramFormat *format, const char *label, GBinSymbol **symbol) { bool result; /* Bilan à retourner */ size_t i; /* Boucle de parcours */ @@ -1143,7 +1233,7 @@ bool g_binary_format_find_symbol_by_label(GBinFormat *format, const char *label, result = false; - g_binary_format_lock_symbols_rd(format); + g_program_format_lock_symbols_rd(format); for (i = 0; i < format->sym_count && !result; i++) { @@ -1163,7 +1253,7 @@ bool g_binary_format_find_symbol_by_label(GBinFormat *format, const char *label, } - g_binary_format_unlock_symbols_rd(format); + g_program_format_unlock_symbols_rd(format); return result; @@ -1186,16 +1276,16 @@ bool g_binary_format_find_symbol_by_label(GBinFormat *format, const char *label, * * ******************************************************************************/ -static bool _g_binary_format_find_symbol(const GBinFormat *format, const vmpa2t *addr, __compar_fn_t fn, size_t *index, GBinSymbol **symbol) +static bool _g_program_format_find_symbol(const GProgramFormat *format, const vmpa2t *addr, __compar_fn_t fn, size_t *index, GBinSymbol **symbol) { /** * Pour ce qui est des justifications quant à la vérification suivante, - * se référer aux commentaires placés dans g_binary_format_add_symbol(). + * se référer aux commentaires placés dans g_program_format_add_symbol(). */ assert(has_phys_addr(addr)); - return __g_binary_format_find_symbol(format, addr, fn, index, symbol); + return __g_program_format_find_symbol(format, addr, fn, index, symbol); } @@ -1216,7 +1306,7 @@ static bool _g_binary_format_find_symbol(const GBinFormat *format, const vmpa2t * * ******************************************************************************/ -static bool __g_binary_format_find_symbol(const GBinFormat *format, const void *key, __compar_fn_t fn, size_t *index, GBinSymbol **symbol) +static bool __g_program_format_find_symbol(const GProgramFormat *format, const void *key, __compar_fn_t fn, size_t *index, GBinSymbol **symbol) { bool result; /* Bilan à retourner */ void *found; /* Résultat de recherches */ @@ -1268,7 +1358,7 @@ static bool __g_binary_format_find_symbol(const GBinFormat *format, const void * * * ******************************************************************************/ -bool g_binary_format_find_symbol_index_at(GBinFormat *format, const vmpa2t *addr, size_t *index) +bool g_program_format_find_symbol_index_at(GProgramFormat *format, const vmpa2t *addr, size_t *index) { bool result; /* Bilan à retourner */ @@ -1282,11 +1372,11 @@ bool g_binary_format_find_symbol_index_at(GBinFormat *format, const vmpa2t *addr } - g_binary_format_lock_symbols_rd(format); + g_program_format_lock_symbols_rd(format); - result = _g_binary_format_find_symbol(format, addr, (__compar_fn_t)find_symbol, index, NULL); + result = _g_program_format_find_symbol(format, addr, (__compar_fn_t)find_symbol, index, NULL); - g_binary_format_unlock_symbols_rd(format); + g_program_format_unlock_symbols_rd(format); return result; @@ -1307,7 +1397,7 @@ bool g_binary_format_find_symbol_index_at(GBinFormat *format, const vmpa2t *addr * * ******************************************************************************/ -bool g_binary_format_find_symbol_at(GBinFormat *format, const vmpa2t *addr, GBinSymbol **symbol) +bool g_program_format_find_symbol_at(GProgramFormat *format, const vmpa2t *addr, GBinSymbol **symbol) { bool result; /* Bilan à retourner */ @@ -1321,11 +1411,11 @@ bool g_binary_format_find_symbol_at(GBinFormat *format, const vmpa2t *addr, GBin } - g_binary_format_lock_symbols_rd(format); + g_program_format_lock_symbols_rd(format); - result = _g_binary_format_find_symbol(format, addr, (__compar_fn_t)find_symbol, NULL, symbol); + result = _g_program_format_find_symbol(format, addr, (__compar_fn_t)find_symbol, NULL, symbol); - g_binary_format_unlock_symbols_rd(format); + g_program_format_unlock_symbols_rd(format); return result; @@ -1346,7 +1436,7 @@ bool g_binary_format_find_symbol_at(GBinFormat *format, const vmpa2t *addr, GBin * * ******************************************************************************/ -bool g_binary_format_find_symbol_for(GBinFormat *format, const vmpa2t *addr, GBinSymbol **symbol) +bool g_program_format_find_symbol_for(GProgramFormat *format, const vmpa2t *addr, GBinSymbol **symbol) { bool result; /* Bilan à retourner */ @@ -1360,11 +1450,11 @@ bool g_binary_format_find_symbol_for(GBinFormat *format, const vmpa2t *addr, GBi } - g_binary_format_lock_symbols_rd(format); + g_program_format_lock_symbols_rd(format); - result = _g_binary_format_find_symbol(format, addr, (__compar_fn_t)find_symbol, NULL, symbol); + result = _g_program_format_find_symbol(format, addr, (__compar_fn_t)find_symbol, NULL, symbol); - g_binary_format_unlock_symbols_rd(format); + g_program_format_unlock_symbols_rd(format); return result; @@ -1385,7 +1475,7 @@ bool g_binary_format_find_symbol_for(GBinFormat *format, const vmpa2t *addr, GBi * * ******************************************************************************/ -bool g_binary_format_find_next_symbol_at(GBinFormat *format, const vmpa2t *addr, GBinSymbol **symbol) +bool g_program_format_find_next_symbol_at(GProgramFormat *format, const vmpa2t *addr, GBinSymbol **symbol) { bool result; /* Bilan à retourner */ size_t index; /* Indice à considérer */ @@ -1400,9 +1490,9 @@ bool g_binary_format_find_next_symbol_at(GBinFormat *format, const vmpa2t *addr, } - g_binary_format_lock_symbols_rd(format); + g_program_format_lock_symbols_rd(format); - result = _g_binary_format_find_symbol(format, addr, (__compar_fn_t)find_symbol, &index, NULL); + result = _g_program_format_find_symbol(format, addr, (__compar_fn_t)find_symbol, &index, NULL); if (result && (index + 1) < format->sym_count) { @@ -1417,7 +1507,7 @@ bool g_binary_format_find_next_symbol_at(GBinFormat *format, const vmpa2t *addr, result = false; } - g_binary_format_unlock_symbols_rd(format); + g_program_format_unlock_symbols_rd(format); return result; @@ -1438,7 +1528,7 @@ bool g_binary_format_find_next_symbol_at(GBinFormat *format, const vmpa2t *addr, * * ******************************************************************************/ -bool g_binary_format_find_first_symbol_inside(GBinFormat *format, const mrange_t *range, size_t *index) +bool g_program_format_find_first_symbol_inside(GProgramFormat *format, const mrange_t *range, size_t *index) { bool result; /* Bilan à retourner */ const GBinSymbol *prev; /* Symbole précédent */ @@ -1463,7 +1553,7 @@ bool g_binary_format_find_first_symbol_inside(GBinFormat *format, const mrange_t g_rw_lock_reader_lock(&format->syms_lock); - result = __g_binary_format_find_symbol(format, range, (__compar_fn_t)find_symbol, index, NULL); + result = __g_program_format_find_symbol(format, range, (__compar_fn_t)find_symbol, index, NULL); if (result) while (*index > 0) @@ -1502,15 +1592,15 @@ bool g_binary_format_find_first_symbol_inside(GBinFormat *format, const mrange_t * * ******************************************************************************/ -bool g_binary_format_resolve_symbol(GBinFormat *format, const vmpa2t *addr, bool strict, GBinSymbol **symbol, phys_t *diff) +bool g_program_format_resolve_symbol(GProgramFormat *format, const vmpa2t *addr, bool strict, GBinSymbol **symbol, phys_t *diff) { bool result; /* Bilan à retourner */ const mrange_t *range; /* Espace mémoire parcouru */ if (strict) - result = g_binary_format_find_symbol_at(format, addr, symbol); + result = g_program_format_find_symbol_at(format, addr, symbol); else - result = g_binary_format_find_symbol_for(format, addr, symbol); + result = g_program_format_find_symbol_for(format, addr, symbol); if (result) { @@ -1548,7 +1638,7 @@ bool g_binary_format_resolve_symbol(GBinFormat *format, const vmpa2t *addr, bool * * ******************************************************************************/ -void g_binary_format_lock_unlock_errors(GBinFormat *format, bool state) +void g_program_format_lock_unlock_errors(GProgramFormat *format, bool state) { if (state) { @@ -1584,11 +1674,11 @@ void g_binary_format_lock_unlock_errors(GBinFormat *format, bool state) * * ******************************************************************************/ -void g_binary_format_add_error(GBinFormat *format, BinaryFormatError type, const vmpa2t *addr, const char *desc) +void g_program_format_add_error(GProgramFormat *format, BinaryFormatError type, const vmpa2t *addr, const char *desc) { fmt_error *error; /* Raccourci de confort */ - g_binary_format_lock_errors(format); + g_program_format_lock_errors(format); format->errors = realloc(format->errors, ++format->error_count * sizeof(fmt_error)); @@ -1603,7 +1693,7 @@ void g_binary_format_add_error(GBinFormat *format, BinaryFormatError type, const else error->desc = NULL; - g_binary_format_unlock_errors(format); + g_program_format_unlock_errors(format); } @@ -1620,7 +1710,7 @@ void g_binary_format_add_error(GBinFormat *format, BinaryFormatError type, const * * ******************************************************************************/ -size_t g_binary_format_count_errors(GBinFormat *format) +size_t g_program_format_count_errors(GProgramFormat *format) { size_t result; /* Quantité à retourner */ @@ -1649,7 +1739,7 @@ size_t g_binary_format_count_errors(GBinFormat *format) * * ******************************************************************************/ -bool g_binary_format_get_error(GBinFormat *format, size_t index, BinaryFormatError *type, vmpa2t *addr, char **desc) +bool g_program_format_get_error(GProgramFormat *format, size_t index, BinaryFormatError *type, vmpa2t *addr, char **desc) { bool result; /* Bilan à retourner */ fmt_error *error; /* Raccourci de confort */ @@ -1693,7 +1783,7 @@ bool g_binary_format_get_error(GBinFormat *format, size_t index, BinaryFormatErr * * ******************************************************************************/ -static bool g_binary_format_load_errors(GBinFormat *format, packed_buffer_t *pbuf) +static bool g_program_format_load_errors(GProgramFormat *format, packed_buffer_t *pbuf) { bool result; /* Bilan à retourner */ uleb128_t value; /* Valeur ULEB128 à charger */ @@ -1701,7 +1791,7 @@ static bool g_binary_format_load_errors(GBinFormat *format, packed_buffer_t *pbu fmt_error *error; /* Raccourci de confort */ rle_string str; /* Chaîne à charger */ - g_binary_format_lock_errors(format); + g_program_format_lock_errors(format); result = unpack_uleb128(&value, pbuf); if (!result) goto exit; @@ -1736,7 +1826,7 @@ static bool g_binary_format_load_errors(GBinFormat *format, packed_buffer_t *pbu exit: - g_binary_format_unlock_errors(format); + g_program_format_unlock_errors(format); return result; @@ -1756,14 +1846,14 @@ static bool g_binary_format_load_errors(GBinFormat *format, packed_buffer_t *pbu * * ******************************************************************************/ -static bool g_binary_format_store_errors(GBinFormat *format, packed_buffer_t *pbuf) +static bool g_program_format_store_errors(GProgramFormat *format, packed_buffer_t *pbuf) { bool result; /* Bilan à retourner */ size_t i; /* Boucle de parcours */ fmt_error *error; /* Raccourci de confort */ rle_string str; /* Chaîne à conserver */ - g_binary_format_lock_errors(format); + g_program_format_lock_errors(format); result = pack_uleb128((uleb128_t []){ format->error_count }, pbuf); @@ -1785,7 +1875,7 @@ static bool g_binary_format_store_errors(GBinFormat *format, packed_buffer_t *pb } - g_binary_format_unlock_errors(format); + g_program_format_unlock_errors(format); return result; @@ -1812,7 +1902,7 @@ static bool g_binary_format_store_errors(GBinFormat *format, packed_buffer_t *pb * * ******************************************************************************/ -static bool g_binary_format_load(GBinFormat *format, GObjectStorage *storage, packed_buffer_t *pbuf) +static bool g_program_format_load(GProgramFormat *format, GObjectStorage *storage, packed_buffer_t *pbuf) { bool result; /* Bilan à retourner */ fmt_extra_data_t *extra; /* Données insérées à consulter*/ @@ -1831,7 +1921,7 @@ static bool g_binary_format_load(GBinFormat *format, GObjectStorage *storage, pa UNLOCK_GOBJECT_EXTRA(extra); if (result) - result = g_binary_format_load_start_points(format, pbuf); + result = g_program_format_load_start_points(format, pbuf); if (result) { @@ -1857,7 +1947,7 @@ static bool g_binary_format_load(GBinFormat *format, GObjectStorage *storage, pa if (result) - result = g_binary_format_load_errors(format, pbuf); + result = g_program_format_load_errors(format, pbuf); return result; @@ -1878,7 +1968,7 @@ static bool g_binary_format_load(GBinFormat *format, GObjectStorage *storage, pa * * ******************************************************************************/ -static bool g_binary_format_store(GBinFormat *format, GObjectStorage *storage, packed_buffer_t *pbuf) +static bool g_program_format_store(GProgramFormat *format, GObjectStorage *storage, packed_buffer_t *pbuf) { bool result; /* Bilan à retourner */ fmt_extra_data_t *extra; /* Données insérées à consulter*/ @@ -1894,7 +1984,7 @@ static bool g_binary_format_store(GBinFormat *format, GObjectStorage *storage, p UNLOCK_GOBJECT_EXTRA(extra); if (result) - result = g_binary_format_store_start_points(format, pbuf); + result = g_program_format_store_start_points(format, pbuf); if (result) { @@ -1913,8 +2003,10 @@ static bool g_binary_format_store(GBinFormat *format, GObjectStorage *storage, p if (result) - result = g_binary_format_store_errors(format, pbuf); + result = g_program_format_store_errors(format, pbuf); return result; } + +#endif diff --git a/src/format/format.h b/src/format/program.h index f9aa430..12b095c 100644 --- a/src/format/format.h +++ b/src/format/program.h @@ -1,8 +1,8 @@ /* Chrysalide - Outil d'analyse de fichiers binaires - * format.h - prototypes pour le support des différents formats binaires + * program.h - prototypes pour le support des différents formats de programmes * - * Copyright (C) 2009-2020 Cyrille Bagard + * Copyright (C) 2009-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -21,12 +21,35 @@ */ -#ifndef _FORMAT_FORMAT_H -#define _FORMAT_FORMAT_H +#ifndef _FORMAT_PROGRAM_H +#define _FORMAT_PROGRAM_H -#include <glib-object.h> #include <stdbool.h> + + +#include "../arch/vmpa.h" +#include "../common/datatypes.h" +#include "../glibext/helpers.h" + + + +#define G_TYPE_PROGRAM_FORMAT (g_program_format_get_type()) + +DECLARE_GTYPE(GProgramFormat, g_program_format, G, PROGRAM_FORMAT); + + +/* Indique le boutisme employé par le format binaire analysé. */ +SourceEndian g_program_format_get_endianness(const GProgramFormat *); + +/* Fournit l'emplacement d'une section donnée. */ +bool g_program_format_find_section_range_by_name(const GProgramFormat *, const char *, mrange_t *); + + + + +#if 0 + #include <sys/types.h> @@ -52,47 +75,31 @@ typedef enum _FormatFlag } FormatFlag; -#define G_TYPE_BIN_FORMAT g_binary_format_get_type() -#define G_BIN_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_BIN_FORMAT, GBinFormat)) -#define G_IS_BIN_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_BIN_FORMAT)) -#define G_BIN_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_BIN_FORMAT, GBinFormatClass)) -#define G_IS_BIN_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_BIN_FORMAT)) -#define G_BIN_FORMAT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_BIN_FORMAT, GBinFormatClass)) -/* Format binaire générique (instance) */ -typedef struct _GBinFormat GBinFormat; - -/* Format binaire générique (classe) */ -typedef struct _GBinFormatClass GBinFormatClass; - - -/* Indique le type défini pour un format binaire générique. */ -GType g_binary_format_get_type(void); - /* Ajoute une information complémentaire à un format. */ -bool g_binary_format_set_flag(GBinFormat *, FormatFlag); +bool g_program_format_set_flag(GProgramFormat *, FormatFlag); /* Retire une information complémentaire à un format. */ -bool g_binary_format_unset_flag(GBinFormat *, FormatFlag); +bool g_program_format_unset_flag(GProgramFormat *, FormatFlag); /* Détermine si un format possède un fanion particulier. */ -bool g_binary_format_has_flag(const GBinFormat *, FormatFlag); +bool g_program_format_has_flag(const GProgramFormat *, FormatFlag); /* Fournit les particularités du format. */ -FormatFlag g_binary_format_get_flags(const GBinFormat *); +FormatFlag g_program_format_get_flags(const GProgramFormat *); /* Indique le boutisme employé par le format binaire analysé. */ -SourceEndian g_binary_format_get_endianness(const GBinFormat *); +//SourceEndian g_program_format_get_endianness(const GProgramFormat *); /* Enregistre une adresse comme début d'une zone de code. */ -void g_binary_format_register_code_point(GBinFormat *, virt_t, DisassPriorityLevel); +void g_program_format_register_code_point(GProgramFormat *, virt_t, DisassPriorityLevel); /* Intègre dans un contexte les informations tirées d'un format. */ -void g_binary_format_preload_disassembling_context(GBinFormat *, GProcContext *, GtkStatusStack *); +void g_program_format_preload_disassembling_context(GProgramFormat *, GProcContext *, GtkStatusStack *); /* Définit les points de départ d'un contexte de désassemblage. */ -void g_binary_format_activate_disassembling_context(GBinFormat *, GProcContext *, GtkStatusStack *); +void g_program_format_activate_disassembling_context(GProgramFormat *, GProcContext *, GtkStatusStack *); @@ -100,7 +107,7 @@ void g_binary_format_activate_disassembling_context(GBinFormat *, GProcContext * /* Fournit le décodeur de symboles privilégié pour un format. */ -GCompDemangler *g_binary_format_get_demangler(const GBinFormat *); +GCompDemangler *g_program_format_get_demangler(const GProgramFormat *); @@ -108,60 +115,60 @@ GCompDemangler *g_binary_format_get_demangler(const GBinFormat *); /* Protège ou lève la protection de l'accès aux symboles. */ -void g_binary_format_lock_unlock_symbols_rd(GBinFormat *, bool); +void g_program_format_lock_unlock_symbols_rd(GProgramFormat *, bool); -#define g_binary_format_lock_symbols_rd(f) g_binary_format_lock_unlock_symbols_rd(f, true) -#define g_binary_format_unlock_symbols_rd(f) g_binary_format_lock_unlock_symbols_rd(f, false) +#define g_program_format_lock_symbols_rd(f) g_program_format_lock_unlock_symbols_rd(f, true) +#define g_program_format_unlock_symbols_rd(f) g_program_format_lock_unlock_symbols_rd(f, false) /* Protège ou lève la protection de l'accès aux symboles. */ -void g_binary_format_lock_unlock_symbols_wr(GBinFormat *, bool); +void g_program_format_lock_unlock_symbols_wr(GProgramFormat *, bool); -#define g_binary_format_lock_symbols_wr(f) g_binary_format_lock_unlock_symbols_wr(f, true) -#define g_binary_format_unlock_symbols_wr(f) g_binary_format_lock_unlock_symbols_wr(f, false) +#define g_program_format_lock_symbols_wr(f) g_program_format_lock_unlock_symbols_wr(f, true) +#define g_program_format_unlock_symbols_wr(f) g_program_format_lock_unlock_symbols_wr(f, false) /* Assure qu'un verrou est bien posé pour l'accès aux symboles. */ #ifndef NDEBUG -void g_binary_format_check_for_symbols_lock(const GBinFormat *); +void g_program_format_check_for_symbols_lock(const GProgramFormat *); #endif /* Fournit la marque de dernière modification des symboles. */ -unsigned int g_binary_format_get_symbols_stamp(const GBinFormat *); +unsigned int g_program_format_get_symbols_stamp(const GProgramFormat *); /* Compte le nombre de symboles représentés. */ -size_t g_binary_format_count_symbols(const GBinFormat *); +size_t g_program_format_count_symbols(const GProgramFormat *); /* Fournit un symbole lié à un format. */ -GBinSymbol *g_binary_format_get_symbol(const GBinFormat *, size_t); +GBinSymbol *g_program_format_get_symbol(const GProgramFormat *, size_t); /* Ajoute un symbole à la collection du format binaire. */ -bool g_binary_format_add_symbol(GBinFormat *, GBinSymbol *); +bool g_program_format_add_symbol(GProgramFormat *, GBinSymbol *); /* Ajoute plusieurs symboles à la collection du format binaire. */ -bool g_binary_format_add_symbols(GBinFormat *, GBinSymbol **, size_t); +bool g_program_format_add_symbols(GProgramFormat *, GBinSymbol **, size_t); /* Retire un symbole de la collection du format binaire. */ -void g_binary_format_remove_symbol(GBinFormat *, GBinSymbol *); +void g_program_format_remove_symbol(GProgramFormat *, GBinSymbol *); /* Recherche le symbole correspondant à une étiquette. */ -bool g_binary_format_find_symbol_by_label(GBinFormat *, const char *, GBinSymbol **); +bool g_program_format_find_symbol_by_label(GProgramFormat *, const char *, GBinSymbol **); /* Recherche l'indice du symbole correspondant à une adresse. */ -bool g_binary_format_find_symbol_index_at(GBinFormat *, const vmpa2t *, size_t *); +bool g_program_format_find_symbol_index_at(GProgramFormat *, const vmpa2t *, size_t *); /* Recherche le symbole correspondant à une adresse. */ -bool g_binary_format_find_symbol_at(GBinFormat *, const vmpa2t *, GBinSymbol **); +bool g_program_format_find_symbol_at(GProgramFormat *, const vmpa2t *, GBinSymbol **); /* Recherche le symbole contenant une adresse. */ -bool g_binary_format_find_symbol_for(GBinFormat *, const vmpa2t *, GBinSymbol **); +bool g_program_format_find_symbol_for(GProgramFormat *, const vmpa2t *, GBinSymbol **); /* Recherche le symbole suivant celui lié à une adresse. */ -bool g_binary_format_find_next_symbol_at(GBinFormat *, const vmpa2t *, GBinSymbol **); +bool g_program_format_find_next_symbol_at(GProgramFormat *, const vmpa2t *, GBinSymbol **); /* Recherche le premier symbole inclus dans une zone mémoire. */ -bool g_binary_format_find_first_symbol_inside(GBinFormat *, const mrange_t *, size_t *); +bool g_program_format_find_first_symbol_inside(GProgramFormat *, const mrange_t *, size_t *); /* Recherche le symbole correspondant à une adresse. */ -bool g_binary_format_resolve_symbol(GBinFormat *, const vmpa2t *, bool, GBinSymbol **, phys_t *); +bool g_program_format_resolve_symbol(GProgramFormat *, const vmpa2t *, bool, GBinSymbol **, phys_t *); @@ -181,20 +188,21 @@ typedef enum _BinaryFormatError /* Protège ou lève la protection de l'accès aux erreurs. */ -void g_binary_format_lock_unlock_errors(GBinFormat *, bool); +void g_program_format_lock_unlock_errors(GProgramFormat *, bool); -#define g_binary_format_lock_errors(f) g_binary_format_lock_unlock_errors(f, true) -#define g_binary_format_unlock_errors(f) g_binary_format_lock_unlock_errors(f, false) +#define g_program_format_lock_errors(f) g_program_format_lock_unlock_errors(f, true) +#define g_program_format_unlock_errors(f) g_program_format_lock_unlock_errors(f, false) /* Etend la liste des soucis détectés avec de nouvelles infos. */ -void g_binary_format_add_error(GBinFormat *, BinaryFormatError, const vmpa2t *, const char *); +void g_program_format_add_error(GProgramFormat *, BinaryFormatError, const vmpa2t *, const char *); /* Indique le nombre d'erreurs relevées au niveau assembleur. */ -size_t g_binary_format_count_errors(GBinFormat *); +size_t g_program_format_count_errors(GProgramFormat *); /* Fournit les éléments concernant un soucis détecté. */ -bool g_binary_format_get_error(GBinFormat *, size_t, BinaryFormatError *, vmpa2t *, char **); +bool g_program_format_get_error(GProgramFormat *, size_t, BinaryFormatError *, vmpa2t *, char **); +#endif -#endif /* _FORMAT_FORMAT_H */ +#endif /* _FORMAT_PROGRAM_H */ |