diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2015-07-17 16:36:21 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2015-07-17 16:36:21 (GMT) |
commit | 24d3836fcf8d443eb654b981f65478cd9923b8f1 (patch) | |
tree | 7672a28b864127e8958c3c6cce751dcf646d2fbe /plugins/pychrysa/format/dex/dex.c | |
parent | a61f089babe336b012da31a494b0f7470b6e1a9a (diff) |
Updated the Python bindings.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@552 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'plugins/pychrysa/format/dex/dex.c')
-rw-r--r-- | plugins/pychrysa/format/dex/dex.c | 99 |
1 files changed, 57 insertions, 42 deletions
diff --git a/plugins/pychrysa/format/dex/dex.c b/plugins/pychrysa/format/dex/dex.c index 6f422a4..a11af52 100644 --- a/plugins/pychrysa/format/dex/dex.c +++ b/plugins/pychrysa/format/dex/dex.c @@ -28,11 +28,12 @@ #include <pygobject.h> -#include <format/dex/dex-int.h> +#include <format/dex/class.h> +#include <format/dex/dex.h> -#include "class.h" -#include "../../quirks.h" +#include "../executable.h" +#include "../../glibext/bincontent.h" @@ -64,19 +65,23 @@ static PyObject *py_dex_format_get_class(PyObject *, PyObject *); static PyObject *py_dex_format_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { PyObject *result; /* Instance à retourner */ - const bin_t *content; /* Données binaires */ - int length; /* Quantité de ces données */ + PyObject *content_obj; /* Objet pour le contenu */ int ret; /* Bilan de lecture des args. */ - GBinFormat *format; /* Version GLib du format */ + GBinContent *content; /* Instance GLib correspondante*/ + GBinFormat *format; /* Création GLib à transmettre */ - ret = PyArg_ParseTuple(args, "s#", &content, &length); - if (!ret) Py_RETURN_NONE; + ret = PyArg_ParseTuple(args, "O", &content_obj); + if (!ret) return NULL; + + ret = PyObject_IsInstance(content_obj, (PyObject *)get_python_binary_content_type()); + if (!ret) return NULL; - format = g_dex_format_new(content, length); - if (format == NULL) Py_RETURN_NONE; + content = G_BIN_CONTENT(pygobject_get(content_obj)); + format = g_dex_format_new(/* FIXME */(bin_t *)content, 0/*content*/); result = pygobject_new(G_OBJECT(format)); - //g_object_unref(format); + + g_object_unref(format); return (PyObject *)result; @@ -149,38 +154,30 @@ static PyObject *py_dex_format_get_class(PyObject *self, PyObject *args) } - - - - - /****************************************************************************** * * -* Paramètres : module = module dont la définition est à compléter. * +* Paramètres : - * * * -* Description : Prend en charge l'objet 'pychrysalide.format.dex.DexFormat'. * +* Description : Fournit un accès à une définition de type à diffuser. * * * -* Retour : Bilan de l'opération. * +* Retour : Définition d'objet pour Python. * * * * Remarques : - * * * ******************************************************************************/ -bool register_python_dex_format(PyObject *module) +PyTypeObject *get_python_dex_format_type(void) { - PyObject *parent_mod; /* Accès au module parent */ - int ret; /* Bilan d'un appel */ - static PyMethodDef py_dex_format_methods[] = { { "count_classes", (PyCFunction)py_dex_format_count_classes, METH_NOARGS, - "Count the quantity of loaded Dex classes." + "count_classes($self, /)\n--\n\nCount the quantity of loaded Dex classes." }, { "get_class", (PyCFunction)py_dex_format_get_class, METH_VARARGS, - "Provide a given loaded Dex class." + "get_class($self, index, /)\n--\n\nProvide a given loaded Dex class." }, { NULL } }; @@ -191,12 +188,12 @@ bool register_python_dex_format(PyObject *module) static PyTypeObject py_dex_format_type = { - PyObject_HEAD_INIT(NULL) + PyVarObject_HEAD_INIT(NULL, 0) .tp_name = "pychrysalide.format.dex.DexFormat", .tp_basicsize = sizeof(PyGObject), - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + .tp_flags = Py_TPFLAGS_DEFAULT, .tp_doc = "PyChrysalide Dex format", @@ -206,27 +203,45 @@ bool register_python_dex_format(PyObject *module) }; - parent_mod = PyImport_ImportModule("pychrysalide.format"); - if (parent_mod == NULL) return false; + return &py_dex_format_type; + +} - py_dex_format_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(parent_mod, "ExeFormat"); - Py_DECREF(parent_mod); - if (PyType_Ready(&py_dex_format_type) < 0) - return false; +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.format.dex.DexFormat'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_dex_format(PyObject *module) +{ + PyTypeObject *py_dex_format_type; /* Type Python 'DexFormat' */ + int ret; /* Bilan d'un appel */ + PyObject *dict; /* Dictionnaire du module */ - Py_INCREF(&py_dex_format_type); - ret = PyModule_AddObject(module, "DexFormat", (PyObject *)&py_dex_format_type); + py_dex_format_type = get_python_dex_format_type(); - parent_mod = PyImport_ImportModule("pychrysalide.format"); - if (parent_mod == NULL) return false; + py_dex_format_type->tp_base = get_python_executable_format_type(); + py_dex_format_type->tp_basicsize = py_dex_format_type->tp_base->tp_basicsize; + + if (PyType_Ready(py_dex_format_type) != 0) + return false; - pygobject_register_class(module, "GDexFormat", G_TYPE_DEX_FORMAT, &py_dex_format_type, - Py_BuildValue("(OO)", py_dex_format_type.tp_base, - PyObject_GetAttrString(parent_mod, "BinFormat"))); + Py_INCREF(py_dex_format_type); + ret = PyModule_AddObject(module, "DexFormat", (PyObject *)py_dex_format_type); + if (ret != 0) return false; - Py_DECREF(parent_mod); + dict = PyModule_GetDict(module); + pygobject_register_class(dict, "DexFormat", G_TYPE_DEX_FORMAT, py_dex_format_type, + Py_BuildValue("(O)", py_dex_format_type->tp_base)); - return (ret == 0); + return true; } |