diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/pychrysalide/analysis/loaded.c | 116 |
1 files changed, 87 insertions, 29 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 } }; |