diff options
Diffstat (limited to 'plugins/pychrysa/format/format.c')
-rw-r--r-- | plugins/pychrysa/format/format.c | 65 |
1 files changed, 43 insertions, 22 deletions
diff --git a/plugins/pychrysa/format/format.c b/plugins/pychrysa/format/format.c index ea556ba..4032da0 100644 --- a/plugins/pychrysa/format/format.c +++ b/plugins/pychrysa/format/format.c @@ -28,6 +28,9 @@ #include <pygobject.h> +#include <format/format.h> + + #include "dex/dex.h" #include "../quirks.h" @@ -36,6 +39,9 @@ /* Crée un nouvel objet Python de type 'BinFormat'. */ static PyObject *py_binary_format_new(PyTypeObject *, PyObject *, PyObject *); +/* Recherche une position dans une routine selon une adresse. */ +static PyObject *py_binary_format_resolve_relative_routine(PyObject *, PyObject *); + /****************************************************************************** @@ -54,43 +60,53 @@ static PyObject *py_binary_format_new(PyTypeObject *, PyObject *, PyObject *); static PyObject *py_binary_format_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { - return Py_None; + Py_RETURN_NONE; } + + + + + /****************************************************************************** * * -* Paramètres : format = instance existante GLib. * +* Paramètres : self = classe représentant un binaire. * +* args = arguments fournis à l'appel. * * * -* Description : Crée un nouvel objet Python de type 'BinFormat'. * +* Description : Recherche une position dans une routine selon une adresse. * * * -* Retour : Instance Python mise en place. * +* Retour : Tuple (nom, décallage) ou Py_None. * * * * Remarques : - * * * ******************************************************************************/ -PyObject *py_binary_format_from_c(GBinFormat *format) +static PyObject *py_binary_format_resolve_relative_routine(PyObject *self, PyObject *args) { - PyObject *result; /* Conversion à retourner */ - GType type; /* Type réel du format */ + PyObject *result; /* Tuple à retourner */ + GBinFormat *format; /* Format à manipuler */ + vmpa_t addr; /* Adresse demandée en visuel */ + int ret; /* Bilan de lecture des args. */ + bool found; /* Bilan de la résolution */ + const char *label; /* Désignation de la trouvaille*/ - type = G_OBJECT_TYPE(G_OBJECT(format)); - - if (type == G_TYPE_DEX_FORMAT) - result = py_dex_format_from_c(G_DEX_FORMAT(format)); - else - result = Py_None; - - return result; - -} + format = G_BIN_FORMAT(pygobject_get(self)); + ret = PyArg_ParseTuple(args, "K", &addr); + if (!ret) Py_RETURN_NONE; + found = g_binary_format_resolve_relative_routine(format, &label, &addr); + if (!found) Py_RETURN_NONE; + result = PyTuple_New(2); + PyTuple_SetItem(result, 0, PyString_FromString(label)); + PyTuple_SetItem(result, 1, PyLong_FromLongLong(addr)); + return result; +} @@ -114,10 +130,15 @@ PyObject *py_binary_format_from_c(GBinFormat *format) bool register_python_binary_format(PyObject *module) { - PyObject *pygobj_mod; /* Module Python-GObject */ + PyObject *parent_mod; /* Module Python-GObject */ int ret; /* Bilan d'un appel */ static PyMethodDef py_binary_format_methods[] = { + { + "resolve_relative_routine", (PyCFunction)py_binary_format_resolve_relative_routine, + METH_VARARGS, + "Search a position inside a routine by a given address." + }, { NULL } }; @@ -142,11 +163,11 @@ bool register_python_binary_format(PyObject *module) }; - pygobj_mod = PyImport_ImportModule("gobject"); - if (pygobj_mod == NULL) return false; + parent_mod = PyImport_ImportModule("gobject"); + if (parent_mod == NULL) return false; - py_binary_format_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(pygobj_mod, "GObject"); - Py_DECREF(pygobj_mod); + py_binary_format_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(parent_mod, "GObject"); + Py_DECREF(parent_mod); if (PyType_Ready(&py_binary_format_type) < 0) return false; |