summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/glibext
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2025-03-13 00:19:58 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2025-03-13 00:19:58 (GMT)
commit733d0cdb8677fe09310125bcaeb058a1a9c56b4d (patch)
tree17b8d9a151068dac695d25e39e875933ff9aaa40 /plugins/pychrysalide/glibext
parent8287d20061887e9fd33e038e8f9bf86cf13f2780 (diff)
Rebuild a generic storage for GObjects using a ZIP format.
Diffstat (limited to 'plugins/pychrysalide/glibext')
-rw-r--r--plugins/pychrysalide/glibext/Makefile.am2
-rw-r--r--plugins/pychrysalide/glibext/module.c4
-rw-r--r--plugins/pychrysalide/glibext/serialize.c141
-rw-r--r--plugins/pychrysalide/glibext/serialize.h12
-rw-r--r--plugins/pychrysalide/glibext/storage.c225
-rw-r--r--plugins/pychrysalide/glibext/storage.h12
6 files changed, 131 insertions, 265 deletions
diff --git a/plugins/pychrysalide/glibext/Makefile.am b/plugins/pychrysalide/glibext/Makefile.am
index af1d9f2..3a5fab2 100644
--- a/plugins/pychrysalide/glibext/Makefile.am
+++ b/plugins/pychrysalide/glibext/Makefile.am
@@ -27,7 +27,9 @@ libpychrysaglibext_la_SOURCES = \
objhole.h objhole.c \
portion.h portion.c \
secstorage.h secstorage.c \
+ serialize.h serialize.c \
singleton.h singleton.c \
+ storage.h storage.c \
strbuilder.h strbuilder.c \
work.h work.c \
workqueue.h workqueue.c
diff --git a/plugins/pychrysalide/glibext/module.c b/plugins/pychrysalide/glibext/module.c
index 6ce0709..bbe357d 100644
--- a/plugins/pychrysalide/glibext/module.c
+++ b/plugins/pychrysalide/glibext/module.c
@@ -44,7 +44,9 @@
#include "objhole.h"
#include "portion.h"
#include "secstorage.h"
+#include "serialize.h"
#include "singleton.h"
+#include "storage.h"
#include "strbuilder.h"
#include "work.h"
#include "workqueue.h"
@@ -116,12 +118,14 @@ bool populate_glibext_module(void)
if (result) result = ensure_python_comparable_object_is_registered();
if (result) result = ensure_python_hashable_object_is_registered();
+ if (result) result = ensure_python_serializable_object_is_registered();
if (result) result = ensure_python_singleton_candidate_is_registered();
if (result) result = ensure_python_string_builder_is_registered();
if (result) result = ensure_python_thick_object_is_registered();
if (result) result = ensure_python_binary_portion_is_registered();
if (result) result = ensure_python_generic_work_is_registered();
+ if (result) result = ensure_python_object_storage_is_registered();
if (result) result = ensure_python_secret_storage_is_registered();
if (result) result = ensure_python_singleton_factory_is_registered();
if (result) result = ensure_python_work_queue_is_registered();
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);
diff --git a/plugins/pychrysalide/glibext/serialize.h b/plugins/pychrysalide/glibext/serialize.h
index 7e831e5..90688ba 100644
--- a/plugins/pychrysalide/glibext/serialize.h
+++ b/plugins/pychrysalide/glibext/serialize.h
@@ -1,8 +1,8 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
- * serialize.h - prototypes pour l'équivalent Python du fichier "analysis/storage/serialize.h"
+ * serialize.h - prototypes pour l'équivalent Python du fichier "glibext/serialize.h"
*
- * Copyright (C) 2020 Cyrille Bagard
+ * Copyright (C) 2020-2025 Cyrille Bagard
*
* This file is part of Chrysalide.
*
@@ -22,8 +22,8 @@
*/
-#ifndef _PLUGINS_PYCHRYSALIDE_ANALYSIS_STORAGE_SERIALIZE_H
-#define _PLUGINS_PYCHRYSALIDE_ANALYSIS_STORAGE_SERIALIZE_H
+#ifndef _PLUGINS_PYCHRYSALIDE_GLIBEXT_SERIALIZE_H
+#define _PLUGINS_PYCHRYSALIDE_GLIBEXT_SERIALIZE_H
#include <Python.h>
@@ -34,7 +34,7 @@
/* Fournit un accès à une définition de type à diffuser. */
PyTypeObject *get_python_serializable_object_type(void);
-/* Prend en charge l'objet 'pychrysalide.analysis.storage.SerializableObject'. */
+/* Prend en charge l'objet 'pychrysalide.glibext.SerializableObject'. */
bool ensure_python_serializable_object_is_registered(void);
/* Tente de convertir en objet adapté à une mise en cache. */
@@ -42,4 +42,4 @@ int convert_to_serializable_object(PyObject *, void *);
-#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_STORAGE_SERIALIZE_H */
+#endif /* _PLUGINS_PYCHRYSALIDE_GLIBEXT_SERIALIZE_H */
diff --git a/plugins/pychrysalide/glibext/storage.c b/plugins/pychrysalide/glibext/storage.c
index c54fe0f..4764700 100644
--- a/plugins/pychrysalide/glibext/storage.c
+++ b/plugins/pychrysalide/glibext/storage.c
@@ -1,8 +1,8 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
- * storage.c - équivalent Python du fichier "analysis/storage/storage.c"
+ * storage.c - équivalent Python du fichier "glibext/storage.c"
*
- * Copyright (C) 2020 Cyrille Bagard
+ * Copyright (C) 2020-2025 Cyrille Bagard
*
* This file is part of Chrysalide.
*
@@ -25,25 +25,23 @@
#include "storage.h"
+#include <assert.h>
#include <pygobject.h>
-#include <analysis/storage/storage-int.h>
-#include <plugins/dt.h>
+#include <glibext/storage-int.h>
#include "serialize.h"
-#include "../../access.h"
-#include "../../helpers.h"
-#include "../../common/packed.h"
+#include "../access.h"
+#include "../helpers.h"
/* ------------------------ GLUE POUR CREATION DEPUIS PYTHON ------------------------ */
-/* Accompagne la création d'une instance dérivée en Python. */
-static PyObject *py_object_storage_new(PyTypeObject *, PyObject *, PyObject *);
+CREATE_DYN_CONSTRUCTOR(object_storage, G_TYPE_OBJECT_STORAGE);
/* Initialise une instance sur la base du dérivé de GObject. */
static int py_object_storage_init(PyObject *, PyObject *, PyObject *);
@@ -68,9 +66,6 @@ static PyObject *py_object_storage_unpack_object(PyObject *, PyObject *);
/* Sauvegarde un object sous forme de données rassemblées. */
static PyObject *py_object_storage_store_object(PyObject *, PyObject *);
-/* Sauvegarde un object interne sous forme de données. */
-static PyObject *py_object_storage_pack_object(PyObject *, PyObject *);
-
/* ---------------------------------------------------------------------------------- */
@@ -80,66 +75,6 @@ static PyObject *py_object_storage_pack_object(PyObject *, PyObject *);
/******************************************************************************
* *
-* Paramètres : type = type du nouvel objet à mettre en place. *
-* args = éventuelle liste d'arguments. *
-* kwds = éventuel dictionnaire de valeurs mises à disposition. *
-* *
-* Description : Accompagne la création d'une instance dérivée en Python. *
-* *
-* Retour : Nouvel objet Python mis en place ou NULL en cas d'échec. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static PyObject *py_object_storage_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- PyObject *result; /* Objet à retourner */
- PyTypeObject *base; /* Type de base à dériver */
- bool first_time; /* Evite les multiples passages*/
- GType gtype; /* Nouveau type de processeur */
- bool status; /* Bilan d'un enregistrement */
-
- /* Validations diverses */
-
- base = get_python_object_storage_type();
-
- if (type == base)
- goto simple_way;
-
- /* Mise en place d'un type dédié */
-
- first_time = (g_type_from_name(type->tp_name) == 0);
-
- gtype = build_dynamic_type(G_TYPE_OBJECT_STORAGE, type->tp_name, NULL, NULL, NULL);
-
- if (first_time)
- {
- status = register_class_for_dynamic_pygobject(gtype, type);
-
- if (!status)
- {
- result = NULL;
- goto exit;
- }
-
- }
-
- /* On crée, et on laisse ensuite la main à PyGObject_Type.tp_init() */
-
- simple_way:
-
- result = PyType_GenericNew(type, args, kwds);
-
- exit:
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
* Paramètres : self = objet à initialiser (théoriquement). *
* args = arguments fournis à l'appel. *
* kwds = arguments de type key=val fournis. *
@@ -154,7 +89,9 @@ static PyObject *py_object_storage_new(PyTypeObject *type, PyObject *args, PyObj
static int py_object_storage_init(PyObject *self, PyObject *args, PyObject *kwds)
{
- const char *hash; /* Empreinte de contenu */
+ const char *type; /* Type global de conservation */
+ unsigned char version; /* Version de ce type */
+ const char *uid; /* Identifiant de distinction */
int ret; /* Bilan de lecture des args. */
GObjectStorage *storage; /* Mécanismes natifs */
@@ -164,14 +101,15 @@ static int py_object_storage_init(PyObject *self, PyObject *args, PyObject *kwds
"\n" \
"Instances can be created using the following constructor:\n" \
"\n" \
- " ObjectStorage(hash)" \
+ " ObjectStorage(type, version uid)" \
"\n" \
- "Where *hash* should a string built from the checksum of the" \
- " relative binary content linked to the storage.pychrysalide."
+ "Where *type* is a short string describing the storage kind," \
+ " *version* provides a version control for this type and *uid* is" \
+ " an arbitrary unique identifier used for creating temporary files."
/* Récupération des paramètres */
- ret = PyArg_ParseTuple(args, "s", &hash);
+ ret = PyArg_ParseTuple(args, "sbs", &type, &version, &uid);
if (!ret) return -1;
/* Initialisation d'un objet GLib */
@@ -183,7 +121,8 @@ static int py_object_storage_init(PyObject *self, PyObject *args, PyObject *kwds
storage = G_OBJECT_STORAGE(pygobject_get(self));
- storage->hash = strdup(hash);
+ if (!g_object_storage_create(storage, type, version, uid))
+ return -1;
return 0;
@@ -212,27 +151,27 @@ static int py_object_storage_init(PyObject *self, PyObject *args, PyObject *kwds
static PyObject *py_object_storage_load(PyObject *self, PyObject *args)
{
PyObject *result; /* Emplacement à retourner */
- packed_buffer_t *pbuf; /* Tampon de données à employer*/
+ const char *filename; /* Fichier de source à traiter */
int ret; /* Bilan de lecture des args. */
GObjectStorage *storage; /* Mécanismes natifs */
-#define OBJECT_STORAGE_LOAD_METHOD PYTHON_METHOD_DEF \
-( \
- load, "pbuf, /", \
- METH_STATIC | METH_VARARGS, py_object_storage, \
- "Construct a new storage from a buffer.\n" \
- "\n" \
- "The *pbuf* has to be an instance of type" \
- " pychrysalide.common.PackedBuffer.\n" \
- "\n" \
- "The result is a new pychrysalide.analysis.storage.ObjectStorage" \
- " object on success, *None* otherwise." \
+#define OBJECT_STORAGE_LOAD_METHOD PYTHON_METHOD_DEF \
+( \
+ load, "filename, /", \
+ METH_STATIC | METH_VARARGS, py_object_storage, \
+ "Construct a new storage from a filename.\n" \
+ "\n" \
+ "The *filename* argument points to the source file to" \
+ " read.\n" \
+ "\n" \
+ "The result is a new pychrysalide.glibext.ObjectStorage" \
+ " object on success, *None* otherwise." \
)
- ret = PyArg_ParseTuple(args, "O&", convert_to_packed_buffer, &pbuf);
+ ret = PyArg_ParseTuple(args, "s", &filename);
if (!ret) return NULL;
- storage = g_object_storage_load(pbuf);
+ storage = g_object_storage_load(filename);
if (storage == NULL)
{
@@ -242,7 +181,7 @@ static PyObject *py_object_storage_load(PyObject *self, PyObject *args)
else
{
result = pygobject_new(G_OBJECT(storage));
- g_object_unref(G_OBJECT(storage));
+ unref_object(storage);
}
return result;
@@ -266,29 +205,29 @@ static PyObject *py_object_storage_load(PyObject *self, PyObject *args)
static PyObject *py_object_storage_store(PyObject *self, PyObject *args)
{
PyObject *result; /* Emplacement à retourner */
- packed_buffer_t *pbuf; /* Tampon de données à employer*/
+ const char *filename; /* Fichier de destination */
int ret; /* Bilan de lecture des args. */
GObjectStorage *storage; /* Mécanismes natifs */
bool status; /* Bilan de l'opération */
#define OBJECT_STORAGE_STORE_METHOD PYTHON_METHOD_DEF \
( \
- store, "$self, pbuf, /", \
+ store, "$self, filename, /", \
METH_VARARGS, py_object_storage, \
- "Save a storage into a buffer.\n" \
+ "Save a storage into a file.\n" \
"\n" \
- "The *pbuf* has to be an instance of type" \
- " pychrysalide.common.PackedBuffer.\n" \
+ "The *filename* argument points to the destination" \
+ " file to write.\n" \
"\n" \
"The result is *True* on success, *False* otherwise." \
)
- ret = PyArg_ParseTuple(args, "O&", convert_to_packed_buffer, &pbuf);
+ ret = PyArg_ParseTuple(args, "s", &filename);
if (!ret) return NULL;
storage = G_OBJECT_STORAGE(pygobject_get(self));
- status = g_object_storage_store(storage, pbuf);
+ status = g_object_storage_store(storage, filename);
result = status ? Py_True : Py_False;
Py_INCREF(result);
@@ -331,7 +270,7 @@ static PyObject *py_object_storage_load_object(PyObject *self, PyObject *args)
" the data to unserialize.\n" \
"\n" \
"The result is a pychrysalide.analysis.storage.SerializableObject" \
- " instancet in case of success, or None in case of failure." \
+ " instancet in case of success, or *None* in case of failure." \
)
ret = PyArg_ParseTuple(args, "sK", &name, &pos);
@@ -370,31 +309,32 @@ static PyObject *py_object_storage_load_object(PyObject *self, PyObject *args)
static PyObject *py_object_storage_unpack_object(PyObject *self, PyObject *args)
{
PyObject *result; /* Bilan à retourner */
- const char *name; /* Désignation de groupe */
- packed_buffer_t *pbuf; /* Tampon de données à employer*/
+ const char *name; /* Désignation de groupe #0 */
+ const char *target_name; /* Désignation de groupe #1 */
int ret; /* Bilan de lecture des args. */
GObjectStorage *storage; /* Mécanismes natifs */
GSerializableObject *object; /* Objet reconstruit ou NULL */
#define OBJECT_STORAGE_UNPACK_OBJECT_METHOD PYTHON_METHOD_DEF \
( \
- unpack_object, "$self, name, pbuf, /", \
+ unpack_object, "$self, name, target_name, /", \
METH_VARARGS, py_object_storage, \
- "Load an object from a buffer with a location pointing to data.\n" \
+ "Load an object from a reference to serialized data.\n" \
"\n" \
- "The *name* is a string label for the group of target objects and" \
- " *pbuf* has to be a pychrysalide.common.PackedBuffer instance.\n" \
+ "The *name* is a string label for the group containing a position" \
+ " pointing to a target object to load. The *target_name* is a" \
+ " string label for the group of this target object.\n" \
"\n" \
"The result is a pychrysalide.analysis.storage.SerializableObject" \
- " instancet in case of success, or None in case of failure." \
+ " instancet in case of success, or *None* in case of failure." \
)
- ret = PyArg_ParseTuple(args, "sO&", &name, convert_to_packed_buffer, &pbuf);
+ ret = PyArg_ParseTuple(args, "sO&", &name, &target_name);
if (!ret) return NULL;
storage = G_OBJECT_STORAGE(pygobject_get(self));
- object = g_object_storage_unpack_object(storage, name, pbuf);
+ object = g_object_storage_unpack_object(storage, name, target_name);
if (object != NULL)
result = pygobject_new(G_OBJECT(object));
@@ -443,7 +383,7 @@ static PyObject *py_object_storage_store_object(PyObject *self, PyObject *args)
" pychrysalide.analysis.storage.SerializableObject instance.\n" \
"\n" \
"The result is the position of the data for stored object," \
- " provided as an integer offset, in case of success or None" \
+ " provided as an integer offset, in case of success or *None*" \
" in case of failure." \
)
@@ -469,62 +409,6 @@ static PyObject *py_object_storage_store_object(PyObject *self, PyObject *args)
/******************************************************************************
* *
-* Paramètres : self = classe représentant une mémorisation de types. *
-* args = arguments fournis à l'appel. *
-* *
-* Description : Sauvegarde un object interne sous forme de données. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static PyObject *py_object_storage_pack_object(PyObject *self, PyObject *args)
-{
- PyObject *result; /* Emplacement à retourner */
- const char *name; /* Désignation de groupe */
- GSerializableObject *object; /* Objet à traiter */
- packed_buffer_t *pbuf; /* Tampon de données à employer*/
- int ret; /* Bilan de lecture des args. */
- GObjectStorage *storage; /* Mécanismes natifs */
- bool status; /* Bilan de l'opération */
-
-#define OBJECT_STORAGE_PACK_OBJECT_METHOD PYTHON_METHOD_DEF \
-( \
- pack_object, "$self, name, object, pbuf/", \
- METH_VARARGS, py_object_storage, \
- "Save an object as serialized data and store the location of" \
- " the data intro a buffer.\n" \
- "\n" \
- "The *name* is a string label for the group of target objects," \
- " the processed *object* has to be a" \
- " pychrysalide.analysis.storage.SerializableObject instance" \
- " and *pbuf* is expected to be a" \
- " pychrysalide.common.PackedBuffer instance.\n" \
- "\n" \
- "The status of the operation is returned as a boolean value:" \
- " *True* for success, *False* for failure." \
-)
-
- ret = PyArg_ParseTuple(args, "sO&O&", &name, convert_to_serializable_object, &object,
- convert_to_packed_buffer, &pbuf);
- if (!ret) return NULL;
-
- storage = G_OBJECT_STORAGE(pygobject_get(self));
-
- status = g_object_storage_pack_object(storage, name, object, pbuf);
-
- result = status ? Py_True : Py_False;
- Py_INCREF(result);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
* Paramètres : - *
* *
* Description : Fournit un accès à une définition de type à diffuser. *
@@ -543,7 +427,6 @@ PyTypeObject *get_python_object_storage_type(void)
OBJECT_STORAGE_LOAD_OBJECT_METHOD,
OBJECT_STORAGE_UNPACK_OBJECT_METHOD,
OBJECT_STORAGE_STORE_OBJECT_METHOD,
- OBJECT_STORAGE_PACK_OBJECT_METHOD,
{ NULL }
};
@@ -555,7 +438,7 @@ PyTypeObject *get_python_object_storage_type(void)
PyVarObject_HEAD_INIT(NULL, 0)
- .tp_name = "pychrysalide.analysis.storage.ObjectStorage",
+ .tp_name = "pychrysalide.glibext.ObjectStorage",
.tp_basicsize = sizeof(PyGObject),
.tp_flags = Py_TPFLAGS_DEFAULT,
@@ -579,7 +462,7 @@ PyTypeObject *get_python_object_storage_type(void)
* *
* Paramètres : module = module dont la définition est à compléter. *
* *
-* Description : Prend en charge l'objet 'pychrysalide....ObjectStorage'. *
+* Description : Prend en charge l'objet 'pychrysalide.glibext.ObjectStorage'.*
* *
* Retour : Bilan de l'opération. *
* *
@@ -597,7 +480,7 @@ bool ensure_python_object_storage_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);
diff --git a/plugins/pychrysalide/glibext/storage.h b/plugins/pychrysalide/glibext/storage.h
index a0a2c18..681f99a 100644
--- a/plugins/pychrysalide/glibext/storage.h
+++ b/plugins/pychrysalide/glibext/storage.h
@@ -1,8 +1,8 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
- * storage.h - prototypes pour l'équivalent Python du fichier "analysis/storage/storage.h"
+ * storage.h - prototypes pour l'équivalent Python du fichier "glibext/storage.h"
*
- * Copyright (C) 2020 Cyrille Bagard
+ * Copyright (C) 2020-2025 Cyrille Bagard
*
* This file is part of Chrysalide.
*
@@ -22,8 +22,8 @@
*/
-#ifndef _PLUGINS_PYCHRYSALIDE_ANALYSIS_STORAGE_STORAGE_H
-#define _PLUGINS_PYCHRYSALIDE_ANALYSIS_STORAGE_STORAGE_H
+#ifndef _PLUGINS_PYCHRYSALIDE_GLIBEXT_STORAGE_H
+#define _PLUGINS_PYCHRYSALIDE_GLIBEXT_STORAGE_H
#include <Python.h>
@@ -34,7 +34,7 @@
/* Fournit un accès à une définition de type à diffuser. */
PyTypeObject *get_python_object_storage_type(void);
-/* Prend en charge l'objet 'pychrysalide.analysis.storage.ObjectStorage'. */
+/* Prend en charge l'objet 'pychrysalide.glibext.ObjectStorage'. */
bool ensure_python_object_storage_is_registered(void);
/* Tente de convertir en conservateur d'objets. */
@@ -45,4 +45,4 @@ int convert_to_object_storage_or_none(PyObject *, void *);
-#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_STORAGE_STORAGE_H */
+#endif /* _PLUGINS_PYCHRYSALIDE_GLIBEXT_STORAGE_H */