diff options
Diffstat (limited to 'plugins/pychrysalide/format')
-rw-r--r-- | plugins/pychrysalide/format/executable.c | 23 | ||||
-rw-r--r-- | plugins/pychrysalide/format/executable.h | 2 | ||||
-rw-r--r-- | plugins/pychrysalide/format/flat.c | 24 | ||||
-rw-r--r-- | plugins/pychrysalide/format/flat.h | 2 | ||||
-rw-r--r-- | plugins/pychrysalide/format/format.c | 26 | ||||
-rw-r--r-- | plugins/pychrysalide/format/format.h | 4 | ||||
-rw-r--r-- | plugins/pychrysalide/format/module.c | 54 | ||||
-rw-r--r-- | plugins/pychrysalide/format/module.h | 7 | ||||
-rw-r--r-- | plugins/pychrysalide/format/symbol.c | 28 | ||||
-rw-r--r-- | plugins/pychrysalide/format/symbol.h | 4 | ||||
-rw-r--r-- | plugins/pychrysalide/format/symiter.c | 27 | ||||
-rw-r--r-- | plugins/pychrysalide/format/symiter.h | 2 |
12 files changed, 131 insertions, 72 deletions
diff --git a/plugins/pychrysalide/format/executable.c b/plugins/pychrysalide/format/executable.c index a3bcdd1..8e24699 100644 --- a/plugins/pychrysalide/format/executable.c +++ b/plugins/pychrysalide/format/executable.c @@ -32,6 +32,7 @@ #include "format.h" +#include "../access.h" #include "../helpers.h" #include "../arch/vmpa.h" @@ -198,17 +199,27 @@ PyTypeObject *get_python_executable_format_type(void) * * ******************************************************************************/ -bool register_python_executable_format(PyObject *module) +bool ensure_python_executable_format_is_registered(void) { - PyTypeObject *py_exe_format_type; /* Type Python 'ExeFormat' */ + PyTypeObject *type; /* Type Python 'ExeFormat' */ + PyObject *module; /* Module à recompléter */ PyObject *dict; /* Dictionnaire du module */ - py_exe_format_type = get_python_executable_format_type(); + type = get_python_executable_format_type(); - dict = PyModule_GetDict(module); + if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) + { + module = get_access_to_python_module("pychrysalide.format"); + + dict = PyModule_GetDict(module); + + if (!ensure_python_binary_format_is_registered()) + return false; - if (!register_class_for_pygobject(dict, G_TYPE_EXE_FORMAT, py_exe_format_type, get_python_binary_format_type())) - return false; + if (!register_class_for_pygobject(dict, G_TYPE_EXE_FORMAT, type, get_python_binary_format_type())) + return false; + + } return true; diff --git a/plugins/pychrysalide/format/executable.h b/plugins/pychrysalide/format/executable.h index 2157b93..8a952cd 100644 --- a/plugins/pychrysalide/format/executable.h +++ b/plugins/pychrysalide/format/executable.h @@ -35,7 +35,7 @@ PyTypeObject *get_python_executable_format_type(void); /* Prend en charge l'objet 'pychrysalide.format.ExeFormat'. */ -bool register_python_executable_format(PyObject *); +bool ensure_python_executable_format_is_registered(void); diff --git a/plugins/pychrysalide/format/flat.c b/plugins/pychrysalide/format/flat.c index c85ee37..18ad414 100644 --- a/plugins/pychrysalide/format/flat.c +++ b/plugins/pychrysalide/format/flat.c @@ -32,6 +32,7 @@ #include "executable.h" +#include "../access.h" #include "../helpers.h" #include "../analysis/content.h" @@ -188,18 +189,27 @@ PyTypeObject *get_python_flat_format_type(void) * * ******************************************************************************/ -bool register_python_flat_format(PyObject *module) +bool ensure_python_flat_format_is_registered(void) { - PyTypeObject *py_flat_format_type; /* Type Python 'FlatFormat' */ + PyTypeObject *type; /* Type Python 'FlatFormat' */ + PyObject *module; /* Module à recompléter */ PyObject *dict; /* Dictionnaire du module */ - py_flat_format_type = get_python_flat_format_type(); + type = get_python_flat_format_type(); - dict = PyModule_GetDict(module); + if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) + { + module = get_access_to_python_module("pychrysalide.format"); + + dict = PyModule_GetDict(module); + + if (!ensure_python_executable_format_is_registered()) + return false; - if (!register_class_for_pygobject(dict, G_TYPE_FLAT_FORMAT, py_flat_format_type, \ - get_python_executable_format_type())) - return false; + if (!register_class_for_pygobject(dict, G_TYPE_FLAT_FORMAT, type, get_python_executable_format_type())) + return false; + + } return true; diff --git a/plugins/pychrysalide/format/flat.h b/plugins/pychrysalide/format/flat.h index 92e5f9e..d7447dd 100644 --- a/plugins/pychrysalide/format/flat.h +++ b/plugins/pychrysalide/format/flat.h @@ -35,7 +35,7 @@ PyTypeObject *get_python_flat_format_type(void); /* Prend en charge l'objet 'pychrysalide.format.FlatFormat'. */ -bool register_python_flat_format(PyObject *); +bool ensure_python_flat_format_is_registered(void); diff --git a/plugins/pychrysalide/format/format.c b/plugins/pychrysalide/format/format.c index 561c0c2..bf6c3f1 100644 --- a/plugins/pychrysalide/format/format.c +++ b/plugins/pychrysalide/format/format.c @@ -33,6 +33,7 @@ #include "symbol.h" #include "symiter.h" +#include "../access.h" #include "../helpers.h" #include "../arch/vmpa.h" @@ -732,22 +733,29 @@ PyTypeObject *get_python_binary_format_type(void) * * ******************************************************************************/ -bool register_python_binary_format(PyObject *module) +bool ensure_python_binary_format_is_registered(void) { - PyTypeObject *py_bin_format_type; /* Type Python 'BinFormat' */ + PyTypeObject *type; /* Type Python 'BinFormat' */ + PyObject *module; /* Module à recompléter */ PyObject *dict; /* Dictionnaire du module */ - py_bin_format_type = get_python_binary_format_type(); + type = get_python_binary_format_type(); - APPLY_ABSTRACT_FLAG(py_bin_format_type); + if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) + { + module = get_access_to_python_module("pychrysalide.format"); + + APPLY_ABSTRACT_FLAG(type); - dict = PyModule_GetDict(module); + dict = PyModule_GetDict(module); - if (!register_class_for_pygobject(dict, G_TYPE_BIN_FORMAT, py_bin_format_type, &PyGObject_Type)) - return false; + if (!register_class_for_pygobject(dict, G_TYPE_BIN_FORMAT, type, &PyGObject_Type)) + return false; - if (!define_python_binary_format_constants(py_bin_format_type)) - return false; + if (!define_python_binary_format_constants(type)) + return false; + + } return true; diff --git a/plugins/pychrysalide/format/format.h b/plugins/pychrysalide/format/format.h index a8dfbf0..6423821 100644 --- a/plugins/pychrysalide/format/format.h +++ b/plugins/pychrysalide/format/format.h @@ -38,7 +38,7 @@ PyTypeObject *get_python_binary_symbol_iterator_type(void); /* Prend en charge l'objet 'pychrysalide...BinSymbolIterator'. */ -bool register_python_binary_symbol_iterator(PyObject *); +bool ensure_python_binary_symbol_iterator_is_registered(void); @@ -49,7 +49,7 @@ bool register_python_binary_symbol_iterator(PyObject *); PyTypeObject *get_python_binary_format_type(void); /* Prend en charge l'objet 'pychrysalide.format.BinFormat'. */ -bool register_python_binary_format(PyObject *); +bool ensure_python_binary_format_is_registered(void); diff --git a/plugins/pychrysalide/format/module.c b/plugins/pychrysalide/format/module.c index 9a88dcd..46d8f43 100644 --- a/plugins/pychrysalide/format/module.c +++ b/plugins/pychrysalide/format/module.c @@ -33,27 +33,26 @@ #include "format.h" #include "symbol.h" #include "symiter.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 'format' au module Python. * +* Description : Ajoute le module 'format' à un module Python. * * * -* Retour : - * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -bool add_format_module_to_python_module(PyObject *super) +bool add_format_module(PyObject *super) { bool result; /* Bilan à retourner */ PyObject *module; /* Sous-module mis en place */ - int ret; /* Bilan d'un appel */ static PyModuleDef py_chrysalide_format_module = { @@ -66,33 +65,38 @@ bool add_format_module_to_python_module(PyObject *super) }; - result = false; + module = build_python_module(super, &py_chrysalide_format_module); - module = PyModule_Create(&py_chrysalide_format_module); - if (module == NULL) return false; + result = (module != NULL); - ret = PyState_AddModule(super, &py_chrysalide_format_module); - if (ret != 0) goto loading_failed; + return result; - ret = _PyImport_FixupBuiltin(module, "pychrysalide.format"); - if (ret != 0) goto loading_failed; +} - Py_INCREF(module); - ret = PyModule_AddObject(super, "format", module); - if (ret != 0) goto loading_failed; - result = true; +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Intègre les objets du module 'format'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ - result &= register_python_binary_format(module); - result &= register_python_executable_format(module); - result &= register_python_flat_format(module); - result &= register_python_binary_symbol(module); - result &= register_python_sym_iterator(module); +bool populate_format_module(void) +{ + bool result; /* Bilan à retourner */ - if (result) - register_access_to_python_module("pychrysalide.format", module); + result = true; - loading_failed: + if (result) result = ensure_python_executable_format_is_registered(); + if (result) result = ensure_python_flat_format_is_registered(); + if (result) result = ensure_python_binary_format_is_registered(); + if (result) result = ensure_python_binary_symbol_is_registered(); + if (result) result = ensure_python_sym_iterator_is_registered(); assert(result); diff --git a/plugins/pychrysalide/format/module.h b/plugins/pychrysalide/format/module.h index fb84580..5d305d4 100644 --- a/plugins/pychrysalide/format/module.h +++ b/plugins/pychrysalide/format/module.h @@ -31,8 +31,11 @@ -/* Ajoute le module 'format' au module Python. */ -bool add_format_module_to_python_module(PyObject *); +/* Ajoute le module 'format' à un module Python. */ +bool add_format_module(PyObject *); + +/* Intègre les objets du module 'format'. */ +bool populate_format_module(void); diff --git a/plugins/pychrysalide/format/symbol.c b/plugins/pychrysalide/format/symbol.c index d6298d4..d2d1637 100644 --- a/plugins/pychrysalide/format/symbol.c +++ b/plugins/pychrysalide/format/symbol.c @@ -35,11 +35,13 @@ #include <format/symbol.h> +#include "../access.h" #include "../helpers.h" #include "../analysis/routine.h" #include "../analysis/db/items/comment.h" #include "../arch/instruction.h" #include "../arch/vmpa.h" +#include "../glibext/linegen.h" @@ -435,20 +437,30 @@ PyTypeObject *get_python_binary_symbol_type(void) * * ******************************************************************************/ -bool register_python_binary_symbol(PyObject *module) +bool ensure_python_binary_symbol_is_registered(void) { - PyTypeObject *py_bin_symbol_type; /* Type Python 'BinSymbol' */ + PyTypeObject *type; /* Type Python 'BinSymbol' */ + PyObject *module; /* Module à recompléter */ PyObject *dict; /* Dictionnaire du module */ - py_bin_symbol_type = get_python_binary_symbol_type(); + type = get_python_binary_symbol_type(); - dict = PyModule_GetDict(module); + if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) + { + module = get_access_to_python_module("pychrysalide.format"); + + dict = PyModule_GetDict(module); + + if (!ensure_python_line_generator_is_registered()) + return false; - if (!register_class_for_pygobject(dict, G_TYPE_BIN_SYMBOL, py_bin_symbol_type, &PyGObject_Type)) - return false; + if (!register_class_for_pygobject(dict, G_TYPE_BIN_SYMBOL, type, &PyGObject_Type)) + return false; - if (!py_binary_symbol_define_constants(py_bin_symbol_type)) - return false; + if (!py_binary_symbol_define_constants(type)) + return false; + + } return true; diff --git a/plugins/pychrysalide/format/symbol.h b/plugins/pychrysalide/format/symbol.h index 913da74..a9161c6 100644 --- a/plugins/pychrysalide/format/symbol.h +++ b/plugins/pychrysalide/format/symbol.h @@ -35,8 +35,8 @@ PyTypeObject *get_python_binary_symbol_type(void); /* Prend en charge l'objet 'pychrysalide.format.BinSymbol'. */ -bool register_python_binary_symbol(PyObject *); +bool ensure_python_binary_symbol_is_registered(void); -#endif /* _PLUGINS_PYCHRYSALIDE_FORMAT_EXECUTABLE_H */ +#endif /* _PLUGINS_PYCHRYSALIDE_FORMAT_SYMBOL_H */ diff --git a/plugins/pychrysalide/format/symiter.c b/plugins/pychrysalide/format/symiter.c index db0b744..74a215d 100644 --- a/plugins/pychrysalide/format/symiter.c +++ b/plugins/pychrysalide/format/symiter.c @@ -32,6 +32,7 @@ #include "format.h" +#include "../access.h" @@ -258,19 +259,29 @@ PyTypeObject *get_python_sym_iterator_type(void) * * ******************************************************************************/ -bool register_python_sym_iterator(PyObject *module) +bool ensure_python_sym_iterator_is_registered(void) { - PyTypeObject *py_sym_iterator_type; /* Type Python 'BinContent' */ + PyTypeObject *type; /* Type Python 'SymIterator' */ + PyObject *module; /* Module à recompléter */ int ret; /* Bilan d'un appel */ - py_sym_iterator_type = get_python_sym_iterator_type(); + type = get_python_sym_iterator_type(); - if (PyType_Ready(py_sym_iterator_type) < 0) - return false; + if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) + { + if (PyType_Ready(type) < 0) + return false; + + module = get_access_to_python_module("pychrysalide.format"); + + Py_INCREF(type); + ret = PyModule_AddObject(module, "SymIterator", (PyObject *)type); - Py_INCREF(py_sym_iterator_type); - ret = PyModule_AddObject(module, "SymIterator", (PyObject *)py_sym_iterator_type); + if (ret != 0) + return false; + + } - return (ret == 0); + return true; } diff --git a/plugins/pychrysalide/format/symiter.h b/plugins/pychrysalide/format/symiter.h index 6cc1d29..fc66884 100644 --- a/plugins/pychrysalide/format/symiter.h +++ b/plugins/pychrysalide/format/symiter.h @@ -35,7 +35,7 @@ PyTypeObject *get_python_sym_iterator_type(void); /* Prend en charge l'objet 'pychrysalide.format.SymIterator'. */ -bool register_python_sym_iterator(PyObject *); +bool ensure_python_sym_iterator_is_registered(void); |