diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2019-05-07 21:53:40 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2019-05-07 21:53:40 (GMT) |
commit | dd2b41538e20de5472cd8c888c530327a1351866 (patch) | |
tree | 7f9a24a32ecd33aacb98a5d1ec4234011c1364a6 /plugins/dex/python/format.c | |
parent | b92a5e56de9198c08956ce486cd12712d7034731 (diff) |
Read raw Dex items by extending the API.
Diffstat (limited to 'plugins/dex/python/format.c')
-rw-r--r-- | plugins/dex/python/format.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/plugins/dex/python/format.c b/plugins/dex/python/format.c index 77ebef6..9bbbfbd 100644 --- a/plugins/dex/python/format.c +++ b/plugins/dex/python/format.c @@ -37,7 +37,9 @@ #include "constants.h" +#include "translate.h" #include "../class.h" +#include "../dex-int.h" #include "../format.h" @@ -98,6 +100,78 @@ static PyObject *py_dex_format_new(PyTypeObject *type, PyObject *args, PyObject /****************************************************************************** * * +* Paramètres : self = objet représentant un format de fichier Dex. * +* args = arguments fournis pour l'opération. * +* * +* Description : Procède à la lecture d'une liste de types DEX. * +* * +* Retour : Instance mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_dex_format_read_type_list(PyObject *self, PyObject *args) +{ + PyObject *result; /* Bilan à retourner */ + unsigned int offset; /* Position de l'élément visé */ + int ret; /* Bilan de lecture des args. */ + GDexFormat *format; /* Format de fichier Dex */ + vmpa2t addr; /* Tête de lecture générique */ + type_list list; /* Elément à transmettre */ + bool status; /* Bilan de l'opération */ + uint32_t i; /* Boucle de parcours */ + +#define DEX_POOL_READ_TYPE_LIST_METHOD PYTHON_METHOD_DEF \ +( \ + "read_type_list", "$self, offset, /", \ + METH_VARARGS, py_dex_format_read_type_list, \ + "Provide the raw data of a given type list as an array of pychrysalide.PyStructObject" \ + " instances." \ + "\n" \ + "All the items are fields extracted from the Dex *type_list* structure:\n" \ + "* type_idx: index into the *type_ids* list.\n" \ + "\n" \ + "In case of error, the function returns None." \ +) + + ret = PyArg_ParseTuple(args, "I", &offset); + if (!ret) return NULL; + + format = G_DEX_FORMAT(pygobject_get(self)); + + init_vmpa(&addr, offset, VMPA_NO_VIRTUAL); + + status = read_dex_type_list(format, &addr, &list); + + if (status) + { + result = PyTuple_New(list.size); + + for (i = 0; i < list.size; i++) + { +#ifndef NDEBUG + ret = PyTuple_SetItem(result, i, translate_dex_type_item_to_python(&list.list[i])); + assert(ret == 0); +#else + PyTuple_SetItem(result, i, translate_dex_type_item_to_python(&list.list[i])); +#endif + } + + } + else + { + result = Py_None; + Py_INCREF(result); + } + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : self = objet Python concerné par l'appel. * * closure = non utilisé ici. * * * @@ -149,6 +223,7 @@ static PyObject *py_dex_format_get_pool(PyObject *self, void *closure) PyTypeObject *get_python_dex_format_type(void) { static PyMethodDef py_dex_format_methods[] = { + DEX_POOL_READ_TYPE_LIST_METHOD, { NULL } }; |