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/plugin.c | |
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/plugin.c')
-rw-r--r-- | src/plugins/plugin.c | 231 |
1 files changed, 105 insertions, 126 deletions
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); } |