summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/format/known.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2020-05-21 12:08:29 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2020-05-21 12:08:29 (GMT)
commit7e5b1add6fdeb74b2356acf8ccf7009f45cfa85e (patch)
treeb7373554017e97fcbe24db79d9818272764e858d /plugins/pychrysalide/format/known.c
parent5dd935b27a765177960bdfe4d2fcb296cbbd41da (diff)
Changed the hierarchy of format objects.
Diffstat (limited to 'plugins/pychrysalide/format/known.c')
-rw-r--r--plugins/pychrysalide/format/known.c177
1 files changed, 174 insertions, 3 deletions
diff --git a/plugins/pychrysalide/format/known.c b/plugins/pychrysalide/format/known.c
index c3b5b9d..d75dd05 100644
--- a/plugins/pychrysalide/format/known.c
+++ b/plugins/pychrysalide/format/known.c
@@ -60,6 +60,9 @@ static char *py_known_format_get_description_wrapper(const GKnownFormat *);
/* Assure l'interprétation d'un format en différé. */
static bool py_known_format_analyze_wrapper(GKnownFormat *, wgroup_id_t, GtkStatusStack *);
+/* Réalise un traitement post-désassemblage. */
+static void py_known_format_complete_analysis_wrapper(GKnownFormat *, wgroup_id_t, GtkStatusStack *);
+
/* --------------------------- DEFINITION DU FORMAT CONNU --------------------------- */
@@ -68,6 +71,9 @@ static bool py_known_format_analyze_wrapper(GKnownFormat *, wgroup_id_t, GtkStat
/* Assure l'interprétation d'un format en différé. */
static PyObject *py_known_format_analyze(PyObject *, PyObject *);
+/* Réalise un traitement post-désassemblage. */
+static PyObject *py_known_format_complete_analysis(PyObject *, PyObject *);
+
/* Indique la désignation interne du format. */
static PyObject *py_known_format_get_key(PyObject *, void *);
@@ -166,6 +172,7 @@ static void py_known_format_init_gclass(GKnownFormatClass *class, gpointer unuse
class->get_desc = py_known_format_get_description_wrapper;
class->analyze = py_known_format_analyze_wrapper;
+ class->complete = py_known_format_complete_analysis_wrapper;
}
@@ -203,6 +210,9 @@ static int py_known_format_init(PyObject *self, PyObject *args, PyObject *kwds)
"* pychrysalide.format.KnownFormat._get_description();\n" \
"* pychrysalide.format.KnownFormat._analyze().\n" \
"\n" \
+ "The following method may also be defined for new classes too:\n" \
+ "* pychrysalide.format.KnownFormat._complete_analysis().\n" \
+ "\n" \
"Calls to the *__init__* constructor of this abstract object expect"\
" only one argument: a binary content, provided as a" \
" pychrysalide.analysis.BinContent instance."
@@ -401,6 +411,62 @@ static bool py_known_format_analyze_wrapper(GKnownFormat *format, wgroup_id_t gi
}
+/******************************************************************************
+* *
+* Paramètres : format = format chargé dont l'analyse est lancée. *
+* gid = groupe de travail dédié. *
+* status = barre de statut à tenir informée. *
+* *
+* Description : Réalise un traitement post-désassemblage. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void py_known_format_complete_analysis_wrapper(GKnownFormat *format, wgroup_id_t gid, GtkStatusStack *status)
+{
+ PyGILState_STATE gstate; /* Sauvegarde d'environnement */
+ PyObject *pyobj; /* Objet Python concerné */
+ PyObject *args; /* Arguments pour l'appel */
+ PyObject *pyret; /* Bilan d'exécution */
+
+#define KNOWN_FORMAT_COMPLETE_ANALYSIS_WRAPPER PYTHON_VOID_WRAPPER_DEF \
+( \
+ _complete_analysis, "$self, gid, status, /", \
+ METH_VARARGS, \
+ "Abstract method used to complete an analysis of a known format.\n" \
+ "\n" \
+ "The identifier refers to the working queue used to process the" \
+ " analysis. A reference to the main status bar may also be" \
+ " provided, as a pychrysalide.gtkext.StatusStack instance if" \
+ " running in graphical mode or None otherwise.\n" \
+)
+
+ gstate = PyGILState_Ensure();
+
+ pyobj = pygobject_new(G_OBJECT(format));
+
+ if (has_python_method(pyobj, "_complete_analysis"))
+ {
+ args = PyTuple_New(2);
+
+ PyTuple_SetItem(args, 0, PyLong_FromUnsignedLong(gid));
+ PyTuple_SetItem(args, 1, pygobject_new(G_OBJECT(status)));
+
+ pyret = run_python_method(pyobj, "_complete_analysis", args);
+
+ Py_DECREF(args);
+ Py_XDECREF(pyret);
+
+ }
+
+ PyGILState_Release(gstate);
+
+}
+
+
/* ---------------------------------------------------------------------------------- */
/* DEFINITION DU FORMAT CONNU */
@@ -461,6 +527,57 @@ static PyObject *py_known_format_analyze(PyObject *self, PyObject *args)
/******************************************************************************
* *
+* Paramètres : self = objet représentant un format connu. *
+* args = arguments fournis pour l'opération. *
+* *
+* Description : Réalise un traitement post-désassemblage. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_known_format_complete_analysis(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Bilan à retourner */
+ int ret; /* Bilan de lecture des args. */
+ GKnownFormat *format; /* Format connu manipulé */
+
+#define KNOWN_FORMAT_COMPLETE_ANALYSIS_METHOD PYTHON_METHOD_DEF \
+( \
+ complete_analysis, "$self, gid, status, /", \
+ METH_VARARGS, py_known_format, \
+ "Complete an analysis of a known format.\n" \
+ "\n" \
+ "This process is usually done once the disassembling process" \
+ " is completed.\n" \
+ "\n" \
+ "The identifier refers to the working queue used to process" \
+ " the analysis. A reference to the main status bar may also be" \
+ " provided, as a pychrysalide.gtkext.StatusStack instance if" \
+ " running in graphical mode or None otherwise.\n" \
+ "\n" \
+ "The return value is a boolean status of the operation." \
+)
+
+ ret = PyArg_ParseTuple(args, "");//|KO!", &gid, &status);
+ if (!ret) return NULL;
+
+ format = G_KNOWN_FORMAT(pygobject_get(self));
+
+ g_known_format_complete_analysis(format, 0, NULL);
+
+ result = Py_None;
+ Py_INCREF(result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : self = objet Python concerné par l'appel. *
* closure = non utilisé ici. *
* *
@@ -566,9 +683,16 @@ static PyObject *py_known_format_get_content(PyObject *self, void *closure)
content = g_known_format_get_content(format);
- result = pygobject_new(G_OBJECT(content));
-
- g_object_unref(content);
+ if (content != NULL)
+ {
+ result = pygobject_new(G_OBJECT(content));
+ g_object_unref(content);
+ }
+ else
+ {
+ result = Py_None;
+ Py_INCREF(result);
+ }
return result;
@@ -592,7 +716,9 @@ PyTypeObject *get_python_known_format_type(void)
static PyMethodDef py_known_format_methods[] = {
KNOWN_FORMAT_GET_DESCRIPTION_WRAPPER,
KNOWN_FORMAT_ANALYZE_WRAPPER,
+ KNOWN_FORMAT_COMPLETE_ANALYSIS_WRAPPER,
KNOWN_FORMAT_ANALYZE_METHOD,
+ KNOWN_FORMAT_COMPLETE_ANALYSIS_METHOD,
{ NULL }
};
@@ -661,3 +787,48 @@ bool ensure_python_known_format_is_registered(void)
return true;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : arg = argument quelconque à tenter de convertir. *
+* dst = destination des valeurs récupérées en cas de succès. *
+* *
+* Description : Tente de convertir en format connu. *
+* *
+* Retour : Bilan de l'opération, voire indications supplémentaires. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int convert_to_known_format(PyObject *arg, void *dst)
+{
+ int result; /* Bilan à retourner */
+
+ result = PyObject_IsInstance(arg, (PyObject *)get_python_known_format_type());
+
+ switch (result)
+ {
+ case -1:
+ /* L'exception est déjà fixée par Python */
+ result = 0;
+ break;
+
+ case 0:
+ PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to known format");
+ break;
+
+ case 1:
+ *((GKnownFormat **)dst) = G_KNOWN_FORMAT(pygobject_get(arg));
+ break;
+
+ default:
+ assert(false);
+ break;
+
+ }
+
+ return result;
+
+}