diff options
Diffstat (limited to 'plugins/pychrysa/analysis/binaries/file.c')
-rw-r--r-- | plugins/pychrysa/analysis/binaries/file.c | 116 |
1 files changed, 82 insertions, 34 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; } |