summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2020-06-23 22:01:00 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2020-06-23 22:01:00 (GMT)
commit7e397e656e983931085ee0d656945b2d8ca3ce5b (patch)
treec766203be348755c557fe8e8d3ae05a754d3cf76
parentd2b5699feb24a5141a3790970dfa5b1a288df4ce (diff)
Improved support for Android boot image Python classes.
-rw-r--r--plugins/bootimg/python/format.c93
1 files changed, 81 insertions, 12 deletions
diff --git a/plugins/bootimg/python/format.c b/plugins/bootimg/python/format.c
index 2f66046..d5e32d3 100644
--- a/plugins/bootimg/python/format.c
+++ b/plugins/bootimg/python/format.c
@@ -29,6 +29,8 @@
#include <i18n.h>
+#include <format/known.h>
+#include <plugins/dt.h>
#include <plugins/pychrysalide/helpers.h>
#include <plugins/pychrysalide/analysis/content.h>
#include <plugins/pychrysalide/format/known.h>
@@ -42,6 +44,9 @@
/* Crée un nouvel objet Python de type 'BootImgFormat'. */
static PyObject *py_bootimg_format_new(PyTypeObject *, PyObject *, PyObject *);
+/* Initialise une instance sur la base du dérivé de GObject. */
+static int py_bootimg_format_init(PyObject *, PyObject *, PyObject *);
+
/* Fournit l'en-tête Bootimg correspondant au format. */
static PyObject *py_bootimg_format_get_header(PyObject *, void *);
@@ -69,7 +74,66 @@ static PyObject *py_bootimg_format_get_ramdisk(PyObject *, void *);
static PyObject *py_bootimg_format_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
- PyObject *result; /* Instance à retourner */
+ 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 */
+
+ /* Validations diverses */
+
+ base = get_python_bootimg_format_type();
+
+ if (type == base)
+ goto simple_way;
+
+ /* Mise en place d'un type dédié */
+
+ first_time = (g_type_from_name(type->tp_name) == 0);
+
+ gtype = build_dynamic_type(G_TYPE_BOOTIMG_FORMAT, type->tp_name, NULL, 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() */
+
+ simple_way:
+
+ result = PyType_GenericNew(type, args, kwds);
+
+ exit:
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* 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_bootimg_format_init(PyObject *self, PyObject *args, PyObject *kwds)
+{
GBinContent *content; /* Instance GLib du contenu */
int ret; /* Bilan de lecture des args. */
GBootImgFormat *format; /* Création GLib à transmettre */
@@ -85,23 +149,26 @@ static PyObject *py_bootimg_format_new(PyTypeObject *type, PyObject *args, PyObj
" provided as a pychrysalide.analysis.BinContent instance."
ret = PyArg_ParseTuple(args, "O&", convert_to_binary_content, &content);
- if (!ret) return NULL;
+ if (!ret) return -1;
- format = g_bootimg_format_new(content);
+ /* Initialisation d'un objet GLib */
- if (format == NULL)
- {
- result = Py_None;
- Py_INCREF(result);
- }
+ ret = forward_pygobjet_init(self);
+ if (ret == -1) return -1;
- else
+ /* Eléments de base */
+
+ if (!check_bootimg_format(content))
{
- result = pygobject_new(G_OBJECT(format));
- g_object_unref(format);
+ PyErr_SetString(PyExc_TypeError, "bad format for an Android boot image");
+ return -1;
}
- return result;
+ format = G_BOOTIMG_FORMAT(pygobject_get(self));
+
+ g_known_format_set_content(G_KNOWN_FORMAT(format), content);
+
+ return 0;
}
@@ -296,6 +363,8 @@ PyTypeObject *get_python_bootimg_format_type(void)
.tp_methods = py_bootimg_format_methods,
.tp_getset = py_bootimg_format_getseters,
+
+ .tp_init = py_bootimg_format_init,
.tp_new = py_bootimg_format_new
};