summaryrefslogtreecommitdiff
path: root/plugins/pychrysa/analysis/binaries
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysa/analysis/binaries')
-rw-r--r--plugins/pychrysa/analysis/binaries/file.c116
-rw-r--r--plugins/pychrysa/analysis/binaries/file.h7
-rw-r--r--plugins/pychrysa/analysis/binaries/module.c43
-rw-r--r--plugins/pychrysa/analysis/binaries/module.h2
4 files changed, 122 insertions, 46 deletions
diff --git a/plugins/pychrysa/analysis/binaries/file.c b/plugins/pychrysa/analysis/binaries/file.c
index 2b2a460..28bfecb 100644
--- a/plugins/pychrysa/analysis/binaries/file.c
+++ b/plugins/pychrysa/analysis/binaries/file.c
@@ -25,20 +25,21 @@
#include "file.h"
-
#include <pygobject.h>
#include <analysis/binaries/file.h>
+#include "../binary.h"
-/* Crée un nouvel objet Python de type 'FileBinary'. */
-static PyObject *py_file_binary_new(PyTypeObject *, PyObject *, PyObject *);
-
+/* Crée un nouvel objet Python de type 'BinaryFile'. */
+static PyObject *py_binary_file_new(PyTypeObject *, PyObject *, PyObject *);
+/* Fournit le chemin d'accès au binaire représenté. */
+static PyObject *py_binary_file_get_filename(PyObject *, void *);
@@ -48,7 +49,7 @@ static PyObject *py_file_binary_new(PyTypeObject *, PyObject *, PyObject *);
* args = arguments fournis à l'appel. *
* kwds = arguments de type key=val fournis. *
* *
-* Description : Crée un nouvel objet Python de type 'FileBinary'. *
+* Description : Crée un nouvel objet Python de type 'BinaryFile'. *
* *
* Retour : Instance Python mise en place. *
* *
@@ -56,7 +57,7 @@ static PyObject *py_file_binary_new(PyTypeObject *, PyObject *, PyObject *);
* *
******************************************************************************/
-static PyObject *py_file_binary_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+static PyObject *py_binary_file_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *result; /* Instance à retourner */
char *filename; /* Nom du fichier à charger */
@@ -69,74 +70,121 @@ static PyObject *py_file_binary_new(PyTypeObject *type, PyObject *args, PyObject
binary = g_file_binary_new_from_file(filename);
result = pygobject_new(G_OBJECT(binary));
- //g_object_unref(binary);
+ g_object_unref(binary);
return result;
}
+/******************************************************************************
+* *
+* Paramètres : self = NULL car méthode statique. *
+* closure = non utilisé ici. *
+* *
+* Description : Fournit le chemin d'accès au binaire représenté. *
+* *
+* Retour : Chemin d'accès en Python. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+static PyObject *py_binary_file_get_filename(PyObject *self, void *closure)
+{
+ const GFileBinary *file; /* Fichier binaire concerné */
+ const char *filename; /* Chemin d'accès à diffuser */
+
+ file = G_FILE_BINARY(pygobject_get(self));
+ filename = g_file_binary_get_filename(file, true);
+ return PyUnicode_FromString(filename);
+
+}
/******************************************************************************
* *
-* Paramètres : module = module dont la définition est à compléter. *
+* Paramètres : - *
* *
-* Description : Prend en charge l'objet 'pychrysalide.analysis.LoadedBinary'.*
+* 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_file_binary(PyObject *module)
+PyTypeObject *get_python_binary_file_type(void)
{
- PyObject *parent_mod; /* Module Python-LoadedBinary */
- int ret; /* Bilan d'un appel */
-
- static PyMethodDef py_file_binary_methods[] = {
+ static PyMethodDef py_binary_file_methods[] = {
{ NULL }
};
- static PyGetSetDef py_file_binary_getseters[] = {
+ static PyGetSetDef py_binary_file_getseters[] = {
+ {
+ "filename", py_binary_file_get_filename, NULL,
+ "Show the filename of the loaded binary file.", NULL
+ },
{ NULL }
};
- static PyTypeObject py_file_binary_type = {
+ static PyTypeObject py_binary_file_type = {
- PyObject_HEAD_INIT(NULL)
+ PyVarObject_HEAD_INIT(NULL, 0)
- .tp_name = "pychrysalide.analysis.binaries.FileBinary",
+ .tp_name = "pychrysalide.analysis.binaries.BinaryFile",
.tp_basicsize = sizeof(PyGObject),
- .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+ .tp_flags = Py_TPFLAGS_DEFAULT,
- .tp_doc = "PyChrysalide file binary",
+ .tp_doc = "PyChrysalide binary file",
- .tp_methods = py_file_binary_methods,
- .tp_getset = py_file_binary_getseters,
- .tp_new = (newfunc)py_file_binary_new
+ .tp_methods = py_binary_file_methods,
+ .tp_getset = py_binary_file_getseters,
+ .tp_new = (newfunc)py_binary_file_new
};
- parent_mod = PyImport_ImportModule("pychrysalide.analysis");
- if (parent_mod == NULL) return false;
+ return &py_binary_file_type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide.analysis.LoadedBinary'.*
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool register_python_binary_file(PyObject *module)
+{
+ PyTypeObject *py_binary_file_type; /* Type Python 'LoadedBinary' */
+ int ret; /* Bilan d'un appel */
+ PyObject *dict; /* Dictionnaire du module */
+
+ py_binary_file_type = get_python_binary_file_type();
- py_file_binary_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(parent_mod, "LoadedBinary");
- Py_DECREF(parent_mod);
+ py_binary_file_type->tp_base = get_python_loaded_binary_type();
+ py_binary_file_type->tp_basicsize = py_binary_file_type->tp_base->tp_basicsize;
- if (PyType_Ready(&py_file_binary_type) < 0)
+ if (PyType_Ready(py_binary_file_type) < 0)
return false;
- Py_INCREF(&py_file_binary_type);
- ret = PyModule_AddObject(module, "FileBinary", (PyObject *)&py_file_binary_type);
+ Py_INCREF(py_binary_file_type);
+ ret = PyModule_AddObject(module, "BinaryFile", (PyObject *)py_binary_file_type);
+ if (ret != 0) return false;
- pygobject_register_class(module, "GFileBinary", G_TYPE_FILE_BINARY, &py_file_binary_type,
- Py_BuildValue("(O)", py_file_binary_type.tp_base));
+ dict = PyModule_GetDict(module);
+ pygobject_register_class(dict, "BinaryFile", G_TYPE_FILE_BINARY, py_binary_file_type,
+ Py_BuildValue("(O)", py_binary_file_type->tp_base));
- return (ret == 0);
+ return true;
}
diff --git a/plugins/pychrysa/analysis/binaries/file.h b/plugins/pychrysa/analysis/binaries/file.h
index 2ba9ed0..b381379 100644
--- a/plugins/pychrysa/analysis/binaries/file.h
+++ b/plugins/pychrysa/analysis/binaries/file.h
@@ -31,8 +31,11 @@
-/* Prend en charge l'objet 'pychrysalide.analysis.binaries.FileBinary'. */
-bool register_python_file_binary(PyObject *);
+/* Fournit un accès à une définition de type à diffuser. */
+PyTypeObject *get_python_binary_file_type(void);
+
+/* Prend en charge l'objet 'pychrysalide.analysis.binaries.BinaryFile'. */
+bool register_python_binary_file(PyObject *);
diff --git a/plugins/pychrysa/analysis/binaries/module.c b/plugins/pychrysa/analysis/binaries/module.c
index aae0a33..c2adddf 100644
--- a/plugins/pychrysa/analysis/binaries/module.c
+++ b/plugins/pychrysa/analysis/binaries/module.c
@@ -41,25 +41,50 @@
* *
******************************************************************************/
-bool add_binaries_module_to_python_module(PyObject *super)
+bool add_analysis_binaries_module_to_python_module(PyObject *super)
{
- bool result;
- PyObject *module;
+ bool result; /* Bilan à retourner */
+ PyObject *module; /* Sous-module mis en place */
int ret; /* Bilan d'un appel */
- static PyMethodDef py_format_methods[] = {
- { NULL }
+ static PyModuleDef py_chrysalide_arch_module = {
+
+ .m_base = PyModuleDef_HEAD_INIT,
+
+ .m_name = "pychrysalide.analysis.binaries",
+ .m_doc = "Python module for Chrysalide.analysis.binaries",
+
+ .m_size = -1,
+
};
- module = Py_InitModule("pychrysalide.analysis.binaries", py_format_methods);
+ result = false;
+
+ module = PyModule_Create(&py_chrysalide_arch_module);
if (module == NULL) return false;
+ ret = PyState_AddModule(super, &py_chrysalide_arch_module);
+ if (ret != 0) goto aabmtpm_exit;
+
+ ret = _PyImport_FixupBuiltin(module, "pychrysalide.analysis.binaries");
+ if (ret != 0) goto aabmtpm_exit;
+
Py_INCREF(module);
- ret = PyModule_AddObject(super, "pychrysalide.analysis.binaries", module);
+ ret = PyModule_AddObject(super, "binaries", module);
+ if (ret != 0) goto aabmtpm_exit;
+
+ result = true;
+
+ result &= register_python_binary_file(module);
+
+ aabmtpm_exit:
- result = (ret == 0);
+ if (!result)
+ {
+ printf("something went wrong in %s...\n", __FUNCTION__);
+ /* ... */
- result &= register_python_file_binary(module);
+ }
return result;
diff --git a/plugins/pychrysa/analysis/binaries/module.h b/plugins/pychrysa/analysis/binaries/module.h
index 1fd62d0..653f7da 100644
--- a/plugins/pychrysa/analysis/binaries/module.h
+++ b/plugins/pychrysa/analysis/binaries/module.h
@@ -32,7 +32,7 @@
/* Ajoute le module 'binaries' au module Python. */
-bool add_binaries_module_to_python_module(PyObject *);
+bool add_analysis_binaries_module_to_python_module(PyObject *);