diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2018-08-16 09:16:53 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2018-08-16 09:16:53 (GMT) |
commit | fb315963527f6412273829f09513325e446eb6c9 (patch) | |
tree | 361f19767812a8f758545e8daa2973fe0b3c9de7 /plugins/pychrysalide/debug | |
parent | 36945bffa2ca648b58c99905ebf9b1b536a9188a (diff) |
Reorganized the Python plugin code.
Diffstat (limited to 'plugins/pychrysalide/debug')
-rw-r--r-- | plugins/pychrysalide/debug/debugger.c | 20 | ||||
-rw-r--r-- | plugins/pychrysalide/debug/debugger.h | 2 | ||||
-rw-r--r-- | plugins/pychrysalide/debug/gdbrsp/gdb.c | 21 | ||||
-rw-r--r-- | plugins/pychrysalide/debug/gdbrsp/gdb.h | 2 | ||||
-rw-r--r-- | plugins/pychrysalide/debug/gdbrsp/module.c | 46 | ||||
-rw-r--r-- | plugins/pychrysalide/debug/gdbrsp/module.h | 7 | ||||
-rw-r--r-- | plugins/pychrysalide/debug/module.c | 53 | ||||
-rw-r--r-- | plugins/pychrysalide/debug/module.h | 7 |
8 files changed, 98 insertions, 60 deletions
diff --git a/plugins/pychrysalide/debug/debugger.c b/plugins/pychrysalide/debug/debugger.c index 5d8181f..0a7f97c 100644 --- a/plugins/pychrysalide/debug/debugger.c +++ b/plugins/pychrysalide/debug/debugger.c @@ -33,6 +33,7 @@ #include <debug/debugger.h> +#include "../access.h" #include "../helpers.h" #include "../arch/vmpa.h" @@ -1168,17 +1169,24 @@ PyTypeObject *get_python_binary_debugger_type(void) * * ******************************************************************************/ -bool register_python_binary_debugger(PyObject *module) +bool ensure_python_binary_debugger_is_registered(void) { - PyTypeObject *py_binary_debugger_type; /* Type Python 'BinaryDebugger'*/ + PyTypeObject *type; /* Type Python 'BinaryDebugger'*/ + PyObject *module; /* Module à recompléter */ PyObject *dict; /* Dictionnaire du module */ - py_binary_debugger_type = get_python_binary_debugger_type(); + type = get_python_binary_debugger_type(); - dict = PyModule_GetDict(module); + if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) + { + module = get_access_to_python_module("pychrysalide.debug"); + + dict = PyModule_GetDict(module); - if (!register_class_for_pygobject(dict, G_TYPE_BINARY_DEBUGGER, py_binary_debugger_type, &PyGObject_Type)) - return false; + if (!register_class_for_pygobject(dict, G_TYPE_BINARY_DEBUGGER, type, &PyGObject_Type)) + return false; + + } return true; diff --git a/plugins/pychrysalide/debug/debugger.h b/plugins/pychrysalide/debug/debugger.h index 97f91ac..7a47456 100644 --- a/plugins/pychrysalide/debug/debugger.h +++ b/plugins/pychrysalide/debug/debugger.h @@ -35,7 +35,7 @@ PyTypeObject *get_python_binary_debugger_type(void); /* Prend en charge l'objet 'pychrysalide.debug.BinaryDebugger'. */ -bool register_python_binary_debugger(PyObject *); +bool ensure_python_binary_debugger_is_registered(void); diff --git a/plugins/pychrysalide/debug/gdbrsp/gdb.c b/plugins/pychrysalide/debug/gdbrsp/gdb.c index a4cde20..df56ca4 100644 --- a/plugins/pychrysalide/debug/gdbrsp/gdb.c +++ b/plugins/pychrysalide/debug/gdbrsp/gdb.c @@ -35,6 +35,7 @@ #include "../debugger.h" +#include "../../access.h" #include "../../helpers.h" #include "../../analysis/binary.h" @@ -148,18 +149,24 @@ PyTypeObject *get_python_gdb_debugger_type(void) * * ******************************************************************************/ -bool register_python_gdb_debugger(PyObject *module) +bool ensure_python_gdb_debugger_is_registered(void) { - PyTypeObject *py_gdb_debugger_type; /* Type Python 'GdbDebugger' */ + PyTypeObject *type; /* Type Python 'GdbDebugger' */ + PyObject *module; /* Module à recompléter */ PyObject *dict; /* Dictionnaire du module */ - py_gdb_debugger_type = get_python_gdb_debugger_type(); + type = get_python_gdb_debugger_type(); - dict = PyModule_GetDict(module); + if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) + { + module = get_access_to_python_module("pychrysalide.debug.gdbrsp"); + + dict = PyModule_GetDict(module); - if (!register_class_for_pygobject(dict, G_TYPE_GDB_DEBUGGER, - py_gdb_debugger_type, get_python_binary_debugger_type())) - return false; + if (!register_class_for_pygobject(dict, G_TYPE_GDB_DEBUGGER, type, get_python_binary_debugger_type())) + return false; + + } return true; diff --git a/plugins/pychrysalide/debug/gdbrsp/gdb.h b/plugins/pychrysalide/debug/gdbrsp/gdb.h index 00afab5..057a38d 100644 --- a/plugins/pychrysalide/debug/gdbrsp/gdb.h +++ b/plugins/pychrysalide/debug/gdbrsp/gdb.h @@ -35,7 +35,7 @@ PyTypeObject *get_python_gdb_debugger_type(void); /* Prend en charge l'objet 'pychrysalide.debug.gdbrsp.GdbDebugger'. */ -bool register_python_gdb_debugger(PyObject *); +bool ensure_python_gdb_debugger_is_registered(void); diff --git a/plugins/pychrysalide/debug/gdbrsp/module.c b/plugins/pychrysalide/debug/gdbrsp/module.c index 6e7896c..c077aa7 100644 --- a/plugins/pychrysalide/debug/gdbrsp/module.c +++ b/plugins/pychrysalide/debug/gdbrsp/module.c @@ -26,28 +26,28 @@ #include "gdb.h" +#include "../../helpers.h" /****************************************************************************** * * -* Paramètres : module = module dont la définition est à compléter. * +* Paramètres : super = module dont la définition est à compléter. * * * -* Description : Ajoute le module 'debug.gdbrsp' au module Python. * +* Description : Ajoute le module 'debug.gdbresp' à un module Python. * * * -* Retour : - * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -bool add_debug_gdbrsp_module_to_python_module(PyObject *super) +bool add_debug_gdbresp_module(PyObject *super) { bool result; /* Bilan à retourner */ PyObject *module; /* Sous-module mis en place */ - int ret; /* Bilan d'un appel */ - static PyModuleDef py_chrysalide_gdbrsp_module = { + static PyModuleDef py_chrysalide_debug_gdbresp_module = { .m_base = PyModuleDef_HEAD_INIT, @@ -58,26 +58,34 @@ bool add_debug_gdbrsp_module_to_python_module(PyObject *super) }; - result = false; + module = build_python_module(super, &py_chrysalide_debug_gdbresp_module); - module = PyModule_Create(&py_chrysalide_gdbrsp_module); - if (module == NULL) return false; + result = (module != NULL); - ret = PyState_AddModule(super, &py_chrysalide_gdbrsp_module); - if (ret != 0) goto loading_failed; + return result; - ret = _PyImport_FixupBuiltin(module, "pychrysalide.debug.gdbrsp"); - if (ret != 0) goto loading_failed; +} - Py_INCREF(module); - ret = PyModule_AddObject(super, "gdbrsp", module); - if (ret != 0) goto loading_failed; - result = true; +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Intègre les objets du module 'debug.gdbresp'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ - result &= register_python_gdb_debugger(module); +bool populate_debug_gdbresp_module(void) +{ + bool result; /* Bilan à retourner */ + + result = true; - loading_failed: + if (result) result = ensure_python_gdb_debugger_is_registered(); assert(result); diff --git a/plugins/pychrysalide/debug/gdbrsp/module.h b/plugins/pychrysalide/debug/gdbrsp/module.h index edc2b11..0ed3719 100644 --- a/plugins/pychrysalide/debug/gdbrsp/module.h +++ b/plugins/pychrysalide/debug/gdbrsp/module.h @@ -31,8 +31,11 @@ -/* Ajoute le module 'debug.gdbrsp' au module Python. */ -bool add_debug_gdbrsp_module_to_python_module(PyObject *); +/* Ajoute le module 'debug.gdbresp' à un module Python. */ +bool add_debug_gdbresp_module(PyObject *); + +/* Intègre les objets du module 'debug.gdbresp'. */ +bool populate_debug_gdbresp_module(void); diff --git a/plugins/pychrysalide/debug/module.c b/plugins/pychrysalide/debug/module.c index ea586be..a2df8bf 100644 --- a/plugins/pychrysalide/debug/module.c +++ b/plugins/pychrysalide/debug/module.c @@ -27,27 +27,26 @@ #include "debugger.h" #include "gdbrsp/module.h" -#include "../access.h" +#include "../helpers.h" /****************************************************************************** * * -* Paramètres : module = module dont la définition est à compléter. * +* Paramètres : super = module dont la définition est à compléter. * * * -* Description : Ajoute le module 'debug' au module Python. * +* Description : Ajoute le module 'debug' à un module Python. * * * -* Retour : - * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -bool add_debug_module_to_python_module(PyObject *super) +bool add_debug_module(PyObject *super) { bool result; /* Bilan à retourner */ PyObject *module; /* Sous-module mis en place */ - int ret; /* Bilan d'un appel */ static PyModuleDef py_chrysalide_debug_module = { @@ -60,31 +59,41 @@ bool add_debug_module_to_python_module(PyObject *super) }; - result = false; + module = build_python_module(super, &py_chrysalide_debug_module); - module = PyModule_Create(&py_chrysalide_debug_module); - if (module == NULL) return false; + result = (module != NULL); - ret = PyState_AddModule(super, &py_chrysalide_debug_module); - if (ret != 0) goto loading_failed; + if (result) result = add_debug_gdbresp_module(module); - ret = _PyImport_FixupBuiltin(module, "pychrysalide.debug"); - if (ret != 0) goto loading_failed; + if (!result) + Py_XDECREF(module); - Py_INCREF(module); - ret = PyModule_AddObject(super, "debug", module); - if (ret != 0) goto loading_failed; + return result; - result = true; +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Intègre les objets du module 'debug'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ - result &= register_python_binary_debugger(module); +bool populate_debug_module(void) +{ + bool result; /* Bilan à retourner */ - result &= add_debug_gdbrsp_module_to_python_module(module); + result = true; - if (result) - register_access_to_python_module("pychrysalide.debug", module); + if (result) result = ensure_python_binary_debugger_is_registered(); - loading_failed: + if (result) result = populate_debug_gdbresp_module(); assert(result); diff --git a/plugins/pychrysalide/debug/module.h b/plugins/pychrysalide/debug/module.h index b723ab8..0216652 100644 --- a/plugins/pychrysalide/debug/module.h +++ b/plugins/pychrysalide/debug/module.h @@ -31,8 +31,11 @@ -/* Ajoute le module 'debug' au module Python. */ -bool add_debug_module_to_python_module(PyObject *); +/* Ajoute le module 'debug' à un module Python. */ +bool add_debug_module(PyObject *); + +/* Intègre les objets du module 'debug'. */ +bool populate_debug_module(void); |