summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/analysis/content.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2023-09-27 23:08:50 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2023-09-27 23:08:50 (GMT)
commit641761e51672fa33f27acdcdb40b46b506ab07dc (patch)
tree8db1ce412b87f0217b250ff371ebcc51ab3905cf /plugins/pychrysalide/analysis/content.c
parenta5cd93644fbb16dfc181f630b1c8d739fdc685fb (diff)
Replace interface by inheritance for binary content objects.
Diffstat (limited to 'plugins/pychrysalide/analysis/content.c')
-rw-r--r--plugins/pychrysalide/analysis/content.c80
1 files changed, 56 insertions, 24 deletions
diff --git a/plugins/pychrysalide/analysis/content.c b/plugins/pychrysalide/analysis/content.c
index f94e3f7..a4f2b99 100644
--- a/plugins/pychrysalide/analysis/content.c
+++ b/plugins/pychrysalide/analysis/content.c
@@ -40,6 +40,7 @@
#include "cattribs.h"
#include "constants.h"
+#include "storage/serialize.h"
#include "../access.h"
#include "../helpers.h"
#include "../arch/vmpa.h"
@@ -49,8 +50,13 @@
/* ------------------------ GLUE POUR CREATION DEPUIS PYTHON ------------------------ */
-/* Procède à l'initialisation de l'interface de génération. */
-static void py_binary_content_interface_init(GBinContentIface *, gpointer *);
+/* Initialise la classe générique des contenus de binaire. */
+static void py_binary_content_init_gclass(GBinContentClass *, gpointer);
+
+CREATE_DYN_ABSTRACT_CONSTRUCTOR(binary_content, G_TYPE_BIN_CONTENT, py_binary_content_init_gclass);
+
+/* Initialise une instance sur la base du dérivé de GObject. */
+static int py_binary_content_init(PyObject *, PyObject *, PyObject *);
/* Fournit le nom associé au contenu binaire. */
static char *py_binary_content_describe_wrapper(const GBinContent *, bool);
@@ -126,10 +132,10 @@ static PyObject *py_binary_content_get_data(PyObject *, void *);
/******************************************************************************
* *
-* Paramètres : iface = interface GLib à initialiser. *
-* unused = adresse non utilisée ici. *
+* Paramètres : class = classe à initialiser. *
+* unused = données non utilisées ici. *
* *
-* Description : Procède à l'initialisation de l'interface de génération. *
+* Description : Initialise la classe générique des contenus de binaire. *
* *
* Retour : - *
* *
@@ -137,9 +143,38 @@ static PyObject *py_binary_content_get_data(PyObject *, void *);
* *
******************************************************************************/
-static void py_binary_content_interface_init(GBinContentIface *iface, gpointer *unused)
+static void py_binary_content_init_gclass(GBinContentClass *class, gpointer unused)
{
-#define BINARY_CONTENT_DOC \
+ class->describe = py_binary_content_describe_wrapper;
+
+ class->read_raw = py_binary_content_read_raw_wrapper;
+ class->read_u8 = py_binary_content_read_u8_wrapper;
+ class->read_u16 = py_binary_content_read_u16_wrapper;
+ class->read_u32 = py_binary_content_read_u32_wrapper;
+ class->read_u64 = py_binary_content_read_u64_wrapper;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = objet à initialiser (théoriquement). *
+* args = arguments fournis à l'appel. *
+* kwds = arguments de type key=val fournis. *
+* *
+* Description : Initialise une instance sur la base du dérivé de GObject. *
+* *
+* Retour : 0. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static int py_binary_content_init(PyObject *self, PyObject *args, PyObject *kwds)
+{
+ int ret; /* Bilan de lecture des args. */
+
+#define BINARY_CONTENT_DOC \
"The BinContent is an interface which handles access to a given binary" \
" content.\n" \
"\n" \
@@ -161,13 +196,12 @@ static void py_binary_content_interface_init(GBinContentIface *iface, gpointer *
"* pychrysalide.analysis.BinContent._read_u32();\n" \
"* pychrysalide.analysis.BinContent._read_u64();\n"
- iface->describe = py_binary_content_describe_wrapper;
+ /* Initialisation d'un objet GLib */
+
+ ret = forward_pygobjet_init(self);
+ if (ret == -1) return -1;
- iface->read_raw = py_binary_content_read_raw_wrapper;
- iface->read_u8 = py_binary_content_read_u8_wrapper;
- iface->read_u16 = py_binary_content_read_u16_wrapper;
- iface->read_u32 = py_binary_content_read_u32_wrapper;
- iface->read_u64 = py_binary_content_read_u64_wrapper;
+ return 0;
}
@@ -1406,14 +1440,17 @@ PyTypeObject *get_python_binary_content_type(void)
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "pychrysalide.analysis.BinContent",
- .tp_basicsize = sizeof(PyObject),
+ .tp_basicsize = sizeof(PyGObject),
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
.tp_doc = BINARY_CONTENT_DOC,
.tp_methods = py_binary_content_methods,
- .tp_getset = py_binary_content_getseters
+ .tp_getset = py_binary_content_getseters,
+
+ .tp_init = py_binary_content_init,
+ .tp_new = py_binary_content_new,
};
@@ -1440,23 +1477,18 @@ bool ensure_python_binary_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_binary_content_interface_init,
- .interface_finalize = NULL,
- .interface_data = NULL,
-
- };
-
type = get_python_binary_content_type();
if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
{
+ if (!ensure_python_serializable_object_is_registered())
+ return false;
+
module = get_access_to_python_module("pychrysalide.analysis");
dict = PyModule_GetDict(module);
- if (!register_interface_for_pygobject(dict, G_TYPE_BIN_CONTENT, type, &info))
+ if (!register_class_for_pygobject(dict, G_TYPE_BIN_CONTENT, type))
return false;
if (!define_analysis_content_constants(type))