summaryrefslogtreecommitdiff
path: root/plugins/dex/python/method.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/dex/python/method.c')
-rw-r--r--plugins/dex/python/method.c223
1 files changed, 223 insertions, 0 deletions
diff --git a/plugins/dex/python/method.c b/plugins/dex/python/method.c
new file mode 100644
index 0000000..4f35e1a
--- /dev/null
+++ b/plugins/dex/python/method.c
@@ -0,0 +1,223 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * method.c - équivalent Python du fichier "plugins/dex/method.c"
+ *
+ * Copyright (C) 2018 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * Chrysalide is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Chrysalide is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "method.h"
+
+
+#include <pygobject.h>
+
+
+#include <plugins/pychrysalide/helpers.h>
+
+
+#include "translate.h"
+#include "../method.h"
+
+
+
+/* Fournit les indications Dex concernant la méthode. */
+static PyObject *py_dex_method_get_encoded(PyObject *, void *);
+
+/* Fournit les indications Dex relatives au corps de la méthode. */
+static PyObject *py_dex_method_get_code_item(PyObject *, void *);
+
+/* Fournit la routine Chrysalide correspondant à la méthode. */
+static PyObject *py_dex_method_get_routine(PyObject *, void *);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* closure = non utilisé ici. *
+* *
+* Description : Fournit les indications Dex concernant la méthode. *
+* *
+* Retour : Données brutes issues du binaire chargé. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_dex_method_get_encoded(PyObject *self, void *closure)
+{
+ PyObject *result; /* Valeur à retourner */
+ GDexMethod *method; /* Version native */
+ const encoded_method *info; /* Elément à traiter */
+
+ method = G_DEX_METHOD(pygobject_get(self));
+
+ info = g_dex_method_get_dex_info(method);
+
+ result = translate_dex_method_info_to_python(info);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* closure = non utilisé ici. *
+* *
+* Description : Fournit les indications Dex relatives au corps de la méthode.*
+* *
+* Retour : Données brutes du binaire, ou None si aucunes. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_dex_method_get_code_item(PyObject *self, void *closure)
+{
+ PyObject *result; /* Valeur à retourner */
+ GDexMethod *method; /* Version native */
+ const code_item *body; /* Elément à traiter */
+
+ method = G_DEX_METHOD(pygobject_get(self));
+
+ body = g_dex_method_get_dex_body(method);
+
+ result = translate_dex_method_body_to_python(body);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* closure = non utilisé ici. *
+* *
+* Description : Fournit la routine Chrysalide correspondant à la méthode. *
+* *
+* Retour : Instance de routine mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_dex_method_get_routine(PyObject *self, void *closure)
+{
+ PyObject *result; /* Valeur à retourner */
+ GDexMethod *method; /* Version native */
+ GBinRoutine *routine; /* Routine correspondante */
+
+ method = G_DEX_METHOD(pygobject_get(self));
+
+ routine = g_dex_method_get_routine(method);
+
+ result = pygobject_new(G_OBJECT(routine));
+
+ g_object_unref(G_OBJECT(routine));
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Fournit un accès à une définition de type à diffuser. *
+* *
+* Retour : Définition d'objet pour Python. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+PyTypeObject *get_python_dex_method_type(void)
+{
+ static PyMethodDef py_dex_method_methods[] = {
+ { NULL }
+ };
+
+ static PyGetSetDef py_dex_method_getseters[] = {
+ {
+ "encoded", py_dex_method_get_encoded, NULL,
+ "Encoded information about the Dex method.", NULL
+ },
+ {
+ "code_item", py_dex_method_get_code_item, NULL,
+ "Code information about the Dex method, None if none.", NULL
+ },
+ {
+ "routine", py_dex_method_get_routine, NULL,
+ "Chrysalide routine for the Dex method.", NULL
+ },
+ { NULL }
+ };
+
+ static PyTypeObject py_dex_method_type = {
+
+ PyVarObject_HEAD_INIT(NULL, 0)
+
+ .tp_name = "pychrysalide.format.dex.DexMethod",
+ .tp_basicsize = sizeof(PyGObject),
+
+ .tp_flags = Py_TPFLAGS_DEFAULT,
+
+ .tp_doc = "PyChrysalide Dex method.",
+
+ .tp_methods = py_dex_method_methods,
+ .tp_getset = py_dex_method_getseters
+
+ };
+
+ return &py_dex_method_type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide.format.dex.DexMethod'. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool register_python_dex_method(PyObject *module)
+{
+ PyTypeObject *py_dex_method_type; /* Type Python 'DexMethod' */
+ PyObject *dict; /* Dictionnaire du module */
+
+ py_dex_method_type = get_python_dex_method_type();
+
+ dict = PyModule_GetDict(module);
+
+ if (!register_class_for_pygobject(dict, G_TYPE_DEX_METHOD, py_dex_method_type, &PyGObject_Type))
+ return false;
+
+ return true;
+
+}