diff options
| author | Cyrille Bagard <nocbos@gmail.com> | 2015-01-26 21:37:49 (GMT) | 
|---|---|---|
| committer | Cyrille Bagard <nocbos@gmail.com> | 2015-01-26 21:37:49 (GMT) | 
| commit | 262c95e0b088a56e9fd919edc57ad19f85e2e40e (patch) | |
| tree | 8510a15924423abb3208610f724d911f2f79b9a6 /src/plugins | |
| parent | 0993276d6450919c6d178182c5fd26497b62d5fc (diff) | |
Begun to rewrite the whole plugins system.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@461 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/plugins')
| -rw-r--r-- | src/plugins/pglist.c | 149 | ||||
| -rw-r--r-- | src/plugins/pglist.h | 28 | ||||
| -rw-r--r-- | src/plugins/plugin-def.h | 194 | ||||
| -rw-r--r-- | src/plugins/plugin-int.h | 29 | ||||
| -rw-r--r-- | src/plugins/plugin.c | 231 | ||||
| -rw-r--r-- | src/plugins/plugin.h | 21 | 
6 files changed, 411 insertions, 241 deletions
| diff --git a/src/plugins/pglist.c b/src/plugins/pglist.c index 9286085..70fc66a 100644 --- a/src/plugins/pglist.c +++ b/src/plugins/pglist.c @@ -25,6 +25,7 @@  #include "pglist.h" +#include <assert.h>  #include <dirent.h>  #include <malloc.h>  #include <string.h> @@ -37,14 +38,23 @@  #include "../common/extstr.h" +/* Représentation dédiée aux listes de greffons */ +typedef struct _pg_array +{ +    PluginAction action;                    /* Action commune ou PGA_ALL   */ + +    GPluginModule **plugins;                /* Liste de greffons           */ +    size_t plugins_count;                   /* Taille de cette liste       */ + +} pg_array;  /* Propriétés de l'ensemble des greffons */  typedef struct _plugins_list  {      GObject *ref;                           /* Référencement global        */ -    GPluginModule **plugins;                /* Liste de greffons           */ -    size_t plugins_count;                   /* Taille de cette liste       */ +    pg_array *all;                          /* Liste de tous les greffons  */ +    pg_array sorted[PGA_COUNT];             /* Tri par catégories          */  } plugins_list; @@ -75,9 +85,17 @@ void browse_directory_for_plugins(plugins_list *, const char *);  bool init_all_plugins(GObject *ref)  { +    size_t i;                               /* Boucle de parcours          */ +      _list.ref = ref;      g_object_ref(ref); +    for (i = 0; i < PGA_COUNT; i++) +        _list.sorted[i].action = PGA_EMPTY; + +    _list.sorted[0].action = PGA_ALL; +    _list.all = &_list.sorted[0]; +      browse_directory_for_plugins(&_list, PACKAGE_SOURCE_DIR "/plugins");      return true; @@ -101,11 +119,11 @@ void exit_all_plugins(void)  {      size_t i;                               /* Boucle de parcours          */ -    for (i = 0; i < _list.plugins_count; i++) -        g_object_unref(_list.plugins[i]); +    for (i = 0; i < _list.all->plugins_count; i++) +        g_object_unref(_list.all->plugins[i]); -    if (_list.plugins != NULL) -        free(_list.plugins); +    for (i = 0; i < PGA_COUNT; i++) +        free(_list.sorted[i].plugins);      g_object_unref(_list.ref); @@ -199,60 +217,30 @@ void browse_directory_for_plugins(plugins_list *list, const char *dir)  /******************************************************************************  *                                                                             *  *  Paramètres  : action = fonctionnalité recherchée.                          * -*                                                                             * -*  Description : Founit un greffon offrant le service demandé.                * -*                                                                             * -*  Retour      : Greffon satisfaisant ou NULL si aucun.                       * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -GPluginModule *get_one_plugin_for_action(PluginAction action) -{ -    GPluginModule *result;                  /* Greffon à retourner         */ -    size_t i;                               /* Boucle de parcours          */ - -    result = NULL; - -    for (i = 0; i < _list.plugins_count; i++) -        if (g_plugin_module_get_action(_list.plugins[i]) & action) -        { -            result = _list.plugins[i]; -            break; -        } - -    return result; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : action = fonctionnalité recherchée.                          *  *                count  = nombre de greffons trouvés. [OUT]                   *  *                                                                             *  *  Description : Founit les greffons offrant le service demandé.              *  *                                                                             * -*  Retour      : Liste de greffons correspondants à libérer de la mémoire.    * +*  Retour      : Liste de greffons correspondants issue d'un tri interne.     *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -GPluginModule **get_all_plugins_for_action(PluginAction action, size_t *count) +const GPluginModule **get_all_plugins_for_action(PluginAction action, size_t *count)  { -    GPluginModule **result;                 /* Greffon à retourner         */ +    const GPluginModule **result;           /* Greffon à retourner         */      size_t i;                               /* Boucle de parcours          */      result = NULL;      *count = 0; -    for (i = 0; i < _list.plugins_count; i++) -        if (g_plugin_module_get_action(_list.plugins[i]) & action) +    for (i = 0; i < PGA_COUNT; i++) +        if (_list.sorted[i].action == action)          { -            result = (GPluginModule **)realloc(result, ++(*count) * sizeof(GPluginModule *)); -            result[*count - 1] = _list.plugins[i]; +            result = (const GPluginModule **)_list.sorted[i].plugins; +            *count = _list.sorted[i].plugins_count; +            break;          }      return result; @@ -274,57 +262,50 @@ GPluginModule **get_all_plugins_for_action(PluginAction action, size_t *count)  void add_plugin_to_main_list(GPluginModule *plugin)  { -    plugins_list *list;                     /* Liste à modifier            */ +    const plugin_interface *interface;      /* Informations à consulter    */ +    size_t i;                               /* Boucle de parcours #1       */ +    size_t j;                               /* Boucle de parcours #2       */ -    list = &_list; +    interface = g_plugin_module_get_interface(plugin); -    if (plugin->init != NULL && !plugin->init(plugin, list->ref)) +    void add_plugin_into_array(pg_array *array, GPluginModule *pg)      { -        log_variadic_message(LMT_ERROR, _("Initialization of plugin '%s' failed !"), -                             plugin->filename); -        g_object_unref(G_OBJECT(plugin)); -        return; -    } +        array->plugins = (GPluginModule **)realloc(array->plugins, +                                                   ++array->plugins_count * sizeof(GPluginModule)); -    list->plugins = (GPluginModule **)realloc(list->plugins, ++list->plugins_count * sizeof(GPluginModule *)); -    list->plugins[list->plugins_count - 1] = plugin; +        array->plugins[array->plugins_count - 1] = pg; -} +    } +    /* FIXME : lock */ -/****************************************************************************** -*                                                                             * -*  Paramètres  : binary = binaire chargé en mémoire à traiter.                * -*                action = fonctionnalité recherchée.                          * -*                lock   = indique si l'exécution n'est pas celle principale.  * -*                                                                             * -*  Description : Opère une action donnée sur un binaire défini.               * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ +    add_plugin_into_array(_list.all, plugin); -void run_plugins_on_binary(GLoadedBinary *binary, PluginAction action, bool lock) -{ -    size_t i;                               /* Boucle de parcours          */ +    for (i = 0; i < interface->actions_count; i++) +    { +        if (interface->actions[i] == PGA_ALL) continue; -    /* -    if (lock) -        gdk_threads_enter(); -    */ +        for (j = 1; j < PGA_COUNT; j++) +        { +            if (_list.sorted[j].action == interface->actions[i]) +            { +                add_plugin_into_array(&_list.sorted[j], plugin); +                break; +            } + +            else if (_list.sorted[j].action == PGA_EMPTY) +            { +                add_plugin_into_array(&_list.sorted[j], plugin); +                _list.sorted[j].action = interface->actions[i]; +                break; +            } -    for (i = 0; i < _list.plugins_count; i++) -        if (g_plugin_module_get_action(_list.plugins[i]) & action) -            g_plugin_module_execute_action_on_binary(_list.plugins[i], binary, action); +        } + +        assert(j < PGA_COUNT); -    /* -    if (lock) -    { -        gdk_flush(); -        gdk_threads_leave();      } -    */ + +    /* FIXME : lock */  } diff --git a/src/plugins/pglist.h b/src/plugins/pglist.h index 4964d1d..fec31c2 100644 --- a/src/plugins/pglist.h +++ b/src/plugins/pglist.h @@ -41,14 +41,30 @@ bool init_all_plugins(GObject *);  /* Procède au déchargement des différents greffons présents. */  void exit_all_plugins(void); -/* Founit un greffon offrant le service demandé. */ -GPluginModule *get_one_plugin_for_action(PluginAction); -  /* Founit less greffons offrant le service demandé. */ -GPluginModule **get_all_plugins_for_action(PluginAction, size_t *) __attribute__ ((deprecated)); +const GPluginModule **get_all_plugins_for_action(PluginAction, size_t *); + + +/** + * Définitions des opérations appliquables à une catégories de greffons. + */ -/*Opère une action donnée sur un binaire défini. */ -void run_plugins_on_binary(GLoadedBinary *, PluginAction, bool); +#define process_all__plugins_for(a, f, ...)                 \ +    do                                                      \ +    {                                                       \ +        size_t __count;                                     \ +        const GPluginModule **__list;                       \ +        size_t __i;                                         \ +        __list = get_all_plugins_for_action(a, &__count);   \ +        for (__i = 0; __i < __count; __i++)                 \ +            f(__list[__i], a, __VA_ARGS__);                 \ +    }                                                       \ +    while (0) + +/* DPS_DISASSEMBLY */ + +#define process_disassembly_event(a, b) \ +    process_all__plugins_for(a, g_plugin_module_process_disassembly_event, b) diff --git a/src/plugins/plugin-def.h b/src/plugins/plugin-def.h index 176c55d..d1a13b7 100644 --- a/src/plugins/plugin-def.h +++ b/src/plugins/plugin-def.h @@ -26,8 +26,127 @@  #define _PLUGINS_PLUGIN_DEF_H -#include "../analysis/binary.h" -#include "../debug/debugger.h" +#include <gmodule.h> +#include <stdint.h> + + + + + +/* ------------------------ IDENTIFICATION DE COMPATIBILITES ------------------------ */ + + +/* Version identifiant les définitions courantes */ +typedef uint32_t plugin_abi_version_t; + +#define DEFINE_PLUGIN_ABI_VERSION(maj, min, rev) \ +    (((maj & 0xff) << 24) | ((min & 0xff) << 16) | (rev & 0xffff)) + +#define GET_ABI_MAJ_VERSION(vs) ((vs >> 24) & 0xff) +#define GET_ABI_MIN_VERSION(vs) ((vs >> 16) & 0xff) +#define GET_ABI_REV_VERSION(vs) (vs & 0xffff) + +#define CURRENT_ABI_VERSION DEFINE_PLUGIN_ABI_VERSION(0, 1, 0) + +//#define HARD_CODE_CURRENT_ABI_VERSION const plugin_abi_version_t abi_version = CURRENT_ABI_VERSION + + + +/* ------------------------- DEFINITION D'UN PROJET INTERNE ------------------------- */ + + +/* Idenifiant d'une action menée */ +typedef uint32_t plugin_action_t; + +#define DEFINE_PLUGIN_CATEGORY(cat) ((cat & 0xff) << 24) +#define DEFINE_PLUGIN_SUB_CATEGORY(sub) ((sub & 0xff) << 16) +#define DEFINE_PLUGIN_ACTION(a) (a & 0xffff) + +#define GET_PLUGIN_CATEGORY(val) ((val >> 24) & 0xff) +#define GET_PLUGIN_SUB_CATEGORY(val) ((val >> 16) & 0xff) + +#define MASK_PLUGIN_CATEGORY(val) (val & (0xff << 24)) +#define MASK_PLUGIN_SUB_CATEGORY(val) (val & (0xff << 16)) + + +#define DPC_NONE                DEFINE_PLUGIN_CATEGORY(0) +#define DPC_BINARY_PROCESSING   DEFINE_PLUGIN_CATEGORY(1) + +// GUI + +/* DPC_NONE */ + +#define DPS_NONE                DEFINE_PLUGIN_SUB_CATEGORY(0) + +/* DPC_BINARY_PROCESSING */ + +#define DPS_FORMAT              DEFINE_PLUGIN_SUB_CATEGORY(0) +#define DPS_DISASSEMBLY         DEFINE_PLUGIN_SUB_CATEGORY(1) + +// GUI -> project +// binary loaded +// binary unload + +// GUI -> dialog box + + + +/* Action(s) menée(s) par un greffon */ +typedef enum _PluginAction +{ +    /* Aucun intérêt */ +    PGA_NONE = DPC_NONE | DPS_NONE | DEFINE_PLUGIN_ACTION(0), + +    /** +     * DPC_BINARY_PROCESSING | DPS_FORMAT +     */ + +    /* Détection et chargement     */ +    PGA_FORMAT_MATCHER = DPC_BINARY_PROCESSING | DPS_FORMAT | DEFINE_PLUGIN_ACTION(0), + +    /** +     * DPC_BINARY_PROCESSING | DPS_DISASSEMBLY +     */ + +    /* Désassemblage démarré */ +    PGA_DISASSEMBLY_STARTED = DPC_BINARY_PROCESSING | DPS_DISASSEMBLY | DEFINE_PLUGIN_ACTION(0), + +    /* Désassemblage fini */ +    PGA_DISASSEMBLY_ENDED   = DPC_BINARY_PROCESSING | DPS_DISASSEMBLY | DEFINE_PLUGIN_ACTION(1), + + + +    PGA_DISASSEMBLE         = (1 << 1),     /* Désassemblage (non trivial) */ + +    PGA_BINARY_DISASSEMBLED = (1 << 2),     /* Désassemblage fini          */ +    PGA_BINARY_LINKED       = (1 << 3),     /* Liaison en place            */ +    PGA_BINARY_BOUNDED      = (1 << 4),     /* Limites de routines définies*/ +    PGA_BINARY_GROUPED      = (1 << 5),     /* Instructions regroupées     */ +    PGA_BINARY_PRINTED      = (1 << 6),     /* Instructions imprimées      */ + +    PGA_DISASS_PROCESS      = (1 << 6),     /* Traitement niveau assembleur*/ +    PGA_CODE_PROCESS        = (1 << 7),     /* Traitement du code existant */ + +    PGA_DEBUGGER_ATTACH     = (1 << 8),     /* Activation d'un débogueur   */ +    PGA_DEBUGGER_DETACH     = (1 << 9),     /* Désactivation d'un débogueur*/ + +    /** +     * Organisation interne : +     *   - rassemblement massif de tous les greffons. +     *   - marquage des cellules vides. +     */ +    PGA_ALL                 = 0xfffffffe, +    PGA_EMPTY               = 0xffffffff + +} PluginAction; + + + +/* MAJ !! */ +#define PGA_COUNT 6 + + + @@ -41,6 +160,7 @@ typedef enum _PluginType  /* Action(s) menée(s) par le greffon */ +#if 0  typedef enum _PluginAction  {      PGA_NONE                = (0 << 0),     /* Aucun intérêt               */ @@ -61,8 +181,9 @@ typedef enum _PluginAction      PGA_DEBUGGER_ATTACH     = (1 << 8),     /* Activation d'un débogueur   */      PGA_DEBUGGER_DETACH     = (1 << 9)      /* Désactivation d'un débogueur*/ -  } PluginAction; +#endif +  /* Actions éligibles pour run_plugins_on_binary() */ @@ -74,7 +195,7 @@ typedef enum _PluginAction  /* Fournit une indication sur le(s) type(s) du greffon présent. */ -typedef PluginType (* get_plugin_type_fc) (void); +//typedef PluginType (* get_plugin_type_fc) (void);  /* Fournit une indication sur le type d'opération(s) menée(s). */  //typedef PluginAction (* get_plugin_action_fc) (void); @@ -98,4 +219,69 @@ typedef enum _MatchingFormatAction + +/* ------------------------ PREMIER INTERFACAGE PROTOCOLAIRE ------------------------ */ + + +#define CHRYSALIDE_PLUGIN_MAGIC 0xdeadc0de1234abcdull + + +/* Définition d'un greffon */ +typedef struct _plugin_interface +{ +    uint64_t magic;                         /* Vérification a minima       */ +    plugin_abi_version_t abi_version;       /* Version du protocole utilisé*/ + +    const char *name;                       /* Désignation humaine courte  */ +    const char *desc;                       /* Description plus loquace    */ +    const char *version;                    /* Version du greffon          */ + +    const char **required;                  /* Pré-chargements requis      */ +    size_t required_count;                  /* Quantité de ces dépendances */ +    /* status */ + +    plugin_action_t *actions;               /* Liste des actions gérées    */ +    size_t actions_count;                   /* Quantité de ces actions     */ + +} plugin_interface; + + +/* Facilitations de déclarations */ + +#define EMPTY_PG_LIST(name)                         \ +    name = NULL,                                    \ +    name ## _count = 0                              \ + +#define BUILD_PG_LIST(name, lst)                    \ +    name = lst,                                     \ +    name ## _count = sizeof(lst) / sizeof(lst[0])   \ + +#define AL(...) BUILD_PG_LIST(.actions, ((plugin_action_t []){ __VA_ARGS__ })) + +#define RL(...) BUILD_PG_LIST(.required, ((char *[]){ __VA_ARGS__ })) + + +#define DEFINE_CHRYSALIDE_PLUGIN(n, d, v, r, a)                 \ +G_MODULE_EXPORT const plugin_interface _chrysalide_plugin = {   \ +                                                                \ +    .magic = CHRYSALIDE_PLUGIN_MAGIC,                           \ +    .abi_version = CURRENT_ABI_VERSION,                         \ +                                                                \ +    .name = n,                                                  \ +    .desc = d,                                                  \ +    .version = v,                                               \ +                                                                \ +    r,                                                          \ +                                                                \ +    a,                                                          \ +                                                                \ +} + + +/* Interfaçage primaire avec Chrysalide */ +#define DEFINE_CHRYSALIDE_ACTIVE_PLUGIN(n, d, v, ...)   \ +    DEFINE_CHRYSALIDE_PLUGIN(n, d, v, EMPTY_PG_LIST(.required), AL( __VA_ARGS__ )) + + +  #endif  /* _PLUGINS_PLUGIN_DEF_H */ diff --git a/src/plugins/plugin-int.h b/src/plugins/plugin-int.h index abe3995..de43a5c 100644 --- a/src/plugins/plugin-int.h +++ b/src/plugins/plugin-int.h @@ -33,6 +33,13 @@ +/* Exécute une action pendant un désassemblage de binaire. */ +typedef void (* pg_process_disassembly) (const GPluginModule *, PluginAction, GLoadedBinary *); + + + + +  /* Précise le nom associé au greffon. */  typedef char * (* get_plugin_name_fc) (void); @@ -53,19 +60,24 @@ typedef MatchingFormatAction (* is_matching_fc) (const GPluginModule *, char **,  typedef bool (* execute_action_on_binary_fc) (const GPluginModule *, GLoadedBinary *, PluginAction);  /* Exécute une action relative à un débogueur. */ -typedef bool (* execute_on_debugger_fc) (const GPluginModule *, GBinaryDebugger *, PluginAction); +//typedef bool (* execute_on_debugger_fc) (const GPluginModule *, GBinaryDebugger *, PluginAction); -/* Greffon pour OpenIDA (instance) */ +/* Greffon pour Chrysalide (instance) */  struct _GPluginModule  {      GObject parent;                         /* A laisser en premier        */ +    char *filename;                         /* Fichier associé au greffon  */      GModule *module;                        /* Abstration de manipulation  */ -    char *name;                             /* Nom associé au greffon      */ -    char *filename;                         /* Fichier associé au greffon  */ -    PluginType type;                        /* Type(s) du greffon          */ +    const plugin_interface *interface;      /* Déclaration d'interfaçage   */ + + + + +    //char *name;                             /* Nom associé au greffon      */ +    //PluginType type;                        /* Type(s) du greffon          */      init_plugin_fc init;                    /* Procédure d'initialisation  */      exit_plugin_fc exit;                    /* Procédure d'extinction      */ @@ -74,12 +86,15 @@ struct _GPluginModule      is_matching_fc is_matching;             /* Recherche de correspondance */      execute_action_on_binary_fc exec_on_bin;/* Action sur un binaire       */ -    execute_on_debugger_fc handle_debugger; /* Action liée à un débogueur  */ +    //execute_on_debugger_fc handle_debugger; /* Action liée à un débogueur  */ + + +    pg_process_disassembly proc_disass;     /* Catégorie 'désassemblage'   */  }; -/* Greffon pour OpenIDA (classe) */ +/* Greffon pour Chrysalide (classe) */  struct _GPluginModuleClass  {      GObjectClass parent;                    /* A laisser en premier        */ diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index c43ac37..fd55f8c 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -137,10 +137,7 @@ static void g_plugin_module_dispose(GPluginModule *plugin)  static void g_plugin_module_finalize(GPluginModule *plugin)  { -    if (plugin->name != NULL) -        free(plugin->name); -    if (plugin->filename != NULL) -        free(plugin->filename); +    free(plugin->filename);      G_OBJECT_CLASS(g_plugin_module_parent_class)->finalize(G_OBJECT(plugin)); @@ -162,13 +159,16 @@ static void g_plugin_module_finalize(GPluginModule *plugin)  GPluginModule *g_plugin_module_new(const gchar *filename)  {      GPluginModule *result;                  /* Structure à retourner       */ -    get_plugin_name_fc get_name;            /* Nom du greffon              */ -    //get_plugin_action_fc __get_type;        /* Type(s) de greffon          */ -    get_plugin_action_fc get_action;        /* Actions du greffon          */ +    plugin_abi_version_t current;           /* Version de l'ABI actuelle   */ +    size_t i;                               /* Boucle de parcours          */ +    uint32_t category;                      /* Catégorie principale        */ +    uint32_t sub;                           /* Sous-catégorie visée        */      char *dir;                              /* Répertoire modifiable       */      result = g_object_new(G_TYPE_PLUGIN_MODULE, NULL); +    result->filename = strdup(filename); +      result->module = g_module_open(filename, G_MODULE_BIND_LAZY);      if (result->module == NULL)      { @@ -178,58 +178,94 @@ GPluginModule *g_plugin_module_new(const gchar *filename)          goto bad_plugin;      } -    if (!g_module_symbol(result->module, "get_plugin_name", (gpointer *)&get_name)) +#define load_plugin_symbol(mod, sym, dest)                                          \ +    ({                                                                              \ +        bool __result;                                                              \ +        if (!g_module_symbol(mod, sym, (gpointer *)dest))                           \ +        {                                                                           \ +            log_variadic_message(LMT_ERROR,                                         \ +                                 _("No '%s' entry in plugin candidate '%s'"),       \ +                                 sym, result->filename);                            \ +            __result = false;                                                       \ +        }                                                                           \ +        else __result = true;                                                       \ +        __result;                                                                   \ +    }) + + +    /* Récupération de la version d'ABI */ + +    if (!load_plugin_symbol(result->module, "_chrysalide_plugin", &result->interface)) +        goto bad_plugin; + +    current = CURRENT_ABI_VERSION; + +    if (0 /* check_version() */)      { +          log_variadic_message(LMT_ERROR,  -                             _("No 'get_plugin_name' entry in plugin candidate '%s'"), +                             _("Bad version... '%s'"),                               filename);          goto bad_plugin; + +      } -    result->name = get_name(); -    result->filename = strdup(filename); +    /* Localisation des différents points d'entrée déclarés */ -    if (!g_module_symbol(result->module, "init_plugin", (gpointer *)&result->init)) -        result->init = NULL; +    for (i = 0; i < result->interface->actions_count; i++) +    { +        category = MASK_PLUGIN_CATEGORY(result->interface->actions[i]); +        sub = MASK_PLUGIN_SUB_CATEGORY(result->interface->actions[i]); -    if (!g_module_symbol(result->module, "exit_plugin", (gpointer *)&result->exit)) -        result->exit = NULL; +        printf(" GET cat = 0x%08x - sub = 0x%08x\n", category, sub); -    /* +        switch (category) +        { +            case DPC_NONE: +                switch (sub) +                { +                    case DPS_NONE: +                        break; -    if (!g_module_symbol(result->module, "get_plugin_type", (gpointer *)&__get_type)) -    { -        printf("No 'get_plugin_type' symbol found in the plugin '%s'\n", filename); -        goto bad_plugin; -    } +                    default: +                        log_variadic_message(LMT_WARNING, +                                             _("Unknown sub-category '0x%02x' in plugin '%s'..."), sub, filename); +                        break; -    result->type = __get_type(); +                } +                break; -    printf("Plugin type :: 0x%08x\n", result->type); -    */ +            case DPC_BINARY_PROCESSING: +                switch (sub) +                { -    if (!g_module_symbol(result->module, "get_plugin_action", (gpointer *)&get_action)) -    { -        printf("Err plugin get_action sym\n"); -        //g_object_destroy(result); -        return NULL; -    } -    result->get_action = get_action; +                    case DPS_DISASSEMBLY: +                        if (!load_plugin_symbol(result->module, +                                                "process_binary_disassembly", &result->proc_disass)) +                            goto bad_plugin; +                        break; -    if (g_plugin_module_get_action(result) & (PGA_BINARY_ACTIONS | /* FIXME : supprimer le reste */ PGA_DISASSEMBLE | PGA_DISASS_PROCESS | PGA_CODE_PROCESS)) -    { -        if (!g_module_symbol(result->module, "execute_action_on_binary", (gpointer *)&result->exec_on_bin)) -        { -            printf("Err plugin disass sym\n"); -            //g_object_destroy(result); -            return NULL; -        } +                    default: +                        log_variadic_message(LMT_WARNING, +                                             _("Unknown sub-category '0x%02x' in plugin '%s'..."), sub, filename); +                        break; + +                } + +                break; +            default: +                log_variadic_message(LMT_WARNING, +                                     _("Unknown category '0x%02x' in plugin '%s'..."), category, filename); +                break; + +        }      } @@ -237,6 +273,19 @@ GPluginModule *g_plugin_module_new(const gchar *filename) +    /* +    if (!g_module_symbol(result->module, "init_plugin", (gpointer *)&result->init)) +        result->init = NULL; + +    if (!g_module_symbol(result->module, "exit_plugin", (gpointer *)&result->exit)) +        result->exit = NULL; +    */ + + + + + +    /* Conclusion */      dir = strdup(filename);      dir = dirname(dir); @@ -261,17 +310,17 @@ GPluginModule *g_plugin_module_new(const gchar *filename)  *                                                                             *  *  Paramètres  : plugin = greffon à consulter.                                *  *                                                                             * -*  Description : Fournit le nom associé au greffon.                           * +*  Description : Fournit la description du greffon dans son intégralité.      *  *                                                                             * -*  Retour      : Désignation humaine.                                         * +*  Retour      : Interfaçage renseigné.                                       *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -const char *g_plugin_module_get_name(const GPluginModule *plugin) +const plugin_interface *g_plugin_module_get_interface(const GPluginModule *plugin)  { -    return plugin->name; +    return plugin->interface;  } @@ -294,12 +343,12 @@ void g_plugin_module_log_simple_message(const GPluginModule *plugin, LogMessageT      size_t len;                             /* Taille tampon disponible    */      char *buffer;                           /* Tampon du msg reconstitué   */ -    len = 1 + strlen(plugin->name) + 2 + strlen(msg) + 1; +    len = 3 +1 + strlen(plugin->interface->name) + 3 + 2 + strlen(msg) + 1;      buffer = calloc(len, sizeof(char)); -    strcpy(buffer, "["); -    strcat(buffer, plugin->name); -    strcat(buffer, "] "); +    strcpy(buffer, "<i>["); +    strcat(buffer, plugin->interface->name); +    strcat(buffer, "]</i> ");      strcat(buffer, msg);      log_simple_message(type, buffer); @@ -368,93 +417,23 @@ void g_plugin_module_log_variadic_message(const GPluginModule *plugin, LogMessag  /******************************************************************************  *                                                                             * -*  Paramètres  : plugin = greffon à consulter.                                * -*                                                                             * -*  Description : Indique les opérations offertes par un greffon donné.        * -*                                                                             * -*  Retour      : Action(s) offerte(s) par le greffon.                         * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -PluginAction g_plugin_module_get_action(const GPluginModule *plugin) -{ -    return plugin->get_action(plugin); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : plugin   = greffon de prise en charge à utiliser.            * -*                filename = éventuel nom de fichier associé ou NULL. [OUT]    * -*                data     = données chargées. [OUT]                           * -*                length   = quantité de ces données. [OUT]                    * -*                                                                             * -*  Description : Identifie un format à associer à un contenu binaire.         * -*                                                                             * -*  Retour      : Bilan de la recherche de correspondances.                    * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -MatchingFormatAction g_plugin_module_is_matching(const GPluginModule *plugin, char **filename, bin_t **data, off_t *length) -{ -    MatchingFormatAction result;            /* Valeur à retourner          */ - -    if (plugin->is_matching == NULL) -        return MFA_NONE; - -    result = plugin->is_matching(plugin, filename, data, length); - -    return result; - -} - - - - - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : plugin = greffon à consulter.                                * -*                binary = binaire dont le contenu est à traiter.              * -*                action = action attendue.                                    * +*  Paramètres  : plugin = greffon à manipuler.                                * +*                action = type d'action attendue.                             * +*                binary = binaire dont le contenu est en cours de traitement. *  *                                                                             * -*  Description : Exécute une action définie sur un binaire chargé.            * +*  Description : Exécute une action pendant un désassemblage de binaire.      *  *                                                                             * -*  Retour      : true si une action a été menée, false sinon.                 * +*  Retour      : -                                                            *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -bool g_plugin_module_execute_action_on_binary(const GPluginModule *plugin, GLoadedBinary *binary, PluginAction action) +void g_plugin_module_process_disassembly_event(const GPluginModule *plugin, PluginAction action, GLoadedBinary *binary)  { -    return plugin->exec_on_bin(plugin, binary, action); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : plugin   = greffon à consulter.                              * -*                debugger = débogueur à l'origine de l'opération.             * -*                action   = action attendue.                                  * -*                                                                             * -*  Description : Exécute une action relative à un débogueur.                  * -*                                                                             * -*  Retour      : true si une action a été menée, false sinon.                 * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ +    printf("plugin = %p\n", plugin); +    printf("plugin->proc_disass = %p\n", plugin->proc_disass); -bool g_plugin_module_handle_debugger(const GPluginModule *plugin, GBinaryDebugger *debugger, PluginAction action) -{ -    return plugin->handle_debugger(plugin, debugger, action); +    plugin->proc_disass(plugin, action, binary);  } diff --git a/src/plugins/plugin.h b/src/plugins/plugin.h index 01a523d..835b1c7 100644 --- a/src/plugins/plugin.h +++ b/src/plugins/plugin.h @@ -30,13 +30,14 @@  #include "plugin-def.h" +#include "../analysis/binary.h" -/* Greffon pour OpenIDA (instance) */ +/* Greffon pour Chrysalide (instance) */  typedef struct _GPluginModule GPluginModule; -/* Greffon pour OpenIDA (classe) */ +/* Greffon pour Chrysalide (classe) */  typedef struct _GPluginModuleClass GPluginModuleClass; @@ -54,22 +55,14 @@ GType g_plugin_module_get_type(void);  /* Crée un module pour un greffon donné. */  GPluginModule *g_plugin_module_new(const gchar *); -/* Fournit le nom associé au greffon. */ -const char *g_plugin_module_get_name(const GPluginModule *); +/* Fournit la description du greffon dans son intégralité. */ +const plugin_interface *g_plugin_module_get_interface(const GPluginModule *); -/* Indique les opérations offertes par un greffon donné. */ -PluginAction g_plugin_module_get_action(const GPluginModule *); -/* Identifie un format à associer à un contenu binaire. */ -MatchingFormatAction g_plugin_module_is_matching(const GPluginModule *, char **, bin_t **, off_t *); - -/* Exécute une action définie sur un binaire chargé. */ -bool g_plugin_module_execute_action_on_binary(const GPluginModule *, GLoadedBinary *, PluginAction); - -/* Exécute une action relative à un débogueur. */ -bool g_plugin_module_handle_debugger(const GPluginModule *, GBinaryDebugger *, PluginAction); +/* Exécute une action pendant un désassemblage de binaire. */ +void g_plugin_module_process_disassembly_event(const GPluginModule *, PluginAction, GLoadedBinary *); | 
