From a27f101ec7351a006537e819f9af55271620bc50 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Sun, 24 Oct 2021 20:17:53 +0200 Subject: Link a class to loaded content nature. --- plugins/pychrysalide/analysis/loaded.c | 116 ++++++++++++++++++++++++--------- src/analysis/binary.c | 41 ++++++++++-- src/analysis/loaded-int.h | 6 +- src/analysis/loaded.c | 9 +-- src/analysis/loaded.h | 4 +- src/analysis/project.c | 6 +- src/gui/dialogs/loading.c | 8 +-- 7 files changed, 139 insertions(+), 51 deletions(-) diff --git a/plugins/pychrysalide/analysis/loaded.c b/plugins/pychrysalide/analysis/loaded.c index 607f57c..89762d3 100644 --- a/plugins/pychrysalide/analysis/loaded.c +++ b/plugins/pychrysalide/analysis/loaded.c @@ -57,8 +57,8 @@ static void py_loaded_content_init_gclass(GLoadedContentClass *, gpointer); /* Fournit le contenu représenté de l'élément chargé. */ static GBinContent *py_loaded_content_get_content_wrapper(const GLoadedContent *); -/* Fournit le format associé à l'élément chargé. */ -static char *py_loaded_content_get_format_name_wrapper(const GLoadedContent *); +/* Décrit la nature du contenu reconnu pour l'élément chargé. */ +static char *py_loaded_content_get_content_class_wrapper(const GLoadedContent *, bool); /* Lance l'analyse propre à l'élément chargé. */ static bool py_loaded_content_analyze_wrapper(GLoadedContent *, bool, bool, wgroup_id_t, GtkStatusStack *); @@ -113,8 +113,11 @@ static PyObject *py_loaded_content_build_view(PyObject *, PyObject *); /* Fournit le contenu représenté de l'élément chargé. */ static PyObject *py_loaded_content_get_content(PyObject *, void *); -/* Fournit le format associé à l'élément chargé. */ -static PyObject *py_loaded_content_get_format_name(PyObject *, void *); +/* Décrit la nature du contenu reconnu pour l'élément chargé. */ +static PyObject *py_loaded_content_get_content_class(PyObject *, void *); + +/* Décrit la nature du contenu reconnu pour l'élément chargé. */ +static PyObject *py_loaded_content_get_content_class_for_human(PyObject *, void *); @@ -159,7 +162,7 @@ static PyObject *py_loaded_content_new(PyTypeObject *type, PyObject *args, PyObj "\n" \ "The following methods have to be defined for new implementations:\n" \ "* pychrysalide.analysis.storage.LoadedContent._get_content();\n" \ - "* pychrysalide.analysis.storage.LoadedContent._get_format_name();\n" \ + "* pychrysalide.analysis.storage.LoadedContent._get_content_class();\n" \ "* pychrysalide.analysis.storage.LoadedContent._analyze();\n" \ "* pychrysalide.analysis.storage.LoadedContent._describe();\n" \ "* pychrysalide.analysis.storage.LoadedContent._count_views();\n" \ @@ -225,7 +228,7 @@ static PyObject *py_loaded_content_new(PyTypeObject *type, PyObject *args, PyObj static void py_loaded_content_init_gclass(GLoadedContentClass *class, gpointer unused) { class->get_content = py_loaded_content_get_content_wrapper; - class->get_format_name = py_loaded_content_get_format_name_wrapper; + class->get_content_class = py_loaded_content_get_content_class_wrapper; class->analyze = py_loaded_content_analyze_wrapper; @@ -301,31 +304,34 @@ static GBinContent *py_loaded_content_get_content_wrapper(const GLoadedContent * /****************************************************************************** * * * Paramètres : content = élément chargé à manipuler. * +* human = description humaine attendue ? * * * -* Description : Fournit le format associé à l'élément chargé. * +* Description : Décrit la nature du contenu reconnu pour l'élément chargé. * * * -* Retour : Format associé à l'élément chargé. * +* Retour : Classe de contenu associée à l'élément chargé. * * * * Remarques : - * * * ******************************************************************************/ -static char *py_loaded_content_get_format_name_wrapper(const GLoadedContent *content) +static char *py_loaded_content_get_content_class_wrapper(const GLoadedContent *content, bool human) { char *result; /* Contenu interne à renvoyer */ PyGILState_STATE gstate; /* Sauvegarde d'environnement */ PyObject *pyobj; /* Objet Python concerné */ + PyObject *args; /* Arguments pour l'appel */ + PyObject *hobj; /* Argument pour Python */ PyObject *pyret; /* Bilan de consultation */ int ret; /* Validité d'une conversion */ -#define LOADED_CONTENT_GET_FORMAT_NAME_WRAPPER PYTHON_WRAPPER_DEF \ +#define LOADED_CONTENT_GET_CONTENT_CLASS_WRAPPER PYTHON_WRAPPER_DEF \ ( \ - _get_format_name, "$self", \ + _get_content_class, "$self, human", \ METH_VARARGS, \ - "Abstract method used to provide the aw name of the format connected" \ - " to the loaded content.\n" \ + "Abstract method used to provide the nature of the loaded content.\n" \ "\n" \ - "The name associated to a loaded Elf binary is for instance 'elf'." \ + "The description associated to a loaded ARM Elf binary is for instance" \ + " 'elf-armv7', or 'Elf, ARMv7' for the human version." \ ) result = NULL; @@ -334,9 +340,16 @@ static char *py_loaded_content_get_format_name_wrapper(const GLoadedContent *con pyobj = pygobject_new(G_OBJECT(content)); - if (has_python_method(pyobj, "_get_format_name")) + if (has_python_method(pyobj, "_get_content_class")) { - pyret = run_python_method(pyobj, "_get_format_name", NULL); + args = PyTuple_New(1); + + hobj = (human ? Py_True : Py_False); + Py_INCREF(hobj); + + PyTuple_SetItem(args, 0, hobj); + + pyret = run_python_method(pyobj, "_get_content_class", args); if (pyret != NULL) { @@ -349,6 +362,8 @@ static char *py_loaded_content_get_format_name_wrapper(const GLoadedContent *con } + Py_DECREF(args); + } Py_DECREF(pyobj); @@ -1381,35 +1396,77 @@ static PyObject *py_loaded_content_get_content(PyObject *self, void *closure) * Paramètres : self = objet Python concerné par l'appel. * * closure = non utilisé ici. * * * -* Description : Fournit le format associé à l'élément chargé. * +* Description : Décrit la nature du contenu reconnu pour l'élément chargé. * * * -* Retour : Format associé à l'élément chargé. * +* Retour : Classe de contenu associée à l'élément chargé. * * * * Remarques : - * * * ******************************************************************************/ -static PyObject *py_loaded_content_get_format_name(PyObject *self, void *closure) +static PyObject *py_loaded_content_get_content_class(PyObject *self, void *closure) { PyObject *result; /* Instance Python à retourner */ GLoadedContent *content; /* Version GLib de l'élément */ - GBinContent *bincnt; /* Contenu binaire associé */ + char *class; /* Nature du contenu binaire */ -#define LOADED_CONTENT_FORMAT_NAME_ATTRIB PYTHON_GET_DEF_FULL \ +#define LOADED_CONTENT_CONTENT_CLASS_ATTRIB PYTHON_GET_DEF_FULL \ ( \ - format_name, py_loaded_content, \ - "Raw name of the format connected to the loaded content.\n" \ + content_class, py_loaded_content, \ + "Nature of the loaded content.\n" \ "\n" \ - "The name associated to a loaded Elf binary is for instance 'elf'." \ + "The description associated to a loaded ARM Elf binary is for instance" \ + " 'elf-armv7'." \ ) content = G_LOADED_CONTENT(pygobject_get(self)); - bincnt = g_loaded_content_get_content(content); + class = g_loaded_content_get_content_class(content, false); - result = pygobject_new(G_OBJECT(bincnt)); + result = PyUnicode_FromString(class); - g_object_unref(G_OBJECT(bincnt)); + free(class); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Décrit la nature du contenu reconnu pour l'élément chargé. * +* * +* Retour : Classe de contenu associée à l'élément chargé. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_loaded_content_get_content_class_for_human(PyObject *self, void *closure) +{ + PyObject *result; /* Instance Python à retourner */ + GLoadedContent *content; /* Version GLib de l'élément */ + char *class; /* Nature du contenu binaire */ + +#define LOADED_CONTENT_CONTENT_CLASS_FOR_HUMAN_ATTRIB PYTHON_GET_DEF_FULL \ +( \ + content_class_for_human, py_loaded_content, \ + "Humain version of the nature of the loaded content.\n" \ + "\n" \ + "The description associated to a loaded ARM Elf binary is for instance" \ + " ''Elf, ARMv7'." \ +) + + content = G_LOADED_CONTENT(pygobject_get(self)); + + class = g_loaded_content_get_content_class(content, true); + + result = PyUnicode_FromString(class); + + free(class); return result; @@ -1432,7 +1489,7 @@ PyTypeObject *get_python_loaded_content_type(void) { static PyMethodDef py_loaded_content_methods[] = { LOADED_CONTENT_GET_CONTENT_WRAPPER, - LOADED_CONTENT_GET_FORMAT_NAME_WRAPPER, + LOADED_CONTENT_GET_CONTENT_CLASS_WRAPPER, LOADED_CONTENT_ANALYZE_WRAPPER, LOADED_CONTENT_DESCRIBE_WRAPPER, LOADED_CONTENT_COUNT_VIEWS_WRAPPER, @@ -1454,7 +1511,8 @@ PyTypeObject *get_python_loaded_content_type(void) static PyGetSetDef py_loaded_content_getseters[] = { LOADED_CONTENT_CONTENT_ATTRIB, - LOADED_CONTENT_FORMAT_NAME_ATTRIB, + LOADED_CONTENT_CONTENT_CLASS_ATTRIB, + LOADED_CONTENT_CONTENT_CLASS_FOR_HUMAN_ATTRIB, { NULL } }; diff --git a/src/analysis/binary.c b/src/analysis/binary.c index ddd2e30..5d604be 100644 --- a/src/analysis/binary.c +++ b/src/analysis/binary.c @@ -156,8 +156,8 @@ static bool g_loaded_binary_save(GLoadedBinary *, xmlDoc *, xmlXPathContext *, c /* Fournit le contenu représenté de l'élément chargé. */ static GBinContent *g_loaded_binary_get_content(const GLoadedBinary *); -/* Fournit le contenu représenté de l'élément chargé. */ -static char *g_loaded_binary_get_format_name(const GLoadedBinary *); +/* Décrit la nature du contenu reconnu pour l'élément chargé. */ +static char *g_loaded_binary_get_content_class(const GLoadedBinary *, bool); /* Assure le désassemblage en différé. */ static bool g_loaded_binary_analyze(GLoadedBinary *, bool, bool, wgroup_id_t, GtkStatusStack *); @@ -225,7 +225,7 @@ static void g_loaded_binary_class_init(GLoadedBinaryClass *klass) loaded->save = (save_content_fc)g_loaded_binary_save; loaded->get_content = (get_content_fc)g_loaded_binary_get_content; - loaded->get_format_name = (get_format_name_fc)g_loaded_binary_get_format_name; + loaded->get_content_class = (get_content_class_fc)g_loaded_binary_get_content_class; loaded->analyze = (analyze_loaded_fc)g_loaded_binary_analyze; @@ -1310,9 +1310,10 @@ static bool g_loaded_binary_save(GLoadedBinary *binary, xmlDoc *xdoc, xmlXPathCo } + /* if (result) { - key = g_loaded_content_get_format_name(G_LOADED_CONTENT(binary)); + key = g_loaded_content_get_content_class(G_LOADED_CONTENT(binary)); result = add_string_attribute_to_node(xdoc, context, path, "format", key); free(key); } @@ -1323,6 +1324,7 @@ static bool g_loaded_binary_save(GLoadedBinary *binary, xmlDoc *xdoc, xmlXPathCo result = add_string_attribute_to_node(xdoc, context, path, "arch", key); free(key); } + */ if (result) result = g_loaded_binary_save_storage(binary, xdoc, context, path); @@ -1366,6 +1368,7 @@ static GBinContent *g_loaded_binary_get_content(const GLoadedBinary *binary) /****************************************************************************** * * * Paramètres : binary = élément chargé à manipuler. * +* human = description humaine attendue ? * * * * Description : Fournit le contenu représenté de l'élément chargé. * * * @@ -1375,11 +1378,37 @@ static GBinContent *g_loaded_binary_get_content(const GLoadedBinary *binary) * * ******************************************************************************/ -static char *g_loaded_binary_get_format_name(const GLoadedBinary *binary) +static char *g_loaded_binary_get_content_class(const GLoadedBinary *binary, bool human) { char *result; /* Désignation à retourner */ + char *part; /* Partie à intégrer */ + + if (human) + { + result = g_known_format_get_description(G_KNOWN_FORMAT(binary->format)); + + result = stradd(result, ", "); + + part = g_arch_processor_get_desc(binary->proc); + + result = stradd(result, part); + + free(part); + + } + else + { + result = g_known_format_get_key(G_KNOWN_FORMAT(binary->format)); + + result = stradd(result, "-"); - result = g_known_format_get_key(G_KNOWN_FORMAT(binary->format)); + part = g_arch_processor_get_key(binary->proc); + + result = stradd(result, part); + + free(part); + + } return result; diff --git a/src/analysis/loaded-int.h b/src/analysis/loaded-int.h index cd47a6a..62534a6 100644 --- a/src/analysis/loaded-int.h +++ b/src/analysis/loaded-int.h @@ -39,8 +39,8 @@ typedef bool (* save_content_fc) (GLoadedContent *, xmlDoc *, xmlXPathContext *, /* Fournit le contenu représenté de l'élément chargé. */ typedef GBinContent * (* get_content_fc) (const GLoadedContent *); -/* Fournit le format associé à l'élément chargé. */ -typedef char * (* get_format_name_fc) (const GLoadedContent *); +/* Décrit la nature du contenu reconnu pour l'élément chargé. */ +typedef char * (* get_content_class_fc) (const GLoadedContent *, bool); /* Assure l'analyse d'un contenu chargé en différé. */ typedef bool (* analyze_loaded_fc) (GLoadedContent *, bool, bool, wgroup_id_t, GtkStatusStack *); @@ -85,7 +85,7 @@ struct _GLoadedContentClass save_content_fc save; /* Sauvegarde dans du XML */ get_content_fc get_content; /* Fourniture du contenu brut */ - get_format_name_fc get_format_name; /* Fourniture du format associé*/ + get_content_class_fc get_content_class; /* Indication de classe liée */ analyze_loaded_fc analyze; /* Analyse du contenu chargé */ diff --git a/src/analysis/loaded.c b/src/analysis/loaded.c index 3a497f9..9ec2f74 100644 --- a/src/analysis/loaded.c +++ b/src/analysis/loaded.c @@ -296,23 +296,24 @@ GBinContent *g_loaded_content_get_content(const GLoadedContent *content) /****************************************************************************** * * * Paramètres : content = élément chargé à manipuler. * +* human = description humaine attendue ? * * * -* Description : Fournit le format associé à l'élément chargé. * +* Description : Décrit la nature du contenu reconnu pour l'élément chargé. * * * -* Retour : Format associé à l'élément chargé. * +* Retour : Classe de contenu associée à l'élément chargé. * * * * Remarques : - * * * ******************************************************************************/ -char *g_loaded_content_get_format_name(const GLoadedContent *content) +char *g_loaded_content_get_content_class(const GLoadedContent *content, bool human) { char *result; /* Contenu interne à renvoyer */ GLoadedContentClass *class; /* Classe de l'instance */ class = G_LOADED_CONTENT_GET_CLASS(content); - result = class->get_format_name(content); + result = class->get_content_class(content, human); return result; diff --git a/src/analysis/loaded.h b/src/analysis/loaded.h index 9a88f8c..406375c 100644 --- a/src/analysis/loaded.h +++ b/src/analysis/loaded.h @@ -67,8 +67,8 @@ bool g_loaded_content_save(GLoadedContent *, xmlDoc *, xmlXPathContext *, const /* Fournit le contenu représenté de l'élément chargé. */ GBinContent *g_loaded_content_get_content(const GLoadedContent *); -/* Fournit le format associé à l'élément chargé. */ -char *g_loaded_content_get_format_name(const GLoadedContent *); +/* Décrit la nature du contenu reconnu pour l'élément chargé. */ +char *g_loaded_content_get_content_class(const GLoadedContent *, bool); /* Lance l'analyse propre à l'élément chargé. */ void g_loaded_content_analyze(GLoadedContent *, bool, bool); diff --git a/src/analysis/project.c b/src/analysis/project.c index b57afc7..682dfb9 100644 --- a/src/analysis/project.c +++ b/src/analysis/project.c @@ -1249,12 +1249,12 @@ static void on_new_content_resolved(GContentResolver *resolver, wgroup_id_t wid, hash = g_binary_content_get_checksum(content); g_object_unref(G_OBJECT(content)); - format = g_loaded_content_get_format_name(available[i]); + format = "FIXME";//g_loaded_content_get_format_name(available[i]); asprintf(&access, "/ChrysalideProject/LoadedContents/Content[@hash='%s' and @format='%s']", hash, format); - free(format); + //free(format); xobject = get_node_xpath_object(handler->context, access); @@ -1309,7 +1309,7 @@ static void on_new_content_resolved(GContentResolver *resolver, wgroup_id_t wid, /** * S'il s'agit des résultats de la dernière exploration, * alors les groupes contenant les éléments chargés vont - * être libéré, potentiellement pendant l'analyse. + * être libérés, potentiellement pendant l'analyse. * * On temporise en incrémentant les références. */ diff --git a/src/gui/dialogs/loading.c b/src/gui/dialogs/loading.c index 912eb8d..39c5820 100644 --- a/src/gui/dialogs/loading.c +++ b/src/gui/dialogs/loading.c @@ -459,7 +459,7 @@ void add_content_to_loading_dialog(GtkBuilder *builder, GLoadedContent *content, { GtkListStore *store; /* Modèle de gestion */ char *desc; /* Description d'un contenu */ - char *format; /* Format associé à un contenu */ + char *class; /* Format associé à un contenu */ char *name; /* Désignation complète */ gboolean recognized; /* Nature du contenu */ GtkTreeIter iter; /* Point d'insertion */ @@ -476,11 +476,11 @@ void add_content_to_loading_dialog(GtkBuilder *builder, GLoadedContent *content, /* Inscription */ desc = g_loaded_content_describe(content, false); - format = g_loaded_content_get_format_name(content); + class = g_loaded_content_get_content_class(content, true); - asprintf(&name, "%s (%s)", desc, format); + asprintf(&name, "%s (%s)", desc, class); - free(format); + free(class); free(desc); recognized = TRUE; -- cgit v0.11.2-87-g4458