summaryrefslogtreecommitdiff
path: root/plugins/dex/python
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-04-14 21:04:32 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-04-14 21:04:32 (GMT)
commit627560def907ec62c38839457e6a018af27b6640 (patch)
treeb41b389c5b3505090cf648fba0160e7b80cd0f37 /plugins/dex/python
parent94fc32b6e4d985df049a33bd2c31f6932a1e292c (diff)
Provided a link to routines from Dex methods.
Diffstat (limited to 'plugins/dex/python')
-rw-r--r--plugins/dex/python/Makefile.am1
-rw-r--r--plugins/dex/python/module.c2
-rw-r--r--plugins/dex/python/routine.c204
-rw-r--r--plugins/dex/python/routine.h45
4 files changed, 252 insertions, 0 deletions
diff --git a/plugins/dex/python/Makefile.am b/plugins/dex/python/Makefile.am
index 2bf98bc..b371b87 100644
--- a/plugins/dex/python/Makefile.am
+++ b/plugins/dex/python/Makefile.am
@@ -8,6 +8,7 @@ libdexpython_la_SOURCES = \
format.h format.c \
method.h method.c \
module.h module.c \
+ routine.h routine.c \
translate.h translate.c
libdexpython_la_LDFLAGS =
diff --git a/plugins/dex/python/module.c b/plugins/dex/python/module.c
index aedbc0f..007b794 100644
--- a/plugins/dex/python/module.c
+++ b/plugins/dex/python/module.c
@@ -36,6 +36,7 @@
#include "field.h"
#include "format.h"
#include "method.h"
+#include "routine.h"
@@ -80,6 +81,7 @@ bool add_format_dex_module_to_python_module(void)
if (result) result = register_python_dex_field(module);
if (result) result = register_python_dex_format(module);
if (result) result = register_python_dex_method(module);
+ if (result) result = register_python_dex_routine(module);
assert(result);
diff --git a/plugins/dex/python/routine.c b/plugins/dex/python/routine.c
new file mode 100644
index 0000000..ef85cc7
--- /dev/null
+++ b/plugins/dex/python/routine.c
@@ -0,0 +1,204 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * routine.c - équivalent Python du fichier "plugins/dex/routine.c"
+ *
+ * Copyright (C) 2019 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 "routine.h"
+
+
+#include <pygobject.h>
+
+
+#include <plugins/pychrysalide/helpers.h>
+#include <plugins/pychrysalide/analysis/routine.h>
+
+
+#include "../routine.h"
+
+
+
+/* Fournit la méthode liée à une routine d'origine Dex. */
+static PyObject *py_dex_routine_get_method(PyObject *, void *);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* closure = non utilisé ici. *
+* *
+* Description : Fournit la méthode liée à une routine d'origine Dex. *
+* *
+* Retour : Méthode Dex liée à la routine ou None. *
+* *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_dex_routine_get_method(PyObject *self, void *closure)
+{
+ PyObject *result; /* Valeur à retourner */
+ GDexRoutine *routine; /* Version native */
+ GDexMethod *method; /* Méthode correspondante */
+
+ routine = G_DEX_ROUTINE(pygobject_get(self));
+
+ method = g_dex_routine_get_method(routine);
+
+ if (method != NULL)
+ {
+ result = pygobject_new(G_OBJECT(method));
+
+ g_object_unref(G_OBJECT(method));
+
+ }
+ else
+ {
+ result = Py_None;
+ Py_INCREF(result);
+ }
+
+ 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_routine_type(void)
+{
+ static PyMethodDef py_dex_routine_methods[] = {
+ { NULL }
+ };
+
+ static PyGetSetDef py_dex_routine_getseters[] = {
+ {
+ "method", py_dex_routine_get_method, NULL,
+ "Dex method attached to the Dex routine.", NULL
+ },
+ { NULL }
+ };
+
+ static PyTypeObject py_dex_routine_type = {
+
+ PyVarObject_HEAD_INIT(NULL, 0)
+
+ .tp_name = "pychrysalide.format.dex.DexRoutine",
+ .tp_basicsize = sizeof(PyGObject),
+
+ .tp_flags = Py_TPFLAGS_DEFAULT,
+
+ .tp_doc = "PyChrysalide Dex routine.",
+
+ .tp_methods = py_dex_routine_methods,
+ .tp_getset = py_dex_routine_getseters
+
+ };
+
+ return &py_dex_routine_type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide.format.dex.DexRoutine'.*
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool register_python_dex_routine(PyObject *module)
+{
+ PyTypeObject *type; /* Type Python 'DexRoutine' */
+ PyObject *dict; /* Dictionnaire du module */
+
+ type = get_python_dex_routine_type();
+
+ dict = PyModule_GetDict(module);
+
+ if (!register_class_for_pygobject(dict, G_TYPE_DEX_ROUTINE, type, get_python_binary_routine_type()))
+ return false;
+
+ return true;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : arg = argument quelconque à tenter de convertir. *
+* dst = destination des valeurs récupérées en cas de succès. *
+* *
+* Description : Tente de convertir en routine de fichier Dex. *
+* *
+* Retour : Bilan de l'opération, voire indications supplémentaires. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int convert_to_dex_routine(PyObject *arg, void *dst)
+{
+ int result; /* Bilan à retourner */
+
+ result = PyObject_IsInstance(arg, (PyObject *)get_python_dex_routine_type());
+
+ switch (result)
+ {
+ case -1:
+ /* L'exception est déjà fixée par Python */
+ result = 0;
+ break;
+
+ case 0:
+ PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to dex routine");
+ break;
+
+ case 1:
+ *((GDexRoutine **)dst) = G_DEX_ROUTINE(pygobject_get(arg));
+ break;
+
+ default:
+ assert(false);
+ break;
+
+ }
+
+ return result;
+
+}
diff --git a/plugins/dex/python/routine.h b/plugins/dex/python/routine.h
new file mode 100644
index 0000000..7653731
--- /dev/null
+++ b/plugins/dex/python/routine.h
@@ -0,0 +1,45 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * routine.h - prototypes pour l'équivalent Python du fichier "plugins/dex/routine.h"
+ *
+ * Copyright (C) 2019 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
+ */
+
+
+#ifndef _PLUGINS_DEX_PYTHON_ROUTINE_H
+#define _PLUGINS_DEX_PYTHON_ROUTINE_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+
+
+/* Fournit un accès à une définition de type à diffuser. */
+PyTypeObject *get_python_dex_routine_type(void);
+
+/* Prend en charge l'objet 'pychrysalide.format.dex.DexRoutine'. */
+bool register_python_dex_routine(PyObject *module);
+
+/* Tente de convertir en routine de fichier Dex. */
+int convert_to_dex_routine(PyObject *, void *);
+
+
+
+#endif /* _PLUGINS_DEX_PYTHON_ROUTINE_H */