summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/analysis
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
parent0150df2a3dafcce46bc95a2cb8642d0bb842ca8d (diff)
Store and load binary contents on demand.
Diffstat (limited to 'plugins/pychrysalide/analysis')
-rw-r--r--plugins/pychrysalide/analysis/contents/encapsulated.c4
-rw-r--r--plugins/pychrysalide/analysis/contents/file.c10
-rw-r--r--plugins/pychrysalide/analysis/contents/memory.c4
-rw-r--r--plugins/pychrysalide/analysis/contents/restricted.c4
-rw-r--r--plugins/pychrysalide/analysis/storage/storage.c115
5 files changed, 104 insertions, 33 deletions
diff --git a/plugins/pychrysalide/analysis/contents/encapsulated.c b/plugins/pychrysalide/analysis/contents/encapsulated.c
index ef26caa..03fce54 100644
--- a/plugins/pychrysalide/analysis/contents/encapsulated.c
+++ b/plugins/pychrysalide/analysis/contents/encapsulated.c
@@ -32,6 +32,7 @@
#include "../content.h"
+#include "../storage/serialize.h"
#include "../../access.h"
#include "../../helpers.h"
@@ -310,6 +311,9 @@ bool ensure_python_encaps_content_is_registered(void)
dict = PyModule_GetDict(module);
+ if (!ensure_python_serializable_object_is_registered())
+ return false;
+
if (!register_class_for_pygobject(dict, G_TYPE_ENCAPS_CONTENT, type, &PyGObject_Type))
return false;
diff --git a/plugins/pychrysalide/analysis/contents/file.c b/plugins/pychrysalide/analysis/contents/file.c
index 93a1ce8..4786cdb 100644
--- a/plugins/pychrysalide/analysis/contents/file.c
+++ b/plugins/pychrysalide/analysis/contents/file.c
@@ -31,6 +31,8 @@
#include <analysis/contents/file.h>
+#include "memory.h"
+#include "../storage/serialize.h"
#include "../../access.h"
#include "../../helpers.h"
@@ -196,7 +198,13 @@ bool ensure_python_file_content_is_registered(void)
dict = PyModule_GetDict(module);
- if (!register_class_for_pygobject(dict, G_TYPE_FILE_CONTENT, type, &PyGObject_Type))
+ if (!ensure_python_memory_content_is_registered())
+ return false;
+
+ if (!ensure_python_serializable_object_is_registered())
+ return false;
+
+ if (!register_class_for_pygobject(dict, G_TYPE_FILE_CONTENT, type, get_python_memory_content_type()))
return false;
}
diff --git a/plugins/pychrysalide/analysis/contents/memory.c b/plugins/pychrysalide/analysis/contents/memory.c
index 8926300..37b098d 100644
--- a/plugins/pychrysalide/analysis/contents/memory.c
+++ b/plugins/pychrysalide/analysis/contents/memory.c
@@ -31,6 +31,7 @@
#include <analysis/contents/memory.h>
+#include "../storage/serialize.h"
#include "../../access.h"
#include "../../helpers.h"
@@ -164,6 +165,9 @@ bool ensure_python_memory_content_is_registered(void)
dict = PyModule_GetDict(module);
+ if (!ensure_python_serializable_object_is_registered())
+ return false;
+
if (!register_class_for_pygobject(dict, G_TYPE_MEMORY_CONTENT, type, &PyGObject_Type))
return false;
diff --git a/plugins/pychrysalide/analysis/contents/restricted.c b/plugins/pychrysalide/analysis/contents/restricted.c
index bbe364a..703f79b 100644
--- a/plugins/pychrysalide/analysis/contents/restricted.c
+++ b/plugins/pychrysalide/analysis/contents/restricted.c
@@ -35,6 +35,7 @@
#include "../content.h"
+#include "../storage/serialize.h"
#include "../../access.h"
#include "../../helpers.h"
#include "../../arch/vmpa.h"
@@ -200,6 +201,9 @@ bool ensure_python_restricted_content_is_registered(void)
dict = PyModule_GetDict(module);
+ if (!ensure_python_serializable_object_is_registered())
+ return false;
+
if (!register_class_for_pygobject(dict, G_TYPE_RESTRICTED_CONTENT, type, &PyGObject_Type))
return false;
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,