diff options
Diffstat (limited to 'plugins/pychrysalide/analysis/binary.c')
-rw-r--r-- | plugins/pychrysalide/analysis/binary.c | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/plugins/pychrysalide/analysis/binary.c b/plugins/pychrysalide/analysis/binary.c index 9d57952..01160a5 100644 --- a/plugins/pychrysalide/analysis/binary.c +++ b/plugins/pychrysalide/analysis/binary.c @@ -25,6 +25,7 @@ #include "binary.h" +#include <malloc.h> #include <pygobject.h> @@ -48,12 +49,18 @@ static PyObject *py_loaded_binary_new(PyTypeObject *, PyObject *, PyObject *); /* Fournit un client assurant la liaison avec un serveur. */ static PyObject *py_loaded_binary_get_client(PyObject *, PyObject *); +/* Trouve une collection assurant une fonctionnalité donnée. */ +static PyObject *py_loaded_binary_find_collection(PyObject *, PyObject *); + /* Demande l'intégration d'une modification dans une collection. */ static PyObject *py_loaded_binary_add_to_collection(PyObject *, PyObject *); /* Fournit le nom associé à l'élément binaire. */ static PyObject *py_loaded_binary_get_name(PyObject *, void *); +/* Fournit l'ensemble des collections utilisées par un binaire. */ +static PyObject *py_loaded_binary_get_collections(PyObject *, void *); + /* Fournit le format de fichier reconnu dans le contenu binaire. */ static PyObject *py_loaded_binary_get_format(PyObject *, void *); @@ -158,6 +165,59 @@ static PyObject *py_loaded_binary_get_client(PyObject *self, PyObject *args) * Paramètres : self = objet représentant un binaire chargé. * * args = arguments fournis pour l'opération. * * * +* Description : Trouve une collection assurant une fonctionnalité donnée. * +* * +* Retour : Collection trouvée ou None. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_loaded_binary_find_collection(PyObject *self, PyObject *args) +{ + PyObject *result; /* Bilan à retourner */ + unsigned int feature; /* Fonctionnalité recherchée */ + int ret; /* Bilan de lecture des args. */ + GLoadedBinary *binary; /* Binaire en cours d'analyse */ + GDbCollection *found; /* Collection trouvée */ + +#define LOADED_BINARY_FIND_COLLECTION_METHOD PYTHON_METHOD_DEF \ +( \ + find_collection, "$self, feature, /", \ + METH_VARARGS, py_loaded_binary, \ + "Provide the collection managing a given database feature." \ + "\n" \ + "The feature is a value of type pychrysalide.analysis.db.DbItem.DbItemFlags." \ +) + + ret = PyArg_ParseTuple(args, "I", &feature); + if (!ret) return NULL; + + binary = G_LOADED_BINARY(pygobject_get(self)); + + found = g_loaded_binary_find_collection(binary, feature); + + if (found != NULL) + { + result = pygobject_new(G_OBJECT(found)); + g_object_unref(G_OBJECT(found)); + } + else + { + result = Py_None; + Py_INCREF(result); + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet représentant un binaire chargé. * +* args = arguments fournis pour l'opération. * +* * * Description : Demande l'intégration d'une modification dans une collection.* * * * Retour : Bilan partiel de l'opération demandée. * @@ -241,6 +301,53 @@ static PyObject *py_loaded_binary_get_name(PyObject *self, void *closure) * Paramètres : self = objet Python concerné par l'appel. * * closure = non utilisé ici. * * * +* Description : Fournit l'ensemble des collections utilisées par un binaire. * +* * +* Retour : Liste de collections en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_loaded_binary_get_collections(PyObject *self, void *closure) +{ + PyObject *result; /* Trouvailles à retourner */ + GLoadedBinary *binary; /* Version native */ + size_t count; /* Quantité de collections */ + GDbCollection **collections; /* Ensemble de collections */ + size_t i; /* Boucle de parcours */ + +#define LOADED_BINARY_COLLECTIONS_ATTRIB PYTHON_GET_DEF_FULL \ +( \ + collections, py_loaded_binary, \ + "List of all collections of database items linked to the binary." \ +) + + binary = G_LOADED_BINARY(pygobject_get(self)); + + collections = g_loaded_binary_get_collections(binary, &count); + + result = PyTuple_New(count); + + for (i = 0; i < count; i++) + { + PyTuple_SetItem(result, i, pygobject_new(G_OBJECT(collections[i]))); + g_object_unref(G_OBJECT(collections[i])); + } + + if (collections != NULL) + free(collections); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * * Description : Fournit le format de fichier reconnu dans le contenu binaire.* * * * Retour : Instance du format reconnu. * @@ -359,6 +466,7 @@ PyTypeObject *get_python_loaded_binary_type(void) { static PyMethodDef py_loaded_binary_methods[] = { LOADED_BINARY_GET_CLIENT_METHOD, + LOADED_BINARY_FIND_COLLECTION_METHOD, LOADED_BINARY_ADD_TO_COLLECTION_METHOD, { NULL } }; @@ -368,6 +476,7 @@ PyTypeObject *get_python_loaded_binary_type(void) "name", py_loaded_binary_get_name, NULL, "Name of the loaded binary.", NULL }, + LOADED_BINARY_COLLECTIONS_ATTRIB, { "format", py_loaded_binary_get_format, NULL, "File format recognized in the binary content.", NULL |