diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2015-07-17 16:36:21 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2015-07-17 16:36:21 (GMT) |
commit | 24d3836fcf8d443eb654b981f65478cd9923b8f1 (patch) | |
tree | 7672a28b864127e8958c3c6cce751dcf646d2fbe /plugins/pychrysa/analysis/blocks | |
parent | a61f089babe336b012da31a494b0f7470b6e1a9a (diff) |
Updated the Python bindings.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@552 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'plugins/pychrysa/analysis/blocks')
-rw-r--r-- | plugins/pychrysa/analysis/blocks/flow.c | 103 | ||||
-rw-r--r-- | plugins/pychrysa/analysis/blocks/flow.h | 3 | ||||
-rw-r--r-- | plugins/pychrysa/analysis/blocks/module.c | 37 | ||||
-rw-r--r-- | plugins/pychrysa/analysis/blocks/module.h | 2 | ||||
-rw-r--r-- | plugins/pychrysa/analysis/blocks/virtual.c | 74 | ||||
-rw-r--r-- | plugins/pychrysa/analysis/blocks/virtual.h | 3 |
6 files changed, 183 insertions, 39 deletions
diff --git a/plugins/pychrysa/analysis/blocks/flow.c b/plugins/pychrysa/analysis/blocks/flow.c index a5ee99c..626d5c8 100644 --- a/plugins/pychrysa/analysis/blocks/flow.c +++ b/plugins/pychrysa/analysis/blocks/flow.c @@ -31,12 +31,15 @@ #include <analysis/blocks/flow.h> +#include "../block.h" +#if 0 + /* Fournit les adresses limites d'un bloc d'exécution. */ static PyObject *py_flow_block_get_boundary_addresses(PyObject *, void *); @@ -180,3 +183,103 @@ bool register_python_flow_block(PyObject *module) return (ret == 0); } + +#endif + + + + + + + + + + + + + + + + + + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_flow_block_type(void) +{ + static PyMethodDef py_flow_block_methods[] = { + { NULL } + }; + + static PyGetSetDef py_flow_block_getseters[] = { + { NULL } + }; + + static PyTypeObject py_flow_block_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.analysis.blocks.FlowBlock", + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "PyChrysalide flow block", + + .tp_methods = py_flow_block_methods, + .tp_getset = py_flow_block_getseters, + + }; + + return &py_flow_block_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide...blocks.FlowBlock'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_flow_block(PyObject *module) +{ + PyTypeObject *py_flow_block_type; /* Type Python 'FlowBlock' */ + int ret; /* Bilan d'un appel */ + PyObject *dict; /* Dictionnaire du module */ + + py_flow_block_type = get_python_flow_block_type(); + + py_flow_block_type->tp_base = get_python_instr_block_type(); + py_flow_block_type->tp_basicsize = py_flow_block_type->tp_base->tp_basicsize; + + if (PyType_Ready(py_flow_block_type) != 0) + return false; + + Py_INCREF(py_flow_block_type); + ret = PyModule_AddObject(module, "FlowBlock", (PyObject *)py_flow_block_type); + if (ret != 0) return false; + + dict = PyModule_GetDict(module); + pygobject_register_class(dict, "FlowBlock", G_TYPE_FLOW_BLOCK, py_flow_block_type, + Py_BuildValue("(O)", py_flow_block_type->tp_base)); + + return true; + +} diff --git a/plugins/pychrysa/analysis/blocks/flow.h b/plugins/pychrysa/analysis/blocks/flow.h index 20d649e..69b6c24 100644 --- a/plugins/pychrysa/analysis/blocks/flow.h +++ b/plugins/pychrysa/analysis/blocks/flow.h @@ -31,6 +31,9 @@ +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_flow_block_type(void); + /* Prend en charge l'objet 'pychrysalide.analysis.blocks.FlowBlock'. */ bool register_python_flow_block(PyObject *); diff --git a/plugins/pychrysa/analysis/blocks/module.c b/plugins/pychrysa/analysis/blocks/module.c index 881ebc7..4968e90 100644 --- a/plugins/pychrysa/analysis/blocks/module.c +++ b/plugins/pychrysa/analysis/blocks/module.c @@ -25,6 +25,9 @@ #include "module.h" +#include <assert.h> + + #include "flow.h" #include "virtual.h" @@ -42,27 +45,47 @@ * * ******************************************************************************/ -bool add_blocks_module_to_python_module(PyObject *super) +bool add_analysis_blocks_module_to_python_module(PyObject *super) { bool result; /* Bilan à retourner */ - PyObject *module; /* Module Python mis en place */ + PyObject *module; /* Sous-module mis en place */ int ret; /* Bilan d'un appel */ - static PyMethodDef py_blocks_methods[] = { - { NULL } + static PyModuleDef py_chrysalide_blocks_module = { + + .m_base = PyModuleDef_HEAD_INIT, + + .m_name = "pychrysalide.analysis.blocks", + .m_doc = "Python module for Chrysalide.analysis.blocks", + + .m_size = -1, + }; - module = Py_InitModule("pychrysalide.analysis.blocks", py_blocks_methods); + result = false; + + module = PyModule_Create(&py_chrysalide_blocks_module); if (module == NULL) return false; + ret = PyState_AddModule(super, &py_chrysalide_blocks_module); + if (ret != 0) goto loading_failed; + + ret = _PyImport_FixupBuiltin(module, "pychrysalide.analysis.blocks"); + if (ret != 0) goto loading_failed; + Py_INCREF(module); - ret = PyModule_AddObject(super, "pychrysalide.analysis.blocks", module); + ret = PyModule_AddObject(super, "blocks", module); + if (ret != 0) goto loading_failed; - result = (ret == 0); + result = true; result &= register_python_flow_block(module); result &= register_python_virtual_block(module); + loading_failed: + + assert(result); + return result; } diff --git a/plugins/pychrysa/analysis/blocks/module.h b/plugins/pychrysa/analysis/blocks/module.h index 395be19..dc2d17c 100644 --- a/plugins/pychrysa/analysis/blocks/module.h +++ b/plugins/pychrysa/analysis/blocks/module.h @@ -32,7 +32,7 @@ /* Ajoute le module 'blocks' au module Python. */ -bool add_blocks_module_to_python_module(PyObject *); +bool add_analysis_blocks_module_to_python_module(PyObject *); diff --git a/plugins/pychrysa/analysis/blocks/virtual.c b/plugins/pychrysa/analysis/blocks/virtual.c index 4f15371..bdc81b0 100644 --- a/plugins/pychrysa/analysis/blocks/virtual.c +++ b/plugins/pychrysa/analysis/blocks/virtual.c @@ -31,35 +31,24 @@ #include <analysis/blocks/virtual.h> - - - - - - - - - +#include "../block.h" /****************************************************************************** * * -* Paramètres : module = module dont la définition est à compléter. * +* Paramètres : - * * * -* Description : Prend en charge l'objet 'pychrysalide.....VirtualBlock'. * +* Description : Fournit un accès à une définition de type à diffuser. * * * -* Retour : Bilan de l'opération. * +* Retour : Définition d'objet pour Python. * * * * Remarques : - * * * ******************************************************************************/ -bool register_python_virtual_block(PyObject *module) +PyTypeObject *get_python_virtual_block_type(void) { - PyObject *parent_mod; /* Module de la classe parente */ - int ret; /* Bilan d'un appel */ - static PyMethodDef py_virtual_block_methods[] = { { NULL } }; @@ -70,35 +59,58 @@ bool register_python_virtual_block(PyObject *module) static PyTypeObject py_virtual_block_type = { - PyObject_HEAD_INIT(NULL) + PyVarObject_HEAD_INIT(NULL, 0) .tp_name = "pychrysalide.analysis.blocks.VirtualBlock", - .tp_basicsize = sizeof(PyGObject), - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + .tp_flags = Py_TPFLAGS_DEFAULT, - .tp_doc = "PyChrysalide basic virtual block", + .tp_doc = "PyChrysalide virtual block", .tp_methods = py_virtual_block_methods, - .tp_getset = py_virtual_block_getseters + .tp_getset = py_virtual_block_getseters, }; - parent_mod = PyImport_ImportModule("pychrysalide.analysis"); - if (parent_mod == NULL) return false; + return &py_virtual_block_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide...blocks.VirtualBlock'.* +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_virtual_block(PyObject *module) +{ + PyTypeObject *py_virtual_block_type; /* Type Python 'VirtualBlock' */ + int ret; /* Bilan d'un appel */ + PyObject *dict; /* Dictionnaire du module */ + + py_virtual_block_type = get_python_virtual_block_type(); - py_virtual_block_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(parent_mod, "InstrBlock"); - Py_DECREF(parent_mod); + py_virtual_block_type->tp_base = get_python_instr_block_type(); + py_virtual_block_type->tp_basicsize = py_virtual_block_type->tp_base->tp_basicsize; - if (PyType_Ready(&py_virtual_block_type) < 0) + if (PyType_Ready(py_virtual_block_type) != 0) return false; - Py_INCREF(&py_virtual_block_type); - ret = PyModule_AddObject(module, "VirtualBlock", (PyObject *)&py_virtual_block_type); + Py_INCREF(py_virtual_block_type); + ret = PyModule_AddObject(module, "VirtualBlock", (PyObject *)py_virtual_block_type); + if (ret != 0) return false; - pygobject_register_class(module, "GVirtualBlock", G_TYPE_VIRTUAL_BLOCK, &py_virtual_block_type, - Py_BuildValue("(O)", py_virtual_block_type.tp_base)); + dict = PyModule_GetDict(module); + pygobject_register_class(dict, "VirtualBlock", G_TYPE_VIRTUAL_BLOCK, py_virtual_block_type, + Py_BuildValue("(O)", py_virtual_block_type->tp_base)); - return (ret == 0); + return true; } diff --git a/plugins/pychrysa/analysis/blocks/virtual.h b/plugins/pychrysa/analysis/blocks/virtual.h index 1c70b34..0bfaf82 100644 --- a/plugins/pychrysa/analysis/blocks/virtual.h +++ b/plugins/pychrysa/analysis/blocks/virtual.h @@ -31,6 +31,9 @@ +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_virtual_block_type(void); + /* Prend en charge l'objet 'pychrysalide.analysis.blocks.VirtualBlock'. */ bool register_python_virtual_block(PyObject *); |