diff options
Diffstat (limited to 'plugins/pychrysa/plugin.c')
-rw-r--r-- | plugins/pychrysa/plugin.c | 129 |
1 files changed, 45 insertions, 84 deletions
diff --git a/plugins/pychrysa/plugin.c b/plugins/pychrysa/plugin.c index e2ba78b..dd2517b 100644 --- a/plugins/pychrysa/plugin.c +++ b/plugins/pychrysa/plugin.c @@ -28,6 +28,8 @@ #include <pygobject.h> +#include <common/extstr.h> + #include "../../src/analysis/binary.h" #include "../../src/plugins/plugin-int.h" @@ -310,10 +312,10 @@ GPluginModule *g_python_plugin_new(const char *modname, const char *filename) 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)->init = (init_plugin_fc)g_python_plugin_do_init; + G_PLUGIN_MODULE(result)->get_action = (get_plugin_action_fc)g_python_plugin_get_action; - G_PLUGIN_MODULE(result)->is_matching = g_python_plugin_is_matching; + G_PLUGIN_MODULE(result)->is_matching = (is_matching_fc)g_python_plugin_is_matching; result->module = module; result->instance = instance; @@ -436,7 +438,7 @@ static MatchingFormatAction g_python_plugin_is_matching(const GPythonPlugin *plu args = PyTuple_New(2); PyTuple_SetItem(args, 0, PyString_FromString(*filename)); - PyTuple_SetItem(args, 1, PyByteArray_FromStringAndSize(*data, *length)); + PyTuple_SetItem(args, 1, PyByteArray_FromStringAndSize((char *)*data, *length)); value = run_python_method(plugin->instance, "is_matching", args); @@ -836,102 +838,61 @@ bool add_plugin_to_python_module(PyObject *module) { int ret; /* Bilan d'un appel */ + static PyMethodDef pychrysa_plugin_methods[] = { + { + "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." + }, + { + "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." + }, + { NULL } + }; -static PyMethodDef pychrysa_plugin_methods[] = { - { - "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." - }, - { - "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." - }, - NULL -}; - + static PyTypeObject pychrysa_plugin_type = { -static PyTypeObject pychrysa_plugin_type = { + PyObject_HEAD_INIT(NULL) - PyObject_HEAD_INIT(NULL) + .tp_name = "plugin.Plugin", + .tp_basicsize = sizeof(pychrysa_plugin), -#if PY_VERSION_HEX < 0x03000000 - 0, /*ob_size*/ -#endif + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - "plugin.Plugin", /* tp_name */ - sizeof(pychrysa_plugin), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved / tp_compare */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ - "PyCHRYSA Plugin objects", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - pychrysa_plugin_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - (newfunc)pychrysa_plugin_new, /* tp_new */ -}; + .tp_doc = "PyChrysalide plugin objects", + .tp_methods = pychrysa_plugin_methods, + .tp_new = (newfunc)pychrysa_plugin_new + }; if (PyType_Ready(&pychrysa_plugin_type) < 0) return false; - if (!pychrysa_plugin_define_constants(pychrysa_plugin_type.tp_dict)) return false; - - - Py_INCREF(&pychrysa_plugin_type); - PyModule_AddObject(module, "Plugin", (PyObject *)&pychrysa_plugin_type); - - - return true; /* FIXME */ + ret = PyModule_AddObject(module, "Plugin", (PyObject *)&pychrysa_plugin_type); + return (ret == 0); } |