diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2019-11-28 22:41:37 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2019-11-28 22:41:37 (GMT) |
commit | 48395d4471d87c20bdbd06bbab1ae3af938ff823 (patch) | |
tree | 00aaaabb7370d6163ed9a2a4f77f9a177f8126f7 /plugins/pychrysalide/analysis/contents/encapsulated.c | |
parent | 472d566943f527e18eb95f31dbe70c50043396aa (diff) |
Improved the API for binary contents a little bit.
Diffstat (limited to 'plugins/pychrysalide/analysis/contents/encapsulated.c')
-rw-r--r-- | plugins/pychrysalide/analysis/contents/encapsulated.c | 159 |
1 files changed, 158 insertions, 1 deletions
diff --git a/plugins/pychrysalide/analysis/contents/encapsulated.c b/plugins/pychrysalide/analysis/contents/encapsulated.c index 031c49f..7a10e5b 100644 --- a/plugins/pychrysalide/analysis/contents/encapsulated.c +++ b/plugins/pychrysalide/analysis/contents/encapsulated.c @@ -40,6 +40,15 @@ /* Crée un nouvel objet Python de type 'BinContent'. */ static PyObject *py_encaps_content_new(PyTypeObject *, PyObject *, PyObject *); +/* Indique la base d'un contenu binaire encapsulé. */ +static PyObject *py_encaps_content_get_base(PyObject *, void *); + +/* Fournit le chemin vers le contenu interne représenté. */ +static PyObject *py_encaps_content_get_path(PyObject *, void *); + +/* Indique le contenu binaire embarqué dans une encapsulation. */ +static PyObject *py_encaps_content_get_endpoint(PyObject *, void *); + /****************************************************************************** @@ -65,6 +74,25 @@ static PyObject *py_encaps_content_new(PyTypeObject *type, PyObject *args, PyObj int ret; /* Bilan de lecture des args. */ GBinContent *content; /* Version GLib du contenu */ +#define ENCAPS_CONTENT_DOC \ + "EncapsulatedContent gathers items relative to a binary encapsulated" \ + " content.\n" \ + "\n" \ + "For instance, if a ZIP archive is processed, the encapsulated content" \ + " stores:\n" \ + "* the archive as a base;\n" \ + "* the access path to the archive member;\n" \ + "* the content of this extracted member.\n" \ + "\n" \ + "Instances can be created using the following constructor:\n" \ + "\n" \ + " EncapsulatedContent(base, path, endpoint)" \ + "\n" \ + "Where base, path and endpoint are the previously described expected" \ + " properties. The base and the endpoint must be" \ + " pychrysalide.analysis.BinContent instances and the access path must" \ + " be provided as a string." + ret = PyArg_ParseTuple(args, "O&sO&", convert_to_binary_content, &base, &path, @@ -85,6 +113,132 @@ static PyObject *py_encaps_content_new(PyTypeObject *type, PyObject *args, PyObj /****************************************************************************** * * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Indique la base d'un contenu binaire encapsulé. * +* * +* Retour : Instance de contenu binaire ou None si aucune. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_encaps_content_get_base(PyObject *self, void *closure) +{ + PyObject *result; /* Valeur à retourner */ + GEncapsContent *content; /* Contenu binaire à consulter */ + GBinContent *target; /* Contenu binaire visé */ + +#define ENCAPS_CONTENT_BASE_ATTRIB PYTHON_GET_DEF_FULL \ +( \ + base, py_encaps_content, \ + "Give access to the base of the encapsulated content." \ +) + + content = G_ENCAPS_CONTENT(pygobject_get(self)); + + target = g_encaps_content_get_base(content); + + if (target == NULL) + { + result = Py_None; + Py_INCREF(result); + } + else + { + result = pygobject_new(G_OBJECT(target)); + g_object_unref(G_OBJECT(target)); + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit le chemin vers le contenu interne représenté. * +* * +* Retour : Chemin d'accès au contenu binaire. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_encaps_content_get_path(PyObject *self, void *closure) +{ + PyObject *result; /* Valeur à retourner */ + GEncapsContent *content; /* Contenu binaire à consulter */ + const char *path; /* Chemin d'accès à transmettre*/ + +#define ENCAPS_CONTENT_PATH_ATTRIB PYTHON_GET_DEF_FULL \ +( \ + path, py_encaps_content, \ + "Provide the access path to the inner binary content." \ +) + + content = G_ENCAPS_CONTENT(pygobject_get(self)); + + path = g_encaps_content_get_path(content); + + result = PyUnicode_FromString(path); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Indique le contenu binaire embarqué dans une encapsulation. * +* * +* Retour : Instance de contenu binaire ou None si aucune. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_encaps_content_get_endpoint(PyObject *self, void *closure) +{ + PyObject *result; /* Valeur à retourner */ + GEncapsContent *content; /* Contenu binaire à consulter */ + GBinContent *target; /* Contenu binaire visé */ + +#define ENCAPS_CONTENT_ENDPOINT_ATTRIB PYTHON_GET_DEF_FULL \ +( \ + endpoint, py_encaps_content, \ + "Give access to the encapsulated binary content." \ +) + + content = G_ENCAPS_CONTENT(pygobject_get(self)); + + target = g_encaps_content_get_base(content); + + if (target == NULL) + { + result = Py_None; + Py_INCREF(result); + } + else + { + result = pygobject_new(G_OBJECT(target)); + g_object_unref(G_OBJECT(target)); + } + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : - * * * * Description : Fournit un accès à une définition de type à diffuser. * @@ -102,6 +256,9 @@ PyTypeObject *get_python_encaps_content_type(void) }; static PyGetSetDef py_encaps_content_getseters[] = { + ENCAPS_CONTENT_BASE_ATTRIB, + ENCAPS_CONTENT_PATH_ATTRIB, + ENCAPS_CONTENT_ENDPOINT_ATTRIB, { NULL } }; @@ -114,7 +271,7 @@ PyTypeObject *get_python_encaps_content_type(void) .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - .tp_doc = "PyChrysalide binary encapsulated content", + .tp_doc = ENCAPS_CONTENT_DOC, .tp_methods = py_encaps_content_methods, .tp_getset = py_encaps_content_getseters, |