summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/analysis/contents
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-08-16 09:16:53 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-08-16 09:16:53 (GMT)
commitfb315963527f6412273829f09513325e446eb6c9 (patch)
tree361f19767812a8f758545e8daa2973fe0b3c9de7 /plugins/pychrysalide/analysis/contents
parent36945bffa2ca648b58c99905ebf9b1b536a9188a (diff)
Reorganized the Python plugin code.
Diffstat (limited to 'plugins/pychrysalide/analysis/contents')
-rw-r--r--plugins/pychrysalide/analysis/contents/encapsulated.c20
-rw-r--r--plugins/pychrysalide/analysis/contents/encapsulated.h2
-rw-r--r--plugins/pychrysalide/analysis/contents/file.c20
-rw-r--r--plugins/pychrysalide/analysis/contents/file.h2
-rw-r--r--plugins/pychrysalide/analysis/contents/memory.c20
-rw-r--r--plugins/pychrysalide/analysis/contents/memory.h2
-rw-r--r--plugins/pychrysalide/analysis/contents/module.c54
-rw-r--r--plugins/pychrysalide/analysis/contents/module.h7
-rw-r--r--plugins/pychrysalide/analysis/contents/restricted.c21
-rw-r--r--plugins/pychrysalide/analysis/contents/restricted.h2
10 files changed, 94 insertions, 56 deletions
diff --git a/plugins/pychrysalide/analysis/contents/encapsulated.c b/plugins/pychrysalide/analysis/contents/encapsulated.c
index a81e45b..0b604c7 100644
--- a/plugins/pychrysalide/analysis/contents/encapsulated.c
+++ b/plugins/pychrysalide/analysis/contents/encapsulated.c
@@ -32,6 +32,7 @@
#include "../content.h"
+#include "../../access.h"
#include "../../helpers.h"
@@ -143,17 +144,24 @@ PyTypeObject *get_python_encaps_content_type(void)
* *
******************************************************************************/
-bool register_python_encaps_content(PyObject *module)
+bool ensure_python_encaps_content_is_registered(void)
{
- PyTypeObject *py_encaps_content_type; /* Type 'EncapsulatedContent' */
+ PyTypeObject *type; /* Type 'EncapsulatedContent' */
+ PyObject *module; /* Module à recompléter */
PyObject *dict; /* Dictionnaire du module */
- py_encaps_content_type = get_python_encaps_content_type();
+ type = get_python_encaps_content_type();
- dict = PyModule_GetDict(module);
+ if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
+ {
+ module = get_access_to_python_module("pychrysalide.analysis.contents");
- if (!register_class_for_pygobject(dict, G_TYPE_ENCAPS_CONTENT, py_encaps_content_type, &PyGObject_Type))
- return false;
+ dict = PyModule_GetDict(module);
+
+ if (!register_class_for_pygobject(dict, G_TYPE_ENCAPS_CONTENT, type, &PyGObject_Type))
+ return false;
+
+ }
return true;
diff --git a/plugins/pychrysalide/analysis/contents/encapsulated.h b/plugins/pychrysalide/analysis/contents/encapsulated.h
index ebd760c..1d46fdc 100644
--- a/plugins/pychrysalide/analysis/contents/encapsulated.h
+++ b/plugins/pychrysalide/analysis/contents/encapsulated.h
@@ -35,7 +35,7 @@
PyTypeObject *get_python_encaps_content_type(void);
/* Prend en charge l'objet 'pychrysalide.analysis.contents.EncapsulatedContent'. */
-bool register_python_encaps_content(PyObject *);
+bool ensure_python_encaps_content_is_registered(void);
diff --git a/plugins/pychrysalide/analysis/contents/file.c b/plugins/pychrysalide/analysis/contents/file.c
index b033611..a44263e 100644
--- a/plugins/pychrysalide/analysis/contents/file.c
+++ b/plugins/pychrysalide/analysis/contents/file.c
@@ -31,6 +31,7 @@
#include <analysis/contents/file.h>
+#include "../../access.h"
#include "../../helpers.h"
@@ -132,17 +133,24 @@ PyTypeObject *get_python_file_content_type(void)
* *
******************************************************************************/
-bool register_python_file_content(PyObject *module)
+bool ensure_python_file_content_is_registered(void)
{
- PyTypeObject *py_file_content_type; /* Type Python 'FileContent' */
+ PyTypeObject *type; /* Type Python 'FileContent' */
+ PyObject *module; /* Module à recompléter */
PyObject *dict; /* Dictionnaire du module */
- py_file_content_type = get_python_file_content_type();
+ type = get_python_file_content_type();
- dict = PyModule_GetDict(module);
+ if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
+ {
+ module = get_access_to_python_module("pychrysalide.analysis.contents");
- if (!register_class_for_pygobject(dict, G_TYPE_FILE_CONTENT, py_file_content_type, &PyGObject_Type))
- return false;
+ dict = PyModule_GetDict(module);
+
+ if (!register_class_for_pygobject(dict, G_TYPE_FILE_CONTENT, type, &PyGObject_Type))
+ return false;
+
+ }
return true;
diff --git a/plugins/pychrysalide/analysis/contents/file.h b/plugins/pychrysalide/analysis/contents/file.h
index 04f4395..110a6da 100644
--- a/plugins/pychrysalide/analysis/contents/file.h
+++ b/plugins/pychrysalide/analysis/contents/file.h
@@ -35,7 +35,7 @@
PyTypeObject *get_python_file_content_type(void);
/* Prend en charge l'objet 'pychrysalide.analysis.contents.FileContent'. */
-bool register_python_file_content(PyObject *);
+bool ensure_python_file_content_is_registered(void);
diff --git a/plugins/pychrysalide/analysis/contents/memory.c b/plugins/pychrysalide/analysis/contents/memory.c
index fadc9bf..ee8b13c 100644
--- a/plugins/pychrysalide/analysis/contents/memory.c
+++ b/plugins/pychrysalide/analysis/contents/memory.c
@@ -31,6 +31,7 @@
#include <analysis/contents/memory.h>
+#include "../../access.h"
#include "../../helpers.h"
@@ -137,17 +138,24 @@ PyTypeObject *get_python_memory_content_type(void)
* *
******************************************************************************/
-bool register_python_memory_content(PyObject *module)
+bool ensure_python_memory_content_is_registered(void)
{
- PyTypeObject *py_memory_content_type; /* Type Python 'MemoryContent' */
+ PyTypeObject *type; /* Type Python 'MemoryContent' */
+ PyObject *module; /* Module à recompléter */
PyObject *dict; /* Dictionnaire du module */
- py_memory_content_type = get_python_memory_content_type();
+ type = get_python_memory_content_type();
- dict = PyModule_GetDict(module);
+ if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
+ {
+ module = get_access_to_python_module("pychrysalide.analysis.contents");
- if (!register_class_for_pygobject(dict, G_TYPE_MEMORY_CONTENT, py_memory_content_type, &PyGObject_Type))
- return false;
+ dict = PyModule_GetDict(module);
+
+ if (!register_class_for_pygobject(dict, G_TYPE_MEMORY_CONTENT, type, &PyGObject_Type))
+ return false;
+
+ }
return true;
diff --git a/plugins/pychrysalide/analysis/contents/memory.h b/plugins/pychrysalide/analysis/contents/memory.h
index f3db9a7..3941e39 100644
--- a/plugins/pychrysalide/analysis/contents/memory.h
+++ b/plugins/pychrysalide/analysis/contents/memory.h
@@ -35,7 +35,7 @@
PyTypeObject *get_python_memory_content_type(void);
/* Prend en charge l'objet 'pychrysalide.analysis.contents.MemoryContent'. */
-bool register_python_memory_content(PyObject *);
+bool ensure_python_memory_content_is_registered(void);
diff --git a/plugins/pychrysalide/analysis/contents/module.c b/plugins/pychrysalide/analysis/contents/module.c
index 53fcdc8..d1650ac 100644
--- a/plugins/pychrysalide/analysis/contents/module.c
+++ b/plugins/pychrysalide/analysis/contents/module.c
@@ -32,29 +32,28 @@
#include "file.h"
#include "memory.h"
#include "restricted.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 'contents' au module Python. *
+* Description : Ajoute le module 'analysis.contents' à un module Python. *
* *
-* Retour : - *
+* Retour : Bilan de l'opération. *
* *
* Remarques : - *
* *
******************************************************************************/
-bool add_analysis_contents_module_to_python_module(PyObject *super)
+bool add_analysis_contents_module(PyObject *super)
{
bool result; /* Bilan à retourner */
PyObject *module; /* Sous-module mis en place */
- int ret; /* Bilan d'un appel */
- static PyModuleDef py_chrysalide_contents_module = {
+ static PyModuleDef py_chrysalide_analysis_contents_module = {
.m_base = PyModuleDef_HEAD_INIT,
@@ -65,32 +64,37 @@ bool add_analysis_contents_module_to_python_module(PyObject *super)
};
- result = false;
+ module = build_python_module(super, &py_chrysalide_analysis_contents_module);
- module = PyModule_Create(&py_chrysalide_contents_module);
- if (module == NULL) return false;
+ result = (module != NULL);
- ret = PyState_AddModule(super, &py_chrysalide_contents_module);
- if (ret != 0) goto loading_failed;
+ return result;
- ret = _PyImport_FixupBuiltin(module, "pychrysalide.analysis.contents");
- if (ret != 0) goto loading_failed;
+}
- Py_INCREF(module);
- ret = PyModule_AddObject(super, "contents", module);
- if (ret != 0) goto loading_failed;
- result = true;
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Intègre les objets du module 'analysis.contents'. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
- result &= register_python_encaps_content(module);
- result &= register_python_file_content(module);
- result &= register_python_memory_content(module);
- result &= register_python_restricted_content(module);
+bool populate_analysis_contents_module(void)
+{
+ bool result; /* Bilan à retourner */
- if (result)
- register_access_to_python_module("pychrysalide.analysis.contents", module);
+ result = true;
- loading_failed:
+ if (result) result = ensure_python_encaps_content_is_registered();
+ if (result) result = ensure_python_file_content_is_registered();
+ if (result) result = ensure_python_memory_content_is_registered();
+ if (result) result = ensure_python_restricted_content_is_registered();
assert(result);
diff --git a/plugins/pychrysalide/analysis/contents/module.h b/plugins/pychrysalide/analysis/contents/module.h
index 5c7418a..441e515 100644
--- a/plugins/pychrysalide/analysis/contents/module.h
+++ b/plugins/pychrysalide/analysis/contents/module.h
@@ -31,8 +31,11 @@
-/* Ajoute le module 'contents' au module Python. */
-bool add_analysis_contents_module_to_python_module(PyObject *);
+/* Ajoute le module 'analysis.contents' à un module Python. */
+bool add_analysis_contents_module(PyObject *);
+
+/* Intègre les objets du module 'analysis.contents'. */
+bool populate_analysis_contents_module(void);
diff --git a/plugins/pychrysalide/analysis/contents/restricted.c b/plugins/pychrysalide/analysis/contents/restricted.c
index f8b0b98..edd6666 100644
--- a/plugins/pychrysalide/analysis/contents/restricted.c
+++ b/plugins/pychrysalide/analysis/contents/restricted.c
@@ -35,6 +35,7 @@
#include "../content.h"
+#include "../../access.h"
#include "../../helpers.h"
#include "../../arch/vmpa.h"
@@ -155,18 +156,24 @@ PyTypeObject *get_python_restricted_content_type(void)
* *
******************************************************************************/
-bool register_python_restricted_content(PyObject *module)
+bool ensure_python_restricted_content_is_registered(void)
{
- PyTypeObject *py_restricted_content_type;/* Type Python 'BinContent' */
+ PyTypeObject *type; /* Type Python 'Restricted...' */
+ PyObject *module; /* Module à recompléter */
PyObject *dict; /* Dictionnaire du module */
- py_restricted_content_type = get_python_restricted_content_type();
+ type = get_python_restricted_content_type();
- dict = PyModule_GetDict(module);
+ if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
+ {
+ module = get_access_to_python_module("pychrysalide.analysis.contents");
+
+ dict = PyModule_GetDict(module);
- if (!register_class_for_pygobject(dict, G_TYPE_RESTRICTED_CONTENT,
- py_restricted_content_type, &PyGObject_Type))
- return false;
+ if (!register_class_for_pygobject(dict, G_TYPE_RESTRICTED_CONTENT, type, &PyGObject_Type))
+ return false;
+
+ }
return true;
diff --git a/plugins/pychrysalide/analysis/contents/restricted.h b/plugins/pychrysalide/analysis/contents/restricted.h
index 5b7b910..35eb3fb 100644
--- a/plugins/pychrysalide/analysis/contents/restricted.h
+++ b/plugins/pychrysalide/analysis/contents/restricted.h
@@ -35,7 +35,7 @@
PyTypeObject *get_python_restricted_content_type(void);
/* Prend en charge l'objet 'pychrysalide.analysis.contents.RestrictedContent'. */
-bool register_python_restricted_content(PyObject *);
+bool ensure_python_restricted_content_is_registered(void);