summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/analysis/storage
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2021-07-04 17:06:28 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2021-07-04 17:06:28 (GMT)
commit5958d9b25f806df73cd0634de2c9475eb6497e8c (patch)
tree7594605f9722cf5329c965cd35e11d52f2dfc4c8 /plugins/pychrysalide/analysis/storage
parent0150df2a3dafcce46bc95a2cb8642d0bb842ca8d (diff)
Store and load binary contents on demand.
Diffstat (limited to 'plugins/pychrysalide/analysis/storage')
-rw-r--r--plugins/pychrysalide/analysis/storage/storage.c115
1 files changed, 83 insertions, 32 deletions
diff --git a/plugins/pychrysalide/analysis/storage/storage.c b/plugins/pychrysalide/analysis/storage/storage.c
index 107980e..7c03be0 100644
--- a/plugins/pychrysalide/analysis/storage/storage.c
+++ b/plugins/pychrysalide/analysis/storage/storage.c
@@ -33,7 +33,6 @@
#include "serialize.h"
-#include "../loaded.h"
#include "../../access.h"
#include "../../helpers.h"
#include "../../common/packed.h"
@@ -54,8 +53,11 @@ static int py_object_storage_init(PyObject *, PyObject *, PyObject *);
/* -------------------------- TAMPON POUR CODE DESASSEMBLE -------------------------- */
-/* Ajoute le support d'un nouveau groupe d'objets construits. */
-static PyObject *py_object_storage_add_backend(PyObject *, PyObject *);
+/* Charge le support d'une conservation d'objets en place. */
+static PyObject *py_object_storage_load(PyObject *, PyObject *);
+
+/* Sauvegarde le support d'une conservation d'objets en place. */
+static PyObject *py_object_storage_store(PyObject *, PyObject *);
/* Charge un objet à partir de données rassemblées. */
static PyObject *py_object_storage_load_object(PyObject *, PyObject *);
@@ -152,7 +154,7 @@ static PyObject *py_object_storage_new(PyTypeObject *type, PyObject *args, PyObj
static int py_object_storage_init(PyObject *self, PyObject *args, PyObject *kwds)
{
- GLoadedContent *loaded; /* Contenu chargé et traité */
+ const char *hash; /* Empreinte de contenu */
int ret; /* Bilan de lecture des args. */
GObjectStorage *storage; /* Mécanismes natifs */
@@ -162,14 +164,14 @@ static int py_object_storage_init(PyObject *self, PyObject *args, PyObject *kwds
"\n" \
"Instances can be created using the following constructor:\n" \
"\n" \
- " ObjectStorage(loaded)" \
+ " ObjectStorage(hash)" \
"\n" \
- "Where *loaded* is a pychrysalide.analysis.LoadedContent instance" \
- " linked to the objects which can apply for a storage process."
+ "Where *hash* should a string built from the checksum of the" \
+ " relative binary content linked to the storage.pychrysalide."
/* Récupération des paramètres */
- ret = PyArg_ParseTuple(args, "O&", convert_to_loaded_content, &loaded);
+ ret = PyArg_ParseTuple(args, "s", &hash);
if (!ret) return -1;
/* Initialisation d'un objet GLib */
@@ -181,8 +183,7 @@ static int py_object_storage_init(PyObject *self, PyObject *args, PyObject *kwds
storage = G_OBJECT_STORAGE(pygobject_get(self));
- storage->loaded = loaded;
- g_object_ref(G_OBJECT(loaded));
+ storage->hash = strdup(hash);
return 0;
@@ -200,7 +201,61 @@ static int py_object_storage_init(PyObject *self, PyObject *args, PyObject *kwds
* Paramètres : self = classe représentant une mémorisation de types. *
* args = arguments fournis à l'appel. *
* *
-* Description : Ajoute le support d'un nouveau groupe d'objets construits. *
+* Description : Charge le support d'une conservation d'objets en place. *
+* *
+* Retour : Gestionnaire de conservations construit ou None si erreur. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_object_storage_load(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Emplacement à retourner */
+ packed_buffer_t *pbuf; /* Tampon de données à employer*/
+ 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." \
+)
+
+ ret = PyArg_ParseTuple(args, "O&", convert_to_packed_buffer, &pbuf);
+ if (!ret) return NULL;
+
+ storage = g_object_storage_load(pbuf);
+
+ if (storage == NULL)
+ {
+ result = Py_None;
+ Py_INCREF(result);
+ }
+ else
+ {
+ result = pygobject_new(G_OBJECT(storage));
+ g_object_unref(G_OBJECT(storage));
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = classe représentant une mémorisation de types. *
+* args = arguments fournis à l'appel. *
+* *
+* Description : Sauvegarde le support d'une conservation d'objets en place. *
* *
* Retour : Bilan de l'opération. *
* *
@@ -208,37 +263,32 @@ static int py_object_storage_init(PyObject *self, PyObject *args, PyObject *kwds
* *
******************************************************************************/
-static PyObject *py_object_storage_add_backend(PyObject *self, PyObject *args)
+static PyObject *py_object_storage_store(PyObject *self, PyObject *args)
{
- PyObject *result; /* Bilan à retourner */
- const char *name; /* Désignation de groupe */
- const char *filename; /* Nom de fichier à associer */
+ PyObject *result; /* Emplacement à retourner */
+ 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_ADD_BACKEND_METHOD PYTHON_METHOD_DEF \
-( \
- add_backend, "$self, name, /, filename", \
- METH_VARARGS, py_object_storage, \
- "Add storage support for a new kind of GLib objects.\n" \
- "\n" \
- "The *name* is a string label for the group of target objects" \
- " and the optional *filename* points to a file used to load" \
- " objects.\n" \
- "\n" \
- "The result is a boolean value indicating the status of" \
- " the operation: True for success, False for failure." \
+#define OBJECT_STORAGE_STORE_METHOD PYTHON_METHOD_DEF \
+( \
+ store, "$self, pbuf, /", \
+ METH_VARARGS, py_object_storage, \
+ "Save a storage into a buffer.\n" \
+ "\n" \
+ "The *pbuf* has to be an instance of type" \
+ " pychrysalide.common.PackedBuffer.\n" \
+ "\n" \
+ "The result is *True* on success, *False* otherwise." \
)
- filename = NULL;
-
- ret = PyArg_ParseTuple(args, "s|s", &name, &filename);
+ ret = PyArg_ParseTuple(args, "O&", convert_to_packed_buffer, &pbuf);
if (!ret) return NULL;
storage = G_OBJECT_STORAGE(pygobject_get(self));
- status = g_object_storage_add_backend(storage, name, filename);
+ status = g_object_storage_store(storage, pbuf);
result = status ? Py_True : Py_False;
Py_INCREF(result);
@@ -488,7 +538,8 @@ static PyObject *py_object_storage_pack_object(PyObject *self, PyObject *args)
PyTypeObject *get_python_object_storage_type(void)
{
static PyMethodDef py_object_storage_methods[] = {
- OBJECT_STORAGE_ADD_BACKEND_METHOD,
+ OBJECT_STORAGE_LOAD_METHOD,
+ OBJECT_STORAGE_STORE_METHOD,
OBJECT_STORAGE_LOAD_OBJECT_METHOD,
OBJECT_STORAGE_UNPACK_OBJECT_METHOD,
OBJECT_STORAGE_STORE_OBJECT_METHOD,