diff options
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/Makefile.am | 10 | ||||
| -rw-r--r-- | src/core/collections.h | 2 | ||||
| -rw-r--r-- | src/core/columns.h | 59 | ||||
| -rw-r--r-- | src/core/core.c | 111 | ||||
| -rw-r--r-- | src/core/core.h | 14 | ||||
| -rw-r--r-- | src/core/demanglers.c | 37 | ||||
| -rw-r--r-- | src/core/demanglers.h | 2 | ||||
| -rw-r--r-- | src/core/global.c | 51 | ||||
| -rw-r--r-- | src/core/global.h | 7 | ||||
| -rw-r--r-- | src/core/logs.c | 13 | ||||
| -rw-r--r-- | src/core/logs.h | 9 | ||||
| -rw-r--r-- | src/core/paths.c | 49 | ||||
| -rw-r--r-- | src/core/processors.c | 5 | 
13 files changed, 304 insertions, 65 deletions
diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 12dcddd..ac1ae14 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -3,6 +3,7 @@ noinst_LTLIBRARIES = libcore.la  libcore_la_SOURCES =					\  	collections.h collections.c			\ +	columns.h							\  	core.h core.c						\  	demanglers.h demanglers.c			\  	global.h global.c					\ @@ -13,16 +14,9 @@ libcore_la_SOURCES =					\  	processors.h processors.c			\  	queue.h queue.c -libcore_la_LDFLAGS = $(LIBGTK_LIBS) $(LIBXML_LIBS) +libcore_la_CFLAGS = $(TOOLKIT_CFLAGS) $(LIBXML_CFLAGS)  devdir = $(includedir)/chrysalide/$(subdir:src/%=core/%)  dev_HEADERS = $(libcore_la_SOURCES:%c=) - - -AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) - -AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) - -SUBDIRS =  diff --git a/src/core/collections.h b/src/core/collections.h index 69da6f7..87f2435 100644 --- a/src/core/collections.h +++ b/src/core/collections.h @@ -49,4 +49,4 @@ void delete_collections_list(GList **); -#endif  /* _ANALYSIS_DB_COLLECTION_H */ +#endif  /* _CORE_COLLECTIONS_H */ diff --git a/src/core/columns.h b/src/core/columns.h new file mode 100644 index 0000000..81f78f8 --- /dev/null +++ b/src/core/columns.h @@ -0,0 +1,59 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * columns.h - prototypes pour l'énumération globale des colonnes de rendu + * + * Copyright (C) 2022 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_COLUMNS_H +#define _CORE_COLUMNS_H + + + +/* Désignation des colonnes d'une ligne */ +typedef enum _DisassLineColumn +{ +    DLC_PHYSICAL,                           /* Position physique           */ +    DLC_VIRTUAL,                            /* Adresse virtuelle           */ +    DLC_BINARY,                             /* Contenu sous forme binaire  */ +    DLC_ASSEMBLY_LABEL,                     /* Etiquette dans les données  */ +    DLC_ASSEMBLY_HEAD,                      /* Instruction pour assembleur */ +    DLC_ASSEMBLY,                           /* Code pour assembleur        */ +    DLC_COMMENTS,                           /* Commentaires éventuels      */ + +    DLC_COUNT, + +} DisassLineColumn; + + +/* Désignation des colonnes d'une ligne */ +typedef enum _HexLineColumn +{ +    HLC_PHYSICAL,                           /* Position physique           */ +    HLC_BINARY,                             /* Données binaires brutes     */ +    HLC_PADDING,                            /* Espacement forcé            */ +    HLC_TRANSLATION,                        /* Traduction de contenu       */ + +    HLC_COUNT, + +} HexLineColumn; + + + +#endif  /* _CORE_COLUMNS_H */ diff --git a/src/core/core.c b/src/core/core.c index 62f6821..636e41e 100644 --- a/src/core/core.c +++ b/src/core/core.c @@ -31,19 +31,19 @@  #include <openssl/ssl.h> -#include <config.h> - -  #include "collections.h"  #include "demanglers.h"  #include "global.h"  #include "params.h"  #include "processors.h"  #include "queue.h" +#include "../analysis/scan/core.h" +#ifdef INCLUDE_MAGIC_SUPPORT +#   include "../analysis/scan/items/magic/cookie.h" +#endif  #include "../common/io.h"  #include "../common/xdg.h"  #include "../glibext/linesegment.h" -#include "../plugins/dt.h" @@ -65,6 +65,7 @@ bool load_all_core_components(bool cs)      char *cfgdir;                           /* Répertoire de configuration */      GContentExplorer *explorer;             /* Explorateur de contenus     */      GContentResolver *resolver;             /* Résolveur de contenus       */ +    GScanNamespace *root_ns;                /* Espace de noms ROST racine  */      /**       * On mémorise les passages réussis. @@ -99,17 +100,28 @@ bool load_all_core_components(bool cs)              explorer = g_content_explorer_new();              set_current_content_explorer(explorer); +            g_object_unref(G_OBJECT(explorer));              resolver = g_content_resolver_new();              set_current_content_resolver(resolver); +            g_object_unref(G_OBJECT(resolver)); + +#ifdef INCLUDE_MAGIC_SUPPORT +            if (result) result = init_magic_cookie(); +#endif + +            root_ns = g_scan_namespace_new(NULL); +            set_rost_root_namespace(root_ns); +            g_object_unref(G_OBJECT(root_ns)); + +            if (result) result = populate_main_scan_namespace(root_ns); +            if (result) result = load_all_known_scan_token_modifiers();              if (result) result = init_segment_content_hash_table();              register_arch_gtypes();              init_operands_factory(); -            if (result) result = init_chrysalide_dynamic_types(); -          }      } @@ -135,14 +147,21 @@ void unload_all_core_components(bool cs)  {      if (cs)      { -        exit_chrysalide_dynamic_types(); -          exit_operands_factory(); +        exit_segment_content_hash_table(); +          unload_demanglers_definitions();          unload_processors_definitions(); +        unload_all_scan_token_modifiers(); +        set_rost_root_namespace(NULL); + +#ifdef INCLUDE_MAGIC_SUPPORT +        exit_magic_cookie(); +#endif +          set_current_content_resolver(NULL);          set_current_content_explorer(NULL); @@ -160,3 +179,79 @@ void unload_all_core_components(bool cs)      ERR_free_strings();  } + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : selected = liste d'éléments à décharger.                     * +*                                                                             * +*  Description : Charge une sélection d'éléments de base du programme.        * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool load_core_components(AvailableCoreComponent flags) +{ +    static bool result = false;             /* Bilan à retourner           */ +    static bool done = false;               /* Mémorisation des passages   */ +    GScanNamespace *root_ns;                /* Espace de noms ROST racine  */ + +    /** +     * On mémorise les passages réussis. +     */ +    if (!done) +    { +        done = true; +        result = true; + +        if (flags & ACC_SCAN_FEATURES) +        { +#ifdef INCLUDE_MAGIC_SUPPORT +            if (result) result = init_magic_cookie(); +#endif + +            root_ns = g_scan_namespace_new(NULL); +            set_rost_root_namespace(root_ns); +            g_object_unref(G_OBJECT(root_ns)); + +            if (result) result = populate_main_scan_namespace(root_ns); +            if (result) result = load_all_known_scan_token_modifiers(); + +        } + +    } + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : selected = liste d'éléments à décharger.                     * +*                                                                             * +*  Description : Décharge une sélection d'éléments de base du programme.      * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +void unload_core_components(AvailableCoreComponent flags) +{ +    if (flags & ACC_SCAN_FEATURES) +    { +        unload_all_scan_token_modifiers(); +        set_rost_root_namespace(NULL); + +#ifdef INCLUDE_MAGIC_SUPPORT +        exit_magic_cookie(); +#endif + +    } + +} diff --git a/src/core/core.h b/src/core/core.h index 0221f56..def2813 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -36,5 +36,19 @@ bool load_all_core_components(bool);  void unload_all_core_components(bool); +/* Eléments à (dé)charger disponibles */ +typedef enum _AvailableCoreComponent +{ +    ACC_SCAN_FEATURES = (1 << 0),           /* Espace de noms pour scan    */ + +} AvailableCoreComponent; + +/* Charge une sélection d'éléments de base du programme. */ +bool load_core_components(AvailableCoreComponent); + +/* Décharge une sélection d'éléments de base du programme. */ +void unload_core_components(AvailableCoreComponent); + +  #endif  /* _CORE_CORE_H */ diff --git a/src/core/demanglers.c b/src/core/demanglers.c index 400fd44..5518008 100644 --- a/src/core/demanglers.c +++ b/src/core/demanglers.c @@ -32,7 +32,7 @@  typedef struct _demangler_t  {      char *key;                              /* Clef pour un accès rapide   */ -    GType instance;                         /* Type à manipuler en interne */ +    GType type;                             /* Type à manipuler en interne */  } demangler_t; @@ -52,8 +52,7 @@ static demangler_t *find_demangler_by_key(const char *);  /******************************************************************************  *                                                                             * -*  Paramètres  : key      = désignation rapide et interne d'un décodeur.      * -*                instance = type GLib représentant le type à instancier.      * +*  Paramètres  : type = type GLib représentant le type à instancier.          *  *                                                                             *  *  Description : Enregistre un décodeur répondant à une appellation donnée.   *  *                                                                             * @@ -63,31 +62,47 @@ static demangler_t *find_demangler_by_key(const char *);  *                                                                             *  ******************************************************************************/ -bool register_demangler_type(const char *key, GType instance) +bool register_demangler_type(GType type)  {      bool result;                            /* Bilan à retourner           */ +    GCompDemangler *demangler;              /* Instance pour consultation  */ +    char *key;                              /* Désignation associée        */      demangler_t *new;                       /* Nouvel élément à définir    */ +    result = false; + +    demangler = g_object_new(type, NULL); + +    key = g_compiler_demangler_get_key(demangler); +    if (key == NULL) goto done; +      G_LOCK(_ddef_access);      new = find_demangler_by_key(key); -    result = (new == NULL); +    if (new != NULL) +        free(key); -    if (result) +    else      { -        _demanglers_definitions = (demangler_t *)realloc(_demanglers_definitions, -                                                         ++_demanglers_definitions_count * sizeof(demangler_t)); +        _demanglers_definitions =   realloc(_demanglers_definitions, +                                            ++_demanglers_definitions_count * sizeof(demangler_t));          new = &_demanglers_definitions[_demanglers_definitions_count - 1]; -        new->key = strdup(key); -        new->instance = instance; +        new->key = key; +        new->type = type; + +        result = true;      }      G_UNLOCK(_ddef_access); + done: + +    g_object_unref(G_OBJECT(demangler)); +      return result;  } @@ -182,7 +197,7 @@ GCompDemangler *get_compiler_demangler_for_key(const char *key)      if (def == NULL)          result = NULL;      else -        result = g_object_new(def->instance, NULL); +        result = g_object_new(def->type, NULL);      G_UNLOCK(_ddef_access); diff --git a/src/core/demanglers.h b/src/core/demanglers.h index 842f345..883692a 100644 --- a/src/core/demanglers.h +++ b/src/core/demanglers.h @@ -33,7 +33,7 @@  /* Enregistre un décodeur répondant à une appellation donnée. */ -bool register_demangler_type(const char *, GType); +bool register_demangler_type(GType);  /* Décharge toutes les définitions de décodeurs. */  void unload_demanglers_definitions(void); diff --git a/src/core/global.c b/src/core/global.c index 4ebb9e0..c99d711 100644 --- a/src/core/global.c +++ b/src/core/global.c @@ -40,6 +40,9 @@ static GContentExplorer *_explorer = NULL;  /* Résolveur de contenus */  static GContentResolver *_resolver = NULL; +/* Espace de noms racine pour ROST */ +static GScanNamespace *_rost_root_ns = NULL; +  /* Projet global actif */  static GStudyProject *_project = NULL; @@ -224,6 +227,54 @@ GContentResolver *get_current_content_resolver(void)  /******************************************************************************  *                                                                             * +*  Paramètres  : ns = espace de noms racine de ROST.                          * +*                                                                             * +*  Description : Définit l'adresse de l'espace de noms principal pour ROST.   * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +void set_rost_root_namespace(GScanNamespace *ns) +{ +    if (_rost_root_ns != NULL) +        g_object_unref(G_OBJECT(_rost_root_ns)); + +    _rost_root_ns = ns; + +    if (ns != NULL) +        g_object_ref_sink(G_OBJECT(ns)); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : -                                                            * +*                                                                             * +*  Description : Fournit l'adresse de l'espace de noms principal pour ROST.   * +*                                                                             * +*  Retour      : Espace de noms racine de ROST ou NULL si aucun (!).          * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GScanNamespace *get_rost_root_namespace(void) +{ +    assert(_rost_root_ns != NULL); + +    g_object_ref(G_OBJECT(_rost_root_ns)); + +    return _rost_root_ns; + +} + + +/****************************************************************************** +*                                                                             *  *  Paramètres  : project = éventuelle adresse du nouveau projet principal.    *  *                                                                             *  *  Description : Définit l'adresse du projet courant.                         * diff --git a/src/core/global.h b/src/core/global.h index 088a7c9..0a9172b 100644 --- a/src/core/global.h +++ b/src/core/global.h @@ -30,6 +30,7 @@  #include "../analysis/loading.h"  #include "../analysis/project.h" +#include "../analysis/scan/space.h"  #include "../glibext/delayed.h" @@ -58,6 +59,12 @@ void set_current_content_resolver(GContentResolver *);  /* Fournit l'adresse du résolveur de contenus courant. */  GContentResolver *get_current_content_resolver(void); +/* Définit l'adresse de l'espace de noms principal pour ROST. */ +void set_rost_root_namespace(GScanNamespace *); + +/* Fournit l'adresse de l'espace de noms principal pour ROST. */ +GScanNamespace *get_rost_root_namespace(void); +  /* Définit l'adresse du projet courant. */  void set_current_project(GStudyProject *); diff --git a/src/core/logs.c b/src/core/logs.c index 2769bd5..2b2b1ab 100644 --- a/src/core/logs.c +++ b/src/core/logs.c @@ -29,8 +29,10 @@  #include "../common/extstr.h" -#include "../gui/core/items.h" -#include "../gui/panels/log.h" +#ifdef INCLUDE_GTK_SUPPORT +#   include "../gui/core/items.h" +#   include "../gui/panels/log.h" +#endif @@ -107,10 +109,14 @@ void set_log_verbosity(LogMessageType level)  void log_simple_message(LogMessageType type, const char *msg)  { +#ifdef INCLUDE_GTK_SUPPORT      GEditorItem *item;                      /* Eventuel affichage présent  */ +#endif      if (type >= _verbosity)      { +#ifdef INCLUDE_GTK_SUPPORT +          item = find_editor_item_by_type(G_TYPE_LOG_PANEL);          if (item != NULL) @@ -120,6 +126,9 @@ void log_simple_message(LogMessageType type, const char *msg)          }          else + +#endif +              print_message_without_gui(type, msg);      } diff --git a/src/core/logs.h b/src/core/logs.h index a58a5a8..e8df8bd 100644 --- a/src/core/logs.h +++ b/src/core/logs.h @@ -130,6 +130,15 @@ void log_variadic_message(LogMessageType, const char *, ...);      }                                                                                                   \      while (0) +#define LOG_ERROR_REGCOMP(preg, errcode)                                                                \ +    do                                                                                                  \ +    {                                                                                                   \ +        char __msg[1024];                                                                               \ +        regerror(errcode, preg, __msg, sizeof(__msg));                                                  \ +        log_variadic_message(LMT_EXT_ERROR, "[%s:%u] regcomp: %s", __FUNCTION__, __LINE__, __msg);      \ +    }                                                                                                   \ +    while (0) +  #define LOG_ERROR_OPENSSL                                                                               \      do                                                                                                  \      {                                                                                                   \ diff --git a/src/core/paths.c b/src/core/paths.c index 5902e83..c9213bc 100644 --- a/src/core/paths.c +++ b/src/core/paths.c @@ -125,15 +125,13 @@ char *get_effective_directory(const char *template)  char *get_effective_directory_new(TargetDirectoryType type)  {      char *result;                           /* Répertoire à retourner      */ -#ifdef DISCARD_LOCAL +#if defined DISCARD_LOCAL && defined PYTHON_PACKAGE      Dl_info info;                           /* Informations dynamiques     */      int ret;                                /* Bilan d'une récupération    */      char *dyn_path_tmp;                     /* Chemin d'accès modifiable   */      const char *dyn_path;                   /* Chemin d'accès courant      */ -#   ifdef PYTHON_PACKAGE      size_t len;                             /* Taille de comparaison       */      size_t pos;                             /* Position dans une chaîne    */ -#   endif  #endif      /** @@ -155,20 +153,6 @@ char *get_effective_directory_new(TargetDirectoryType type)      result = NULL; -#ifdef DISCARD_LOCAL - -    ret = dladdr(__FUNCTION__, &info); -    if (ret == 0) -    { -        LOG_ERROR_DL_N("dladdr"); -        goto exit; -    } - -    dyn_path_tmp = strdup(info.dli_fname); -    dyn_path = dirname(dyn_path_tmp); - -#endif -      switch (type)      {          case TDT_PLUGINS_LIB: @@ -178,6 +162,16 @@ char *get_effective_directory_new(TargetDirectoryType type)  #else  #   ifdef PYTHON_PACKAGE +            ret = dladdr(__FUNCTION__, &info); +            if (ret == 0) +            { +                LOG_ERROR_DL_N("dladdr"); +                break; +            } + +            dyn_path_tmp = strdup(info.dli_fname); +            dyn_path = dirname(dyn_path_tmp); +              len = strlen("chrysalide-libs");              pos = strlen(dyn_path); @@ -193,9 +187,12 @@ char *get_effective_directory_new(TargetDirectoryType type)              result[pos] = '\0';              result = stradd(result, "chrysalide-plugins"); + bad_sync: + +            free(dyn_path_tmp); +  #   else -            result = strdup(dyn_path); -            result = stradd(result, G_DIR_SEPARATOR_S "chrysalide-plugins"); +            result = strdup(PLUGINS_LIB_DIR);  #   endif  #endif              break; @@ -206,20 +203,6 @@ char *get_effective_directory_new(TargetDirectoryType type)      } -#ifdef DISCARD_LOCAL - -#   ifdef PYTHON_PACKAGE - - bad_sync: - -#   endif - -    free(dyn_path_tmp); - - exit: - -#endif -      assert(result != NULL);      return result; diff --git a/src/core/processors.c b/src/core/processors.c index 666ddac..e4a558f 100644 --- a/src/core/processors.c +++ b/src/core/processors.c @@ -185,7 +185,10 @@ bool register_processor_type(GType type)      new = find_processor_by_key(key); -    if (new == NULL) +    if (new != NULL) +        free(key); + +    else      {          _processors_definitions = realloc(_processors_definitions,                                            ++_processors_definitions_count * sizeof(proc_t));  | 
