diff options
Diffstat (limited to 'plugins/pychrysalide/analysis/storage')
-rw-r--r-- | plugins/pychrysalide/analysis/storage/Makefile.am | 13 | ||||
-rw-r--r-- | plugins/pychrysalide/analysis/storage/cache.c | 4 | ||||
-rw-r--r-- | plugins/pychrysalide/analysis/storage/storage.c | 119 | ||||
-rw-r--r-- | plugins/pychrysalide/analysis/storage/tpmem.c | 56 |
4 files changed, 117 insertions, 75 deletions
diff --git a/plugins/pychrysalide/analysis/storage/Makefile.am b/plugins/pychrysalide/analysis/storage/Makefile.am index 01240cb..d0a4df4 100644 --- a/plugins/pychrysalide/analysis/storage/Makefile.am +++ b/plugins/pychrysalide/analysis/storage/Makefile.am @@ -9,19 +9,10 @@ libpychrysaanalysisstorage_la_SOURCES = \ storage.h storage.c \ tpmem.h tpmem.c -libpychrysaanalysisstorage_la_LIBADD = - -libpychrysaanalysisstorage_la_LDFLAGS = +libpychrysaanalysisstorage_la_CFLAGS = $(TOOLKIT_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_INTERPRETER_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ + -I$(top_srcdir)/src -DNO_IMPORT_PYGOBJECT devdir = $(includedir)/chrysalide/$(subdir) dev_HEADERS = $(libpychrysaanalysisstorage_la_SOURCES:%c=) - - -AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ - -I$(top_srcdir)/src - -AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) - -SUBDIRS = diff --git a/plugins/pychrysalide/analysis/storage/cache.c b/plugins/pychrysalide/analysis/storage/cache.c index 9859623..8cd5bac 100644 --- a/plugins/pychrysalide/analysis/storage/cache.c +++ b/plugins/pychrysalide/analysis/storage/cache.c @@ -100,7 +100,7 @@ static PyObject *py_object_cache_new(PyTypeObject *type, PyObject *args, PyObjec if (first_time) { - status = register_class_for_dynamic_pygobject(gtype, type, base); + status = register_class_for_dynamic_pygobject(gtype, type); if (!status) { @@ -304,7 +304,7 @@ bool ensure_python_object_cache_is_registered(void) dict = PyModule_GetDict(module); - if (!register_class_for_pygobject(dict, G_TYPE_OBJECT_CACHE, type, &PyGObject_Type)) + if (!register_class_for_pygobject(dict, G_TYPE_OBJECT_CACHE, type)) return false; } diff --git a/plugins/pychrysalide/analysis/storage/storage.c b/plugins/pychrysalide/analysis/storage/storage.c index 107980e..c54fe0f 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 *); @@ -113,7 +115,7 @@ static PyObject *py_object_storage_new(PyTypeObject *type, PyObject *args, PyObj if (first_time) { - status = register_class_for_dynamic_pygobject(gtype, type, base); + status = register_class_for_dynamic_pygobject(gtype, type); if (!status) { @@ -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, @@ -550,7 +601,7 @@ bool ensure_python_object_storage_is_registered(void) dict = PyModule_GetDict(module); - if (!register_class_for_pygobject(dict, G_TYPE_OBJECT_STORAGE, type, &PyGObject_Type)) + if (!register_class_for_pygobject(dict, G_TYPE_OBJECT_STORAGE, type)) return false; } diff --git a/plugins/pychrysalide/analysis/storage/tpmem.c b/plugins/pychrysalide/analysis/storage/tpmem.c index 8df20b2..ae07008 100644 --- a/plugins/pychrysalide/analysis/storage/tpmem.c +++ b/plugins/pychrysalide/analysis/storage/tpmem.c @@ -52,8 +52,8 @@ static int py_type_memory_init(PyObject *, PyObject *, PyObject *); /* -------------------------- TAMPON POUR CODE DESASSEMBLE -------------------------- */ -/* Apprend tous les types mémorisés dans un flux. */ -static PyObject *py_type_memory_read_types(PyObject *, PyObject *); +/* Apprend tous les types mémorisés dans un tampon. */ +static PyObject *py_type_memory_load_types(PyObject *, PyObject *); /* Crée une nouvelle instance d'objet à partir de son type. */ static PyObject *py_type_memory_create_object(PyObject *, PyObject *); @@ -61,8 +61,8 @@ static PyObject *py_type_memory_create_object(PyObject *, PyObject *); /* Sauvegarde le type d'un objet instancié. */ static PyObject *py_type_memory_store_object_gtype(PyObject *, PyObject *); -/* Enregistre tous les types mémorisés dans un flux. */ -static PyObject *py_type_memory_write_types(PyObject *, PyObject *); +/* Enregistre tous les types mémorisés dans un tampon. */ +static PyObject *py_type_memory_store_types(PyObject *, PyObject *); @@ -108,7 +108,7 @@ static PyObject *py_type_memory_new(PyTypeObject *type, PyObject *args, PyObject if (first_time) { - status = register_class_for_dynamic_pygobject(gtype, type, base); + status = register_class_for_dynamic_pygobject(gtype, type); if (!status) { @@ -178,7 +178,7 @@ static int py_type_memory_init(PyObject *self, PyObject *args, PyObject *kwds) * Paramètres : self = classe représentant une mémorisation de types. * * args = arguments fournis à l'appel. * * * -* Description : Apprend tous les types mémorisés dans un flux. * +* Description : Apprend tous les types mémorisés dans un tampon. * * * * Retour : Bilan de l'opération. * * * @@ -186,36 +186,36 @@ static int py_type_memory_init(PyObject *self, PyObject *args, PyObject *kwds) * * ******************************************************************************/ -static PyObject *py_type_memory_read_types(PyObject *self, PyObject *args) +static PyObject *py_type_memory_load_types(PyObject *self, PyObject *args) { PyObject *result; /* Bilan à retourner */ - int fd; /* Flux ouvert en lecture */ + packed_buffer_t *pbuf; /* Tampon à consulter */ int ret; /* Bilan de lecture des args. */ GTypeMemory *tpmem; /* Mémorisation native */ bool status; /* Bilan de l'opération */ -#define TYPE_MEMORY_READ_TYPES_METHOD PYTHON_METHOD_DEF \ +#define TYPE_MEMORY_LOAD_TYPES_METHOD PYTHON_METHOD_DEF \ ( \ - read_types, "$self, fd", \ + load_types, "$self, pbuf", \ METH_VARARGS, py_type_memory, \ - "Read types from a stream.\n" \ + "Read types from a buffer.\n" \ "\n" \ "This operation is usually handled internally by the" \ " Chrysalide's core.\n" \ "\n" \ - "The *fd* parameter is an integer representing a valid" \ - " identifier for a file descriptor opened for reading." \ + "The *pbuf* parameter is a pychrysalide.common.PackedBuffer"\ + " instance providing buffered data to read." \ "\n" \ "The result is a boolean value indicating the status of" \ " the operation: True for success, False for failure." \ ) - ret = PyArg_ParseTuple(args, "i", &fd); + ret = PyArg_ParseTuple(args, "O&", convert_to_packed_buffer, &pbuf); if (!ret) return NULL; tpmem = G_TYPE_MEMORY(pygobject_get(self)); - status = g_type_memory_read_types(tpmem, fd); + status = g_type_memory_load_types(tpmem, pbuf); result = status ? Py_True : Py_False; Py_INCREF(result); @@ -330,7 +330,7 @@ static PyObject *py_type_memory_store_object_gtype(PyObject *self, PyObject *arg * Paramètres : self = classe représentant une mémorisation de types. * * args = arguments fournis à l'appel. * * * -* Description : Enregistre tous les types mémorisés dans un flux. * +* Description : Enregistre tous les types mémorisés dans un tampon. * * * * Retour : Bilan de l'opération. * * * @@ -338,36 +338,36 @@ static PyObject *py_type_memory_store_object_gtype(PyObject *self, PyObject *arg * * ******************************************************************************/ -static PyObject *py_type_memory_write_types(PyObject *self, PyObject *args) +static PyObject *py_type_memory_store_types(PyObject *self, PyObject *args) { PyObject *result; /* Bilan à retourner */ - int fd; /* Flux ouvert en lecture */ + packed_buffer_t *pbuf; /* Tampon à consulter */ int ret; /* Bilan de lecture des args. */ GTypeMemory *tpmem; /* Mémorisation native */ bool status; /* Bilan de l'opération */ -#define TYPE_MEMORY_WRITE_TYPES_METHOD PYTHON_METHOD_DEF \ +#define TYPE_MEMORY_STORE_TYPES_METHOD PYTHON_METHOD_DEF \ ( \ - write_types, "$self, fd", \ + store_types, "$self, pbuf", \ METH_VARARGS, py_type_memory, \ - "Write types into a stream.\n" \ + "Write types into a buffer.\n" \ "\n" \ "This operation is usually handled internally by the" \ " Chrysalide's core.\n" \ "\n" \ - "The *fd* parameter is an integer representing a valid" \ - " identifier for a file descriptor opened for writing." \ + "The *pbuf* parameter is a pychrysalide.common.PackedBuffer"\ + " instance providing buffered data to read." \ "\n" \ "The result is a boolean value indicating the status of" \ " the operation: True for success, False for failure." \ ) - ret = PyArg_ParseTuple(args, "i", &fd); + ret = PyArg_ParseTuple(args, "O&", convert_to_packed_buffer, &pbuf); if (!ret) return NULL; tpmem = G_TYPE_MEMORY(pygobject_get(self)); - status = g_type_memory_write_types(tpmem, fd); + status = g_type_memory_store_types(tpmem, pbuf); result = status ? Py_True : Py_False; Py_INCREF(result); @@ -392,10 +392,10 @@ static PyObject *py_type_memory_write_types(PyObject *self, PyObject *args) PyTypeObject *get_python_type_memory_type(void) { static PyMethodDef py_type_memory_methods[] = { - TYPE_MEMORY_READ_TYPES_METHOD, + TYPE_MEMORY_LOAD_TYPES_METHOD, TYPE_MEMORY_CREATE_OBJECT_METHOD, TYPE_MEMORY_STORE_OBJECT_GTYPE_METHOD, - TYPE_MEMORY_WRITE_TYPES_METHOD, + TYPE_MEMORY_STORE_TYPES_METHOD, { NULL } }; @@ -453,7 +453,7 @@ bool ensure_python_type_memory_is_registered(void) dict = PyModule_GetDict(module); - if (!register_class_for_pygobject(dict, G_TYPE_TYPE_MEMORY, type, &PyGObject_Type)) + if (!register_class_for_pygobject(dict, G_TYPE_TYPE_MEMORY, type)) return false; } |