summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/glibext/serialize.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysalide/glibext/serialize.c')
-rw-r--r--plugins/pychrysalide/glibext/serialize.c141
1 files changed, 59 insertions, 82 deletions
diff --git a/plugins/pychrysalide/glibext/serialize.c b/plugins/pychrysalide/glibext/serialize.c
index 40fcef7..61f359f 100644
--- a/plugins/pychrysalide/glibext/serialize.c
+++ b/plugins/pychrysalide/glibext/serialize.c
@@ -1,8 +1,8 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
- * serialize.c - équivalent Python du fichier "analysis/storage/serialize.h"
+ * serialize.c - équivalent Python du fichier "glibext/serialize.h"
*
- * Copyright (C) 2020 Cyrille Bagard
+ * Copyright (C) 2020-2025 Cyrille Bagard
*
* This file is part of Chrysalide.
*
@@ -28,13 +28,12 @@
#include <pygobject.h>
-#include <analysis/storage/serialize-int.h>
+#include <glibext/serialize-int.h>
#include "storage.h"
-#include "../../access.h"
-#include "../../helpers.h"
-#include "../../common/packed.h"
+#include "../access.h"
+#include "../helpers.h"
@@ -42,23 +41,23 @@
/* Procède à l'initialisation de l'interface de génération. */
-static void py_serializable_object_interface_init(GSerializableObjectIface *, gpointer *);
+static void py_serializable_object_interface_init(GSerializableObjectInterface *, gpointer *);
-/* Charge un objet depuis une mémoire tampon. */
-static bool py_serializable_object_load_wrapper(GSerializableObject *, GObjectStorage *, packed_buffer_t *);
+/* Charge un objet depuis un flux de données. */
+static bool py_serializable_object_load_wrapper(GSerializableObject *, GObjectStorage *, int);
-/* Sauvegarde un objet dans une mémoire tampon. */
-static bool py_serializable_object_store_wrapper(const GSerializableObject *, GObjectStorage *, packed_buffer_t *);
+/* Sauvegarde un objet dans un flux de données. */
+static bool py_serializable_object_store_wrapper(const GSerializableObject *, GObjectStorage *, int);
/* ------------------------- CONNEXION AVEC L'API DE PYTHON ------------------------- */
-/* Charge un objet depuis une mémoire tampon. */
+/* Charge un objet depuis un flux de données. */
static bool py_serializable_object_load(PyObject *, PyObject *);
-/* Sauvegarde un objet dans une mémoire tampon. */
+/* Sauvegarde un objet dans un flux de données. */
static bool py_serializable_object_store(PyObject *, PyObject *);
@@ -81,7 +80,7 @@ static bool py_serializable_object_store(PyObject *, PyObject *);
* *
******************************************************************************/
-static void py_serializable_object_interface_init(GSerializableObjectIface *iface, gpointer *unused)
+static void py_serializable_object_interface_init(GSerializableObjectInterface *iface, gpointer *unused)
{
#define SERIALIZABLE_OBJECT_DOC \
@@ -94,8 +93,8 @@ static void py_serializable_object_interface_init(GSerializableObjectIface *ifac
" ...\n" \
"\n" \
"The following methods have to be defined for new implementations:\n" \
- "* pychrysalide.analysis.storage.SerializableObject._load();\n" \
- "* pychrysalide.analysis.storage.SerializableObject._store();\n"
+ "* pychrysalide.glibext.SerializableObject._load();\n" \
+ "* pychrysalide.glibext.SerializableObject._store();\n"
iface->load = py_serializable_object_load_wrapper;
iface->store = py_serializable_object_store_wrapper;
@@ -106,10 +105,10 @@ static void py_serializable_object_interface_init(GSerializableObjectIface *ifac
/******************************************************************************
* *
* Paramètres : object = instruction d'assemblage à consulter. *
-* storage = conservateur de données à manipuler ou NULL. *
-* pbuf = zone tampon à remplir. *
+* storage = conservateur de données à manipuler. *
+* fd = flux ouvert en lecture. *
* *
-* Description : Charge un objet depuis une mémoire tampon. *
+* Description : Charge un objet depuis un flux de données. *
* *
* Retour : Bilan de l'opération. *
* *
@@ -117,25 +116,24 @@ static void py_serializable_object_interface_init(GSerializableObjectIface *ifac
* *
******************************************************************************/
-static bool py_serializable_object_load_wrapper(GSerializableObject *object, GObjectStorage *storage, packed_buffer_t *pbuf)
+static bool py_serializable_object_load_wrapper(GSerializableObject *object, GObjectStorage *storage, int fd)
{
bool result; /* Bilan à retourner */
PyGILState_STATE gstate; /* Sauvegarde d'environnement */
- PyObject *storage_obj; /* Objet Python à emmployer */
PyObject *args; /* Arguments pour l'appel */
PyObject *pyobj; /* Objet Python concerné */
PyObject *pyret; /* Bilan de consultation */
#define SERIALIZABLE_OBJECT_LOAD_WRAPPER PYTHON_WRAPPER_DEF \
( \
- _load, "$self, storage, pbuf, /", \
+ _load, "$self, storage, fd, /", \
METH_VARARGS, \
- "Abstract method used to load an object definition from buffered data.\n" \
+ "Abstract method used to load an object definition from a data stream.\n" \
"\n" \
- "The *storage* is a pychrysalide.analysis.storage.ObjectStorage instance" \
- " provided to store inner objects, if relevant, or None. The *pbuf*" \
- " argument points to a pychrysalide.common.PackedBuffer object containing" \
- " the data to process.\n" \
+ "The *storage* is a pychrysalide.glibext.ObjectStorage instance" \
+ " provided to store inner objects. The *fd* argument is an integer value" \
+ " provided as a file descriptor which as to be kept open after" \
+ " processing.\n" \
"\n" \
"The result is a boolean indicating the status of the operation." \
)
@@ -148,17 +146,9 @@ static bool py_serializable_object_load_wrapper(GSerializableObject *object, GOb
if (has_python_method(pyobj, "_load"))
{
- if (storage == NULL)
- {
- storage_obj = Py_None;
- Py_INCREF(storage_obj);
- }
- else
- storage_obj = pygobject_new(G_OBJECT(storage));
-
args = PyTuple_New(2);
- PyTuple_SetItem(args, 0, storage_obj);
- PyTuple_SetItem(args, 1, build_from_internal_packed_buffer(pbuf));
+ PyTuple_SetItem(args, 0, pygobject_new(G_OBJECT(storage)));
+ PyTuple_SetItem(args, 1, PyLong_FromLong(fd));
pyret = run_python_method(pyobj, "_load", args);
@@ -182,10 +172,10 @@ static bool py_serializable_object_load_wrapper(GSerializableObject *object, GOb
/******************************************************************************
* *
* Paramètres : object = instruction d'assemblage à consulter. *
-* storage = conservateur de données à manipuler ou NULL. *
-* pbuf = zone tampon à remplir. *
+* storage = conservateur de données à manipuler. *
+* fd = flux ouvert en écriture. *
* *
-* Description : Sauvegarde un objet dans une mémoire tampon. *
+* Description : Sauvegarde un objet dans un flux de données. *
* *
* Retour : Bilan de l'opération. *
* *
@@ -193,25 +183,24 @@ static bool py_serializable_object_load_wrapper(GSerializableObject *object, GOb
* *
******************************************************************************/
-static bool py_serializable_object_store_wrapper(const GSerializableObject *object, GObjectStorage *storage, packed_buffer_t *pbuf)
+static bool py_serializable_object_store_wrapper(const GSerializableObject *object, GObjectStorage *storage, int fd)
{
bool result; /* Bilan à retourner */
PyGILState_STATE gstate; /* Sauvegarde d'environnement */
- PyObject *storage_obj; /* Objet Python à emmployer */
PyObject *args; /* Arguments pour l'appel */
PyObject *pyobj; /* Objet Python concerné */
PyObject *pyret; /* Bilan de consultation */
#define SERIALIZABLE_OBJECT_STORE_WRAPPER PYTHON_WRAPPER_DEF \
( \
- _store, "$self, storage, pbuf, /", \
+ _store, "$self, storage, fd, /", \
METH_VARARGS, \
- "Abstract method used to store an object definition into buffered data.\n" \
+ "Abstract method used to store an object definition into a data stream.\n" \
"\n" \
- "The *storage* is a pychrysalide.analysis.storage.ObjectStorage instance" \
- " provided to store inner objects, if relevant, or None. The *pbuf*" \
- " argument points to a pychrysalide.common.PackedBuffer object containing" \
- " the data to process.\n" \
+ "The *storage* is a pychrysalide.glibext.ObjectStorage instance" \
+ " provided to store inner objects. The *fd* argument is an integer value" \
+ " provided as a file descriptor which as to be kept open after" \
+ " processing.\n" \
"\n" \
"The result is a boolean indicating the status of the operation." \
)
@@ -224,17 +213,9 @@ static bool py_serializable_object_store_wrapper(const GSerializableObject *obje
if (has_python_method(pyobj, "_store"))
{
- if (storage == NULL)
- {
- storage_obj = Py_None;
- Py_INCREF(storage_obj);
- }
- else
- storage_obj = pygobject_new(G_OBJECT(storage));
-
args = PyTuple_New(2);
- PyTuple_SetItem(args, 0, storage_obj);
- PyTuple_SetItem(args, 1, build_from_internal_packed_buffer(pbuf));
+ PyTuple_SetItem(args, 0, pygobject_new(G_OBJECT(storage)));
+ PyTuple_SetItem(args, 1, PyLong_FromLong(fd));
pyret = run_python_method(pyobj, "_store", args);
@@ -266,7 +247,7 @@ static bool py_serializable_object_store_wrapper(const GSerializableObject *obje
* Paramètres : self = classe représentant un générateur à manipuler. *
* args = arguments fournis à l'appel. *
* *
-* Description : Charge un objet depuis une mémoire tampon. *
+* Description : Charge un objet depuis un flux de données. *
* *
* Retour : Bilan de l'opération. *
* *
@@ -278,32 +259,30 @@ static bool py_serializable_object_load(PyObject *self, PyObject *args)
{
PyObject *result; /* Bilan à retourner */
GObjectStorage *storage; /* Conservateur à manipuler */
- packed_buffer_t *pbuf; /* Tampon de données à employer*/
+ int fd; /* Flux ouvert (en lecture) */
int ret; /* Bilan de lecture des args. */
GSerializableObject *object; /* Version native */
bool status; /* Bilan de l'opération */
#define SERIALIZABLE_OBJECT_LOAD_METHOD PYTHON_METHOD_DEF \
( \
- load, "$self, storage, pbuf, /", \
+ load, "$self, storage, fd, /", \
METH_VARARGS, py_serializable_object, \
- "Load an object definition from buffered data.\n" \
+ "Load an object definition from a data stream.\n" \
"\n" \
- "The *storage* is a pychrysalide.analysis.storage.ObjectStorage instance" \
- " provided to store inner objects, if relevant, or None. The *pbuf*" \
- " argument points to a pychrysalide.common.PackedBuffer object containing" \
- " the data to process.\n" \
+ "The *storage* is a pychrysalide.glibext.ObjectStorage instance" \
+ " provided to store inner objects. The *fd* argument is an integer value" \
+ " used as a file descriptor for writing data\n" \
"\n" \
"The result is a boolean indicating the status of the operation." \
)
- ret = PyArg_ParseTuple(args, "O&O&", convert_to_object_storage_or_none, &storage,
- convert_to_packed_buffer, &pbuf);
+ ret = PyArg_ParseTuple(args, "O&i", convert_to_object_storage, &storage, &fd);
if (!ret) return NULL;
object = G_SERIALIZABLE_OBJECT(pygobject_get(self));
- status = g_serializable_object_load(object, storage, pbuf);
+ status = g_serializable_object_load(object, storage, fd);
result = status ? Py_True : Py_False;
Py_INCREF(result);
@@ -318,7 +297,7 @@ static bool py_serializable_object_load(PyObject *self, PyObject *args)
* Paramètres : self = classe représentant un générateur à manipuler. *
* args = arguments fournis à l'appel. *
* *
-* Description : Sauvegarde un objet dans une mémoire tampon. *
+* Description : Sauvegarde un objet dans un flux de données. *
* *
* Retour : Bilan de l'opération. *
* *
@@ -330,32 +309,30 @@ static bool py_serializable_object_store(PyObject *self, PyObject *args)
{
PyObject *result; /* Bilan à retourner */
GObjectStorage *storage; /* Conservateur à manipuler */
- packed_buffer_t *pbuf; /* Tampon de données à employer*/
+ int fd; /* Flux ouvert (en lecture) */
int ret; /* Bilan de lecture des args. */
GSerializableObject *object; /* Version native */
bool status; /* Bilan de l'opération */
#define SERIALIZABLE_OBJECT_STORE_METHOD PYTHON_METHOD_DEF \
( \
- store, "$self, storage, pbuf, /", \
+ store, "$self, storage, fd, /", \
METH_VARARGS, py_serializable_object, \
- "Store an object definition into buffered data.\n" \
+ "Store an object definition into a data stream.\n" \
"\n" \
- "The *storage* is a pychrysalide.analysis.storage.ObjectStorage instance" \
- " provided to store inner objects, if relevant, or None. The *pbuf*" \
- " argument points to a pychrysalide.common.PackedBuffer object containing" \
- " the data to process.\n" \
+ "The *storage* is a pychrysalide.glibext.ObjectStorage instance" \
+ " provided to store inner objects. The *fd* argument is an integer value" \
+ " used as a file descriptor for writing data\n" \
"\n" \
"The result is a boolean indicating the status of the operation." \
)
- ret = PyArg_ParseTuple(args, "O&O&", convert_to_object_storage_or_none, &storage,
- convert_to_packed_buffer, &pbuf);
+ ret = PyArg_ParseTuple(args, "O&i", convert_to_object_storage, &storage, &fd);
if (!ret) return NULL;
object = G_SERIALIZABLE_OBJECT(pygobject_get(self));
- status = g_serializable_object_store(object, storage, pbuf);
+ status = g_serializable_object_store(object, storage, fd);
result = status ? Py_True : Py_False;
Py_INCREF(result);
@@ -395,7 +372,7 @@ PyTypeObject *get_python_serializable_object_type(void)
PyVarObject_HEAD_INIT(NULL, 0)
- .tp_name = "pychrysalide.analysis.storage.SerializableObject",
+ .tp_name = "pychrysalide.glibext.SerializableObject",
.tp_basicsize = sizeof(PyObject),
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
@@ -442,7 +419,7 @@ bool ensure_python_serializable_object_is_registered(void)
if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
{
- module = get_access_to_python_module("pychrysalide.analysis.storage");
+ module = get_access_to_python_module("pychrysalide.glibext");
dict = PyModule_GetDict(module);