diff options
Diffstat (limited to 'src/plugins')
| -rw-r--r-- | src/plugins/plugin-def.h | 27 | ||||
| -rw-r--r-- | src/plugins/plugin-int.h | 12 | ||||
| -rw-r--r-- | src/plugins/plugin.c | 81 | ||||
| -rw-r--r-- | src/plugins/plugin.h | 6 | 
4 files changed, 108 insertions, 18 deletions
| diff --git a/src/plugins/plugin-def.h b/src/plugins/plugin-def.h index 50b8df2..43ec28e 100644 --- a/src/plugins/plugin-def.h +++ b/src/plugins/plugin-def.h @@ -42,9 +42,13 @@ typedef enum _PluginType  /* Action(s) menée(s) par le greffon */  typedef enum _PluginAction  { -    PGA_DISASSEMBLE     = (1 << 0),         /* Désassemblage (non trivial) */ +    PGA_NONE            = (0 << 0),         /* Aucun intérêt               */ -    PGA_CODE_PROCESS    = (1 << 1)          /* Traitement du code existant */ +    PGA_FORMAT_MATCHER  = (1 << 0),         /* Détection et chargement     */ + +    PGA_DISASSEMBLE     = (1 << 1),         /* Désassemblage (non trivial) */ + +    PGA_CODE_PROCESS    = (1 << 2)          /* Traitement du code existant */  } PluginAction; @@ -54,11 +58,28 @@ typedef enum _PluginAction  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); +//typedef PluginAction (* get_plugin_action_fc) (void);  /* Exécute une action définie sur un binaire chargé. */  typedef bool (* execute_action_on_binary_fc) (GOpenidaBinary *, PluginAction); +/* 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; + + + + +  #endif  /* _PLUGINS_PLUGIN_DEF_H */ diff --git a/src/plugins/plugin-int.h b/src/plugins/plugin-int.h index 929dbf9..a0b5758 100644 --- a/src/plugins/plugin-int.h +++ b/src/plugins/plugin-int.h @@ -36,6 +36,11 @@  /* Procède à l'initialisation du greffon */  typedef bool (* init_plugin_fc) (GObject *); +/* Fournit une indication sur le type d'opération(s) menée(s). */ +typedef PluginAction (* get_plugin_action_fc) (const GPluginModule *); + +/* Identifie un format à associer à un contenu binaire. */ +typedef MatchingFormatAction (* is_matching_fc) (const GPluginModule *, char **, bin_t **, off_t *);  /* Greffon pour OpenIDA (instance) */ @@ -46,9 +51,11 @@ struct _GPluginModule      GModule *module;                        /* Abstration de manipulation  */      PluginType type;                        /* Type(s) du greffon          */ -    PluginAction action;                    /* Opération(s) menée(s)       */      init_plugin_fc init;                    /* Procédure d'initialisation  */ +    get_plugin_action_fc get_action;        /* Opération(s) menée(s)       */ + +    is_matching_fc is_matching;             /* Recherche de correspondance */      execute_action_on_binary_fc exec_on_bin;/* Action sur un binaire       */ @@ -66,6 +73,9 @@ struct _GPluginModuleClass + + +  /* Ajoute un greffon à la liste principale de greffons. */  void add_plugin_to_main_list(GPluginModule *); diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index 2443768..ce8ef37 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -99,7 +99,7 @@ GPluginModule *g_plugin_module_new(const gchar *filename, GObject *ref)  {      GPluginModule *result;                  /* Structure à retourner       */      get_plugin_action_fc __get_type;        /* Type(s) de greffon          */ -    get_plugin_action_fc __get_action;      /* Actions du greffon          */ +    get_plugin_action_fc get_action;        /* Actions du greffon          */      result = g_object_new(G_TYPE_PLUGIN_MODULE, NULL); @@ -107,6 +107,21 @@ GPluginModule *g_plugin_module_new(const gchar *filename, GObject *ref)      result->module = g_module_open(filename, G_MODULE_BIND_LAZY); +    if (!result->module) +    { +        printf("err null mod\n"); +        return NULL; + +    } + + +    if (!g_module_symbol(result->module, "init_plugin", (gpointer *)&result->init)) +    { +        printf("Err plugin init sym\n"); +        /* TODO */ +    } + +    /*      if (!g_module_symbol(result->module, "get_plugin_type", (gpointer *)&__get_type)) @@ -119,20 +134,20 @@ GPluginModule *g_plugin_module_new(const gchar *filename, GObject *ref)      printf("Plugin type :: 0x%08x\n", result->type); +    */ - -#if 1 -    if (!g_module_symbol(result->module, "get_plugin_action", (gpointer *)&__get_action)) +    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->action = __get_action(); +    result->get_action = get_action; +    /*      if (result->action & (PGA_DISASSEMBLE | PGA_CODE_PROCESS))      {          if (!g_module_symbol(result->module, "execute_action_on_binary", (gpointer *)&result->exec_on_bin)) @@ -144,14 +159,7 @@ GPluginModule *g_plugin_module_new(const gchar *filename, GObject *ref)      } -#endif  - - -    if (!g_module_symbol(result->module, "init_plugin", (gpointer *)&result->init)) -    { -        printf("Err plugin init sym\n"); -        /* TODO */ -    } +    */ @@ -188,11 +196,56 @@ GPluginModule *g_plugin_module_new(const gchar *filename, GObject *ref)  PluginAction g_plugin_module_get_action(const GPluginModule *plugin)  { -    return plugin->action; +    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          */ +    char *old_filename;                     /* Ancien nom de fichier       */ +    bin_t *old_data;                        /* Ancien contenu binaire      */ + +    if (plugin->is_matching == NULL) +        return MFA_NONE; + +    old_filename = *filename; +    old_data = *data; + +    result = plugin->is_matching(plugin, filename, data, length); + +    if (result == MFA_RELOAD) +    { +        if (old_filename != NULL) +            free(old_filename); +        free(old_data); +    } + +    return result;  } + + + +  /******************************************************************************  *                                                                             *  *  Paramètres  : plugin = greffon à consulter.                                * diff --git a/src/plugins/plugin.h b/src/plugins/plugin.h index d17cee5..8df0e0e 100644 --- a/src/plugins/plugin.h +++ b/src/plugins/plugin.h @@ -57,9 +57,15 @@ GPluginModule *g_plugin_module_new(const gchar *, GObject *);  /* 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 *, GOpenidaBinary *, PluginAction); + + +  #endif  /* _PLUGINS_PLUGIN_H */ | 
