diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2021-09-30 06:41:23 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2021-09-30 06:41:23 (GMT) |
commit | da3da13a32a2f98c16a591a389e274a7803fc48a (patch) | |
tree | b2a9b5976982781b732114c9daa3ac2f7285f337 /plugins | |
parent | 0b5e9a3c7bcd3eb15be0e888ebfe46d14497b101 (diff) |
Move loaded contents from interface to object structures.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/pychrysalide/analysis/binary.c | 2 | ||||
-rw-r--r-- | plugins/pychrysalide/analysis/loaded.c | 119 |
2 files changed, 91 insertions, 30 deletions
diff --git a/plugins/pychrysalide/analysis/binary.c b/plugins/pychrysalide/analysis/binary.c index c9dc9c5..d8f01e5 100644 --- a/plugins/pychrysalide/analysis/binary.c +++ b/plugins/pychrysalide/analysis/binary.c @@ -562,7 +562,7 @@ bool ensure_python_loaded_binary_is_registered(void) if (!ensure_python_loaded_content_is_registered()) return false; - if (!register_class_for_pygobject(dict, G_TYPE_LOADED_BINARY, type, &PyGObject_Type)) + if (!register_class_for_pygobject(dict, G_TYPE_LOADED_BINARY, type, get_python_loaded_content_type())) return false; } diff --git a/plugins/pychrysalide/analysis/loaded.c b/plugins/pychrysalide/analysis/loaded.c index 3ed51d5..607f57c 100644 --- a/plugins/pychrysalide/analysis/loaded.c +++ b/plugins/pychrysalide/analysis/loaded.c @@ -35,6 +35,7 @@ #include <analysis/loaded-int.h> #include <core/global.h> +#include <plugins/dt.h> #include "content.h" @@ -47,8 +48,11 @@ /* ------------------------ GLUE POUR CREATION DEPUIS PYTHON ------------------------ */ -/* Procède à l'initialisation de l'interface de génération. */ -static void py_loaded_content_interface_init(GLoadedContentIface *, gpointer *); +/* Accompagne la création d'une instance dérivée en Python. */ +static PyObject *py_loaded_content_new(PyTypeObject *, PyObject *, PyObject *); + +/* Initialise la classe générique des contenus chargés. */ +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 *); @@ -121,21 +125,28 @@ static PyObject *py_loaded_content_get_format_name(PyObject *, void *); /****************************************************************************** * * -* Paramètres : iface = interface GLib à initialiser. * -* unused = adresse non utilisée ici. * +* Paramètres : type = type du nouvel objet à mettre en place. * +* args = éventuelle liste d'arguments. * +* kwds = éventuel dictionnaire de valeurs mises à disposition. * * * -* Description : Procède à l'initialisation de l'interface de génération. * +* Description : Accompagne la création d'une instance dérivée en Python. * * * -* Retour : - * +* Retour : Nouvel objet Python mis en place ou NULL en cas d'échec. * * * * Remarques : - * * * ******************************************************************************/ -static void py_loaded_content_interface_init(GLoadedContentIface *iface, gpointer *unused) +static PyObject *py_loaded_content_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { + PyObject *result; /* Objet à retourner */ + PyTypeObject *base; /* Type de base à dériver */ + bool first_time; /* Evite les multiples passages*/ + GType gtype; /* Nouveau type de processeur */ + bool status; /* Bilan d'un enregistrement */ + #define LOADED_CONTENT_DOC \ - "The LoadedContent interface is an intermediary level of abstraction" \ + "The LoadedContent object is an intermediary level of abstraction" \ " for all loaded binary contents to analyze." \ "\n" \ "No matter if the loaded content comes from an ELF file or XML data," \ @@ -157,18 +168,74 @@ static void py_loaded_content_interface_init(GLoadedContentIface *iface, gpointe "* pychrysalide.analysis.storage.LoadedContent._build_view();\n" \ "* pychrysalide.analysis.storage.LoadedContent._get_view_index();\n" - iface->get_content = py_loaded_content_get_content_wrapper; - iface->get_format_name = py_loaded_content_get_format_name_wrapper; + /* Validations diverses */ + + base = get_python_loaded_content_type(); + + if (type == base) + { + result = NULL; + PyErr_Format(PyExc_RuntimeError, _("%s is an abstract class"), type->tp_name); + goto exit; + } + + /* Mise en place d'un type dédié */ + + first_time = (g_type_from_name(type->tp_name) == 0); + + gtype = build_dynamic_type(G_TYPE_LOADED_CONTENT, type->tp_name, + (GClassInitFunc)py_loaded_content_init_gclass, NULL, NULL); + + if (first_time) + { + status = register_class_for_dynamic_pygobject(gtype, type, base); + + if (!status) + { + result = NULL; + goto exit; + } + + } + + /* On crée, et on laisse ensuite la main à PyGObject_Type.tp_init() */ + + result = PyType_GenericNew(type, args, kwds); + + exit: + + return result; - iface->analyze = py_loaded_content_analyze_wrapper; +} - iface->describe = py_loaded_content_describe_wrapper; - iface->count_views = py_loaded_content_count_views_wrapper; - iface->get_view_name = py_loaded_content_get_view_name_wrapper; - iface->build_def_view = py_loaded_content_build_default_view_wrapper; - iface->build_view = py_loaded_content_build_view_wrapper; - iface->get_view_index = py_loaded_content_get_view_index_wrapper; +/****************************************************************************** +* * +* Paramètres : class = classe à initialiser. * +* unused = données non utilisées ici. * +* * +* Description : Initialise la classe générique des contenus chargés. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +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->analyze = py_loaded_content_analyze_wrapper; + + class->describe = py_loaded_content_describe_wrapper; + + class->count_views = py_loaded_content_count_views_wrapper; + class->get_view_name = py_loaded_content_get_view_name_wrapper; + class->build_def_view = py_loaded_content_build_default_view_wrapper; + class->build_view = py_loaded_content_build_view_wrapper; + class->get_view_index = py_loaded_content_get_view_index_wrapper; } @@ -1396,14 +1463,16 @@ PyTypeObject *get_python_loaded_content_type(void) PyVarObject_HEAD_INIT(NULL, 0) .tp_name = "pychrysalide.analysis.LoadedContent", - .tp_basicsize = sizeof(PyObject), + .tp_basicsize = sizeof(PyGObject), - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_BASETYPE, .tp_doc = LOADED_CONTENT_DOC, .tp_methods = py_loaded_content_methods, - .tp_getset = py_loaded_content_getseters + .tp_getset = py_loaded_content_getseters, + + .tp_new = py_loaded_content_new, }; @@ -1430,14 +1499,6 @@ bool ensure_python_loaded_content_is_registered(void) PyObject *module; /* Module à recompléter */ PyObject *dict; /* Dictionnaire du module */ - static GInterfaceInfo info = { /* Paramètres d'inscription */ - - .interface_init = (GInterfaceInitFunc)py_loaded_content_interface_init, - .interface_finalize = NULL, - .interface_data = NULL, - - }; - type = get_python_loaded_content_type(); if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) @@ -1449,7 +1510,7 @@ bool ensure_python_loaded_content_is_registered(void) if (!ensure_python_named_widget_is_registered()) return false; - if (!register_interface_for_pygobject(dict, G_TYPE_LOADED_CONTENT, type, &info)) + if (!register_class_for_pygobject(dict, G_TYPE_LOADED_CONTENT, type, &PyGObject_Type)) return false; } |