summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/analysis/db/analyst.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysalide/analysis/db/analyst.c')
-rw-r--r--plugins/pychrysalide/analysis/db/analyst.c75
1 files changed, 48 insertions, 27 deletions
diff --git a/plugins/pychrysalide/analysis/db/analyst.c b/plugins/pychrysalide/analysis/db/analyst.c
index bb9af30..f2860ed 100644
--- a/plugins/pychrysalide/analysis/db/analyst.c
+++ b/plugins/pychrysalide/analysis/db/analyst.c
@@ -30,21 +30,23 @@
#include <i18n.h>
-#include <analysis/db/analyst.h>
+#include <analysis/db/analyst-int.h>
#include <core/collections.h>
#include "client.h"
#include "collection.h"
+#include "constants.h"
#include "../content.h"
+#include "../loaded.h"
#include "../../access.h"
#include "../../helpers.h"
#include "../../struct.h"
-/* Crée un nouvel objet Python de type 'AnalystClient'. */
-static PyObject *py_analyst_client_new(PyTypeObject *, PyObject *, PyObject *);
+/* Initialise une instance sur la base du dérivé de GObject. */
+static int py_analyst_client_init(PyObject *, PyObject *, PyObject *);
/* Envoie un contenu binaire pour conservation côté serveur. */
static PyObject *py_analyst_client_send_content(PyObject *, PyObject *);
@@ -78,24 +80,29 @@ static PyObject *py_analyst_client_get_current_snapshot(PyObject *, void *);
+CREATE_DYN_CONSTRUCTOR(analyst_client, G_TYPE_ANALYST_CLIENT);
+
+
/******************************************************************************
* *
-* Paramètres : type = type de l'objet à instancier. *
+* Paramètres : self = objet à initialiser (théoriquement). *
* args = arguments fournis à l'appel. *
* kwds = arguments de type key=val fournis. *
* *
-* Description : Crée un nouvel objet Python de type 'AnalystClient'. *
+* Description : Initialise une instance sur la base du dérivé de GObject. *
* *
-* Retour : Instance Python mise en place. *
+* Retour : 0. *
* *
* Remarques : - *
* *
******************************************************************************/
-static PyObject *py_analyst_client_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+static int py_analyst_client_init(PyObject *self, PyObject *args, PyObject *kwds)
{
- PyObject *result; /* Instance à retourner */
+ int result; /* Bilan à retourner */
+ GLoadedContent *loaded; /* Contenu local déjà chargé */
const char *hash; /* Empreinte du binaire visé */
+ const char *class; /* Nature du contenu analysé */
PyObject *list; /* Liste Python de collections */
int ret; /* Bilan de lecture des args. */
Py_ssize_t length; /* Nombre d'éléments collectés */
@@ -103,7 +110,8 @@ static PyObject *py_analyst_client_new(PyTypeObject *type, PyObject *args, PyObj
Py_ssize_t i; /* Boucle de parcours */
PyObject *item; /* Elément de la liste Python */
GDbCollection *collec; /* Version équivalente native */
- GAnalystClient *client; /* Serveur mis en place */
+ GAnalystClient *client; /* Client mis en place */
+ bool status; /* Bilan d'initialisation */
#define ANALYST_CLIENT_DOC \
"AnalystClient provides and receives binary updates to and from a connected" \
@@ -113,11 +121,15 @@ static PyObject *py_analyst_client_new(PyTypeObject *type, PyObject *args, PyObj
"\n" \
"Instances can be created using the following constructor:\n" \
"\n" \
- " AnalystClient(hash, list)" \
+ " AnalystClient(hash, class, list, loaded=None)" \
"\n" \
- "Where hash is a SHA256 fingerprint of the studied binary and list is a list of" \
+ "Where *hash* is a SHA256 fingerprint of the studied binary, *class* refers to" \
+ " the nature description of the loaded content (as provided from" \
+ " pychrysalide.analysis.LoadedContent.content_class), *list* is a list of" \
" pychrysalide.analysis.db.DbCollection instances ; this kind of list can be" \
" retrived with the pychrysalide.analysis.LoadedBinary.collections attribute." \
+ " The *loaded* object is an optional local already loaded content which has to" \
+ " be a pychrysalide.analysis.LoadedContent instance or *None*." \
"\n" \
"AnalystClient instances emit the following signals:\n" \
"* 'snapshots-updated'\n" \
@@ -131,13 +143,20 @@ static PyObject *py_analyst_client_new(PyTypeObject *type, PyObject *args, PyObj
" Handlers are expected to have only one argument: the client managing the" \
" snapshots."
- ret = PyArg_ParseTuple(args, "sO", &hash, &list);
- if (!ret) return NULL;
+ loaded = NULL;
+
+ ret = PyArg_ParseTuple(args, "ssO|O&", &hash, &class, &list, convert_to_loaded_content, &loaded);
+ if (!ret) return -1;
+
+ /* Initialisation d'un objet GLib */
+
+ ret = forward_pygobjet_init(self);
+ if (ret == -1) return -1;
if (!PySequence_Check(list))
{
PyErr_SetString(PyExc_TypeError, _("The second argument must be a collection list"));
- return NULL;
+ return -1;
}
length = PySequence_Length(list);
@@ -155,7 +174,7 @@ static PyObject *py_analyst_client_new(PyTypeObject *type, PyObject *args, PyObj
if (ret != 1)
{
delete_collections_list(&collections);
- result = NULL;
+ result = -1;
goto exit;
}
@@ -164,14 +183,11 @@ static PyObject *py_analyst_client_new(PyTypeObject *type, PyObject *args, PyObj
}
- client = g_analyst_client_new(hash, collections);
+ client = G_ANALYST_CLIENT(pygobject_get(self));
- if (client != NULL)
- {
- result = pygobject_new(G_OBJECT(client));
- g_object_unref(client);
- }
- else result = NULL;
+ status = g_analyst_client_setup(client, hash, class, collections, loaded);
+
+ result = status ? 0 : -1;
exit:
@@ -851,7 +867,9 @@ PyTypeObject *get_python_analyst_client_type(void)
.tp_methods = py_analyst_client_methods,
.tp_getset = py_analyst_client_getseters,
- .tp_new = py_analyst_client_new,
+
+ .tp_init = py_analyst_client_init,
+ .tp_new = py_analyst_client_new
};
@@ -882,14 +900,17 @@ bool ensure_python_analyst_client_is_registered(void)
if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
{
- if (!ensure_python_hub_client_is_registered())
- return false;
-
module = get_access_to_python_module("pychrysalide.analysis.db");
dict = PyModule_GetDict(module);
- if (!register_class_for_pygobject(dict, G_TYPE_ANALYST_CLIENT, type, get_python_hub_client_type()))
+ if (!ensure_python_hub_client_is_registered())
+ return false;
+
+ if (!register_class_for_pygobject(dict, G_TYPE_ANALYST_CLIENT, type))
+ return false;
+
+ if (!define_loading_status_hint_constants(type))
return false;
}