diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/analysis/binary.c | 60 | ||||
| -rw-r--r-- | src/analysis/binary.h | 3 | ||||
| -rw-r--r-- | src/core/Makefile.am | 1 | ||||
| -rw-r--r-- | src/core/core.c | 5 | ||||
| -rw-r--r-- | src/core/formats.c | 394 | ||||
| -rw-r--r-- | src/core/formats.h | 80 | ||||
| -rw-r--r-- | src/format/Makefile.am | 7 | ||||
| -rw-r--r-- | src/plugins/plugin-def.h | 20 | ||||
| -rw-r--r-- | src/plugins/plugin.c | 15 | 
9 files changed, 4 insertions, 581 deletions
diff --git a/src/analysis/binary.c b/src/analysis/binary.c index fd0dd3b..5b84f58 100644 --- a/src/analysis/binary.c +++ b/src/analysis/binary.c @@ -44,7 +44,6 @@  #include "../common/cpp.h"  #include "../common/xdg.h"  #include "../core/collections.h" -#include "../core/formats.h"  #include "../core/global.h"  #include "../core/logs.h"  #include "../core/params.h" @@ -1236,65 +1235,6 @@ bool _g_loaded_binary_remove_from_collection(GLoadedBinary *binary, DBFeatures f  *                                                                             *  ******************************************************************************/ -bool g_loaded_binary_attach_debug_info(GLoadedBinary *binary, GBinContent *content) -{ -    bool result;                            /* Bilan à retourner pour info */ -    FormatMatchStatus status;               /* Statut d'une reconnaissance */ -    char *target;                           /* Sous-traitance requise      */ -    const char *desc;                       /* Description humaine associée*/ -    GDbgFormat *debug;                      /* Format de débogage trouvé   */ - -    status = find_matching_format(content, binary->format, &target); - -    if (status == FMS_MATCHED) -    { -        result = false; - -        desc = get_binary_format_name(target); - -        if (desc == NULL) -            log_simple_message(LMT_INFO, _("Unknown binary debug format")); - -        else -        { -            log_variadic_message(LMT_INFO, _("Detected debug format: %s"), desc); - -            debug = G_DBG_FORMAT(load_new_named_format(target, content, binary->format)); - -            if (debug == NULL) -                log_simple_message(LMT_ERROR, _("Error while loading the debug information for binary")); - -            else -            { -                result = true; -                g_exe_format_add_debug_info(binary->format, debug); -            } - -        } - -        free(target); - -    } -    else -        result = true; - -    return result; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : binary = élément binaire à consulter.                        * -*                                                                             * -*  Description : Fournit le format de fichier reconnu dans le contenu binaire.* -*                                                                             * -*  Retour      : Instance du format reconnu.                                  * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ -  GExeFormat *g_loaded_binary_get_format(const GLoadedBinary *binary)  {      GExeFormat *result;                     /* Instance à retourner        */ diff --git a/src/analysis/binary.h b/src/analysis/binary.h index 648da10..7c2c760 100644 --- a/src/analysis/binary.h +++ b/src/analysis/binary.h @@ -153,9 +153,6 @@ bool _g_loaded_binary_remove_from_collection(GLoadedBinary *, DBFeatures, GDbIte  /* Fournit le format de fichier reconnu dans le contenu binaire. */ -bool g_loaded_binary_attach_debug_info(GLoadedBinary *, GBinContent *); - -/* Fournit le format de fichier reconnu dans le contenu binaire. */  GExeFormat *g_loaded_binary_get_format(const GLoadedBinary *);  /* Fournit le processeur de l'architecture liée au binaire. */ diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 89dd345..b783603 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -5,7 +5,6 @@ libcore_la_SOURCES =					\  	collections.h collections.c			\  	core.h core.c						\  	demanglers.h demanglers.c			\ -	formats.h formats.c					\  	global.h global.c					\  	logs.h logs.c						\  	nproc.h nproc.c						\ diff --git a/src/core/core.c b/src/core/core.c index 3f0d244..fe8ccbb 100644 --- a/src/core/core.c +++ b/src/core/core.c @@ -35,7 +35,6 @@  #include "collections.h"  #include "demanglers.h" -#include "formats.h"  #include "global.h"  #include "params.h"  #include "processors.h" @@ -106,8 +105,6 @@ bool load_all_basic_components(void)          result &= load_hard_coded_processors_definitions(); -        result &= load_hard_coded_formats_definitions(); -          result &= load_hard_coded_collection_definitions();      } @@ -135,8 +132,6 @@ void unload_all_basic_components(void)      unload_demanglers_definitions(); -    unload_formats_definitions(); -      unload_processors_definitions();      exit_global_works(); diff --git a/src/core/formats.c b/src/core/formats.c deleted file mode 100644 index d16cb26..0000000 --- a/src/core/formats.c +++ /dev/null @@ -1,394 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * formats.c - enregistrement et fourniture des formats de binaires supportés - * - * Copyright (C) 2015-2017 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 "formats.h" - - -#include <malloc.h> -#include <pthread.h> -#include <string.h> - - -#include "../format/dwarf/dwarf.h" -#include "../format/dwarf/v2/dwarf.h" -#include "../format/dwarf/v3/dwarf.h" -#include "../format/dwarf/v4/dwarf.h" - - - -/* Eléments pour détection */ -typedef struct _format_matcher_t -{ -    format_match_fc func;                   /* Recherche de correspondance */ -    void *data;                             /* Eventuelle donnée à y lier  */ - -} format_matcher_t; - - -/* Caractéristiques d'un processeur */ -typedef struct _format_loader_t -{ -    char *key;                              /* Clef pour un accès rapide   */ -    char *name;                             /* Désignation humaine         */ - -    format_load_fc func;                    /* Procédure de chargement     */ - -} format_loader_t; - - -/* Mémorisation des détections de format enregistrées */ -static format_matcher_t *_formats_matchers = NULL; -static size_t _formats_matchers_count = 0; - -/* Mémorisation des types de formats enregistrés */ -static format_loader_t *_formats_loaders = NULL; -static size_t _formats_loaders_count = 0; - -/* Verrou pour des accès atomiques */ -static GRWLock _formats_lock; - - -/* Retrouve l'enregistrement correspondant à une architecture. */ -static format_loader_t *find_format_by_key(const char *); - - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : func = procédure de détection à utiliser.                    * -*                data = éventuelle donnée à associer aux opérations.          * -*                                                                             * -*  Description : Enregistre un détection de format(s) binaire(s).             * -*                                                                             * -*  Retour      : Bilan de l'opération.                                        * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -bool register_format_matcher(format_match_fc func, void *data) -{ -    bool result;                            /* Bilan à retourner           */ -    size_t i;                               /* Boucle de parcours          */ -    const format_matcher_t *cur;            /* Elément parcouru et analysé */ -    format_matcher_t *new;                  /* Nouvel élément à définir    */ - -    g_rw_lock_writer_lock(&_formats_lock); - -    for (i = 0; i < _formats_matchers_count; i++) -    { -        cur = &_formats_matchers[i]; - -        if (cur->func == func && cur->data == data) -            break; - -    } - -    result = (i == _formats_matchers_count); - -    if (result) -    { -        _formats_matchers = (format_matcher_t *)realloc(_formats_matchers, -                                                        ++_formats_matchers_count * sizeof(format_matcher_t)); - -        new = &_formats_matchers[_formats_matchers_count - 1]; - -        new->func = func; -        new->data = data; - -    } - -    g_rw_lock_writer_unlock(&_formats_lock); - -    return result; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : key  = désignation rapide et interne d'un format.            * -*                name = désignation humaine au format de binaire.             * -*                func = procédure de chargement associée.                     * -*                                                                             * -*  Description : Enregistre un format de contenu binaire donné.               * -*                                                                             * -*  Retour      : Bilan de l'opération.                                        * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -bool register_format_loader(const char *key, const char *name, format_load_fc func) -{ -    bool result;                            /* Bilan à retourner           */ -    size_t i;                               /* Boucle de parcours          */ -    format_loader_t *new;                   /* Nouvel élément à définir    */ - -    g_rw_lock_writer_lock(&_formats_lock); - -    for (i = 0; i < _formats_loaders_count; i++) -        if (strcmp(_formats_loaders[i].key, key) == 0 && strcmp(_formats_loaders[i].name, name) == 0) -            break; - -    result = (i == _formats_loaders_count); - -    if (result) -    { -        _formats_loaders = (format_loader_t *)realloc(_formats_loaders, -                                                        ++_formats_loaders_count * sizeof(format_loader_t)); - -        new = &_formats_loaders[_formats_loaders_count - 1]; - -        new->key = strdup(key); -        new->name = strdup(name); - -        new->func = func; - -    } - -    g_rw_lock_writer_unlock(&_formats_lock); - -    return result; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : -                                                            * -*                                                                             * -*  Description : Charge les définitions de formats "natifs".                  * -*                                                                             * -*  Retour      : Bilan de l'opération.                                        * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -bool load_hard_coded_formats_definitions(void) -{ -    bool result;                            /* Bilan à retourner           */ - -    result = true; - -    /* Détections */ - -    result &= register_format_matcher(dwarf_is_matching, NULL); - -    /* Chargements */ - -    result &= register_format_loader("dwarf_v2", "Debugging With Arbitrary Record Formats (v2)", -                                     g_dwarfv2_format_new); - -    result &= register_format_loader("dwarf_v3", "Debugging With Arbitrary Record Formats (v3)", -                                     g_dwarfv3_format_new); - -    result &= register_format_loader("dwarf_v4", "Debugging With Arbitrary Record Formats (v4)", -                                     g_dwarfv4_format_new); - -    return result; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : -                                                            * -*                                                                             * -*  Description : Décharge toutes les définitions de formats.                  * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -void unload_formats_definitions(void) -{ -    size_t i;                               /* Boucle de parcours          */ - -    if (_formats_matchers != NULL) -        free(_formats_matchers); - -    _formats_matchers = NULL; -    _formats_matchers_count = 0; - -    for (i = 0; i < _formats_loaders_count; i++) -    { -        free(_formats_loaders[i].key); -        free(_formats_loaders[i].name); -    } - -    if (_formats_loaders != NULL) -        free(_formats_loaders); - -    _formats_loaders = NULL; -    _formats_loaders_count = 0; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : key = nom technique du processeur recherché.                 * -*                                                                             * -*  Description : Retrouve l'enregistrement correspondant à une architecture.  * -*                                                                             * -*  Retour      : Définition trouvée ou NULL en cas d'échec.                   * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static format_loader_t *find_format_by_key(const char *key) -{ -    format_loader_t *result;                /* Trouvaille à retourner      */ -    size_t i;                               /* Boucle de parcours          */ - -    /** -     * Le verrou d'accès global doit être posé ! -     */ - -    result = NULL; - -    if (key != NULL) -        for (i = 0; i < _formats_loaders_count; i++) -            if (strcmp(_formats_loaders[i].key, key) == 0) -                result = &_formats_loaders[i]; - -    return result; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : key = nom technique du format recherché.                     * -*                                                                             * -*  Description : Fournit le nom humain du format binaire visé.                * -*                                                                             * -*  Retour      : Désignation humaine trouvée ou NULL.                         * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -const char *get_binary_format_name(const char *key) -{ -    const char *result;                     /* Description à retourner     */ -    format_loader_t *def;                   /* Définition d'architecture   */ - -    g_rw_lock_reader_lock(&_formats_lock); - -    def = find_format_by_key(key); - -    if (def == NULL) -        result = NULL; -    else -        result = def->name; - -    g_rw_lock_reader_unlock(&_formats_lock); - -    return result; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : content = contenu binaire à parcourir.                       * -*                parent  = éventuel format exécutable déjà chargé.            * -*                key     = identifiant de format trouvé ou NULL. [OUT]        * -*                                                                             * -*  Description : Identifie un format binaire par son contenu.                 * -*                                                                             * -*  Retour      : Conclusion de haut niveau sur la reconnaissance effectuée.   * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -FormatMatchStatus find_matching_format(GBinContent *content, GExeFormat *parent, char **key) -{ -    FormatMatchStatus result;               /* Bilan à retourner           */ -    size_t i;                               /* Boucle de parcours          */ -    const format_matcher_t *cur;            /* Elément parcouru et analysé */ - -    result = FMS_UNKNOWN; - -    g_rw_lock_reader_lock(&_formats_lock); - -    for (i = 0; i < _formats_matchers_count && result == FMS_UNKNOWN; i++) -    { -        cur = &_formats_matchers[i]; - -        result = cur->func(content, parent, cur->data, key); - -    } - -    g_rw_lock_reader_unlock(&_formats_lock); - -    return result; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : key     = nom technique du processeur recherché.             * -*                content = contenu binaire pré-chargé à traiter.              * -*                parent  = contenu binaire principal éventuel déjà chargé.    * -*                                                                             * -*  Description : Charge le format binaire correspondant à un type.            * -*                                                                             * -*  Retour      : Format binaire instancié.                                    * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -GBinFormat *load_new_named_format(const char *key, GBinContent *content, GExeFormat *parent) -{ -    GBinFormat *result;                     /* Instance à retourner        */ -    format_loader_t *def;                   /* Définition d'architecture   */ - -    g_rw_lock_reader_lock(&_formats_lock); - -    def = find_format_by_key(key); - -    if (def == NULL) -        result = NULL; -    else -    { -        extern GtkStatusStack *get_global_status(void); - -        result = def->func(content, parent, get_global_status()); - -    } - -    g_rw_lock_reader_unlock(&_formats_lock); - -    return result; - -} diff --git a/src/core/formats.h b/src/core/formats.h deleted file mode 100644 index 2d155a0..0000000 --- a/src/core/formats.h +++ /dev/null @@ -1,80 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * formats.h - prototypes pour l'enregistrement et la fourniture des formats de binaires supportés - * - * Copyright (C) 2015-2017 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/>. - */ - - -#ifndef _CORE_FORMATS_H -#define _CORE_FORMATS_H - - -#include <glib-object.h> -#include <stdbool.h> - - -#include "../format/format.h" -#include "../format/executable.h" -#include "../gtkext/gtkstatusstack.h" - - - -/* Conclusion d'une opération de reconnaissance */ -typedef enum _FormatMatchStatus -{ -    FMS_MATCHED,                            /* Correspondance établie      */ -    FMS_FORWARDED,                          /* Sous-formats détectés       */ -    FMS_UNKNOWN,                            /* Aucun format reconnu        */ - -    FMS_COUNT - -} FormatMatchStatus; - - -/* Indication à propos du support d'un format */ -typedef FormatMatchStatus (* format_match_fc) (GBinContent *, GExeFormat *, void *, char **); - -/* Méthode de chargement d'un format */ -typedef GBinFormat * (* format_load_fc) (GBinContent *, GExeFormat *, GtkStatusStack *); - - -/* Enregistre un détection de format(s) binaire(s). */ -bool register_format_matcher(format_match_fc, void *); - -/* Enregistre un format de contenu binaire donné. */ -bool register_format_loader(const char *, const char *, format_load_fc); - -/* Charge les définitions de formats "natifs". */ -bool load_hard_coded_formats_definitions(void); - -/* Décharge toutes les définitions de formats. */ -void unload_formats_definitions(void); - -/* Fournit le nom humain du format binaire visé. */ -const char *get_binary_format_name(const char *); - -/* Identifie un format binaire par son contenu. */ -FormatMatchStatus find_matching_format(GBinContent *, GExeFormat *, char **); - -/* Charge le format binaire correspondant à un type. */ -GBinFormat *load_new_named_format(const char *, GBinContent *, GExeFormat *); - - - -#endif  /* _CORE_FORMATS_H */ diff --git a/src/format/Makefile.am b/src/format/Makefile.am index 8a47b82..24f03da 100644 --- a/src/format/Makefile.am +++ b/src/format/Makefile.am @@ -17,10 +17,7 @@ libformat_la_SOURCES =					\  	symbol-int.h						\  	symbol.h symbol.c -libformat_la_LIBADD =					\ -	dwarf/libformatdwarf.la				\ -	java/libformatjava.la				\ -	pe/libformatpe.la +libformat_la_LIBADD =   libformat_la_LDFLAGS =  @@ -34,4 +31,4 @@ AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS)  AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) -SUBDIRS = dwarf java pe +# SUBDIRS = dwarf java pe diff --git a/src/plugins/plugin-def.h b/src/plugins/plugin-def.h index b8b0e0d..8b7ac7d 100644 --- a/src/plugins/plugin-def.h +++ b/src/plugins/plugin-def.h @@ -130,14 +130,11 @@ typedef enum _PluginAction       * DPC_BINARY_PROCESSING | DPS_FORMAT       */ -    /* Détection et chargement */ -    PGA_FORMAT_MATCHER     = DPC_BINARY_PROCESSING | DPS_FORMAT | DEFINE_PLUGIN_ACTION(0), -      /* Accompagnement du chargement (fin) */ -    PGA_FORMAT_LOADER_LAST = DPC_BINARY_PROCESSING | DPS_FORMAT | DEFINE_PLUGIN_ACTION(1), +    PGA_FORMAT_LOADER_LAST = DPC_BINARY_PROCESSING | DPS_FORMAT | DEFINE_PLUGIN_ACTION(0),      /* Accompagnement du chargement (fin) */ -    PGA_FORMAT_PRELOAD     = DPC_BINARY_PROCESSING | DPS_FORMAT | DEFINE_PLUGIN_ACTION(2), +    PGA_FORMAT_PRELOAD     = DPC_BINARY_PROCESSING | DPS_FORMAT | DEFINE_PLUGIN_ACTION(1),      /**       * DPC_BINARY_PROCESSING | DPS_DISASSEMBLY @@ -269,19 +266,6 @@ typedef enum _PluginAction  //typedef PluginAction (* get_plugin_action_fc) (void); -/* PGA_FORMAT_MATCHER */ - -/* Bilans d'une reconnaissance */ -typedef enum _MatchingFormatAction -{ -    MFA_NONE,                               /* Aucune détection            */ -    MFA_MATCHED,                            /* Format reconnu              */ -    MFA_RELOAD,                             /* Rechargemet opéré           */ - -    MFA_COUNT - -} MatchingFormatAction; - diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index 7780f43..d309332 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -39,9 +39,6 @@  #include "plugin-int.h" -#include "../core/formats.h" - -  /* Initialise la classe des greffons. */  static void g_plugin_module_class_init(GPluginModuleClass *); @@ -199,7 +196,6 @@ GPluginModule *g_plugin_module_new(const gchar *filename)      uint32_t action;                        /* Identifiant d'une action    */      uint32_t category;                      /* Catégorie principale        */      uint32_t sub;                           /* Sous-catégorie visée        */ -    format_match_fc matcher;                /* Routine de reconnaissance   */      result = g_object_new(G_TYPE_PLUGIN_MODULE, NULL); @@ -334,17 +330,6 @@ GPluginModule *g_plugin_module_new(const gchar *filename)                          switch (action)                          { -                            case PGA_FORMAT_MATCHER: - -                                if (!load_plugin_symbol(result->module, -                                                        "is_format_matching", &matcher)) -                                    goto bad_plugin; - -                                if (!register_format_matcher(matcher, result)) -                                    goto bad_plugin; - -                                break; -                              case PGA_FORMAT_LOADER_LAST:                                  if (!load_plugin_symbol(result->module,                                                          "handle_binary_format", &result->handle_format))  | 
