summaryrefslogtreecommitdiff
path: root/plugins/pychrysa/plugin.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysa/plugin.c')
-rw-r--r--plugins/pychrysa/plugin.c129
1 files changed, 96 insertions, 33 deletions
diff --git a/plugins/pychrysa/plugin.c b/plugins/pychrysa/plugin.c
index 9601432..1bda007 100644
--- a/plugins/pychrysa/plugin.c
+++ b/plugins/pychrysa/plugin.c
@@ -25,10 +25,14 @@
#include "plugin.h"
+#include <pygobject.h>
+
+
#include "../../src/analysis/binary.h"
#include "../../src/plugins/plugin-int.h"
+#include "helpers.h"
#include "analysis/binary.h"
#include "debug/debugger.h"
@@ -65,6 +69,9 @@ static void g_python_plugin_class_init(GPythonPluginClass *);
/* Initialise l'instance d'un greffon Python. */
static void g_python_plugin_init(GPythonPlugin *);
+/* Procède à l'initialisation du greffon. */
+static bool g_python_plugin_do_init(GPythonPlugin *, GObject *);
+
/* Indique l'utilité pratique du greffon. */
static PluginAction g_python_plugin_get_action(const GPythonPlugin *);
@@ -106,6 +113,9 @@ static PyObject *pychrysa_plugin_run(PyObject *, PyObject *);
/* Définit les constantes pour les greffons en Python. */
static bool pychrysa_plugin_define_constants(PyObject *);
+/* Procède à l'initialisation du greffon. */
+static PyObject *pychrysa_plugin_init(PyObject *, PyObject *);
+
/* Définit le comportement par défaut d'un greffon Python. */
static PyObject *pychrysa_plugin_get_action(PyObject *, PyObject *);
@@ -255,29 +265,6 @@ static void g_python_plugin_init(GPythonPlugin *plugin)
-PyObject *run_python_method(PyObject *module, const char *method, PyObject *args)
-{
- PyObject *result; /* Bilan à retourner */
- PyObject *func; /* Fonction visée */
-
- result = NULL;
-
- func = PyObject_GetAttrString(module, method);
- if (func == NULL) return NULL;
-
- if (PyCallable_Check(func))
- {
- result = PyObject_CallObject(func, args);
- if (result == NULL) PyErr_Print();
- }
- else if (PyErr_Occurred()) PyErr_Print();
-
- Py_DECREF(func);
-
- return result;
-
-}
-
/******************************************************************************
* *
@@ -333,7 +320,9 @@ GPluginModule *g_python_plugin_new(const char *modname, const char *filename)
G_PLUGIN_MODULE(result)->name = strdup(modname);
G_PLUGIN_MODULE(result)->name = stradd(G_PLUGIN_MODULE(result)->name, ".py");
+ G_PLUGIN_MODULE(result)->filename = strdup(G_PLUGIN_MODULE(result)->name);
+ G_PLUGIN_MODULE(result)->init = g_python_plugin_do_init;
G_PLUGIN_MODULE(result)->get_action = g_python_plugin_get_action;
G_PLUGIN_MODULE(result)->is_matching = g_python_plugin_is_matching;
@@ -360,6 +349,44 @@ GPluginModule *g_python_plugin_new(const char *modname, const char *filename)
/******************************************************************************
* *
+* Paramètres : plugin = greffon à initialiser. *
+* ref = espace de référencement global. *
+* *
+* Description : Procède à l'initialisation du greffon. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_python_plugin_do_init(GPythonPlugin *plugin, GObject *ref)
+{
+ bool result; /* Bilan à retourner */
+ PyObject *args; /* Arguments pour l'appel */
+ PyObject *value; /* Valeur obtenue */
+ int cmp; /* Bilan de la comparaison */
+
+ args = PyTuple_New(1);
+ PyTuple_SetItem(args, 0, pygobject_new(ref));
+
+ value = run_python_method(plugin->instance, "init", args);
+
+ if (PyObject_Cmp(value, Py_True, &cmp) == -1)
+ result = false;
+ else
+ result = (cmp == 0);
+
+ Py_XDECREF(value);
+ Py_DECREF(args);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : plugin = greffon de prise en charge à utiliser. *
* *
* Description : Indique l'utilité pratique du greffon. *
@@ -669,6 +696,27 @@ static bool pychrysa_plugin_define_constants(PyObject *dict)
* Paramètres : self = classe assurant le lien avec l'éditeur de messages. *
* args = arguments fournis à l'appel. *
* *
+* Description : Procède à l'initialisation du greffon. *
+* *
+* Retour : Rien en équivalent Python. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *pychrysa_plugin_init(PyObject *self, PyObject *args)
+{
+ Py_INCREF(Py_True);
+ return Py_True;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = classe assurant le lien avec l'éditeur de messages. *
+* args = arguments fournis à l'appel. *
+* *
* Description : Définit le comportement par défaut d'un greffon Python. *
* *
* Retour : Rien en équivalent Python. *
@@ -820,20 +868,35 @@ bool add_plugin_to_python_module(PyObject *module)
static PyMethodDef pychrysa_plugin_methods[] = {
- { "get_action", (PyCFunction)pychrysa_plugin_get_action, METH_NOARGS,
- "Register the plugin for given actions."
+ {
+ "init", (PyCFunction)pychrysa_plugin_init,
+ METH_VARARGS,
+ "Initialize the plugin."
+ },
+ {
+ "get_action", (PyCFunction)pychrysa_plugin_get_action,
+ METH_NOARGS,
+ "Register the plugin for given actions."
},
- { "is_matching", (PyCFunction)pychrysa_plugin_is_matching, METH_VARARGS,
- "Define if the given file can be handled."
+ {
+ "is_matching", (PyCFunction)pychrysa_plugin_is_matching,
+ METH_VARARGS,
+ "Define if the given file can be handled."
},
- { "handle_debugger", (PyCFunction)pychrysa_plugin_handle_debugger, METH_VARARGS,
- "Be notify about debugger attaching or detaching."
+ {
+ "handle_debugger", (PyCFunction)pychrysa_plugin_handle_debugger,
+ METH_VARARGS,
+ "Be notify about debugger attaching or detaching."
},
- { "run", (PyCFunction)pychrysa_plugin_run, METH_VARARGS,
- "Run the plugin for a specific action."
+ {
+ "run", (PyCFunction)pychrysa_plugin_run,
+ METH_VARARGS,
+ "Run the plugin for a specific action."
},
- { "add_wgt", (PyCFunction)add_wgt, METH_VARARGS,
- "Run the plugin for a specific action."
+ {
+ "add_wgt", (PyCFunction)add_wgt,
+ METH_VARARGS,
+ "Run the plugin for a specific action."
},
NULL
};