diff options
Diffstat (limited to 'plugins/dex/python/pool.c')
| -rw-r--r-- | plugins/dex/python/pool.c | 330 | 
1 files changed, 330 insertions, 0 deletions
| diff --git a/plugins/dex/python/pool.c b/plugins/dex/python/pool.c index eae1e86..695e07f 100644 --- a/plugins/dex/python/pool.c +++ b/plugins/dex/python/pool.c @@ -36,6 +36,21 @@ +/* Reconstitue les éléments bruts d'un type Dex. */ +static PyObject *py_dex_pool_get_raw_type(PyObject *, PyObject *); + +/* Reconstitue les éléments bruts d'un champ Dex. */ +static PyObject *py_dex_pool_get_raw_field(PyObject *, PyObject *); + +/* Reconstitue les éléments bruts d'une routine Dex. */ +static PyObject *py_dex_pool_get_raw_prototype(PyObject *, PyObject *); + +/* Reconstitue les éléments bruts d'une méthode Dex. */ +static PyObject *py_dex_pool_get_raw_method(PyObject *, PyObject *); + +/* Reconstitue les éléments bruts d'une classe Dex. */ +static PyObject *py_dex_pool_get_raw_class(PyObject *, PyObject *); +  /* Fournit la liste de toutes les chaînes de la table globale. */  static PyObject *py_dex_pool_get_strings(PyObject *, void *); @@ -65,6 +80,316 @@ static PyObject *py_dex_pool_get_classes(PyObject *, void *);  /******************************************************************************  *                                                                             * +*  Paramètres  : self = objet représentant une table de ressources Dex.       * +*                args = arguments fournis pour l'opération.                   * +*                                                                             * +*  Description : Reconstitue les éléments bruts d'un type Dex.                * +*                                                                             * +*  Retour      : Instance mise en place.                                      * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static PyObject *py_dex_pool_get_raw_type(PyObject *self, PyObject *args) +{ +    PyObject *result;                       /* Bilan à retourner           */ +    unsigned int index;                     /* Indice de l'élément visé    */ +    int ret;                                /* Bilan de lecture des args.  */ +    GDexPool *pool;                         /* Table de ressources Dex     */ +    type_id_item type_id;                 /* Elément à transmettre       */ +    bool status;                            /* Bilan de l'opération        */ + +#define DEX_POOL_GET_RAW_TYPE_METHOD PYTHON_METHOD_DEF                                          \ +(                                                                                               \ +    "get_raw_type", "$self, index, /",                                                          \ +    METH_VARARGS, py_dex_pool_get_raw_type,                                                     \ +    "Provide the raw data of a given type in the Dex pool as a pychrysalide.PyStructObject"     \ +    " instance."                                                                                \ +    "\n"                                                                                        \ +    "Indexes start at 0.\n"                                                                     \ +    "\n"                                                                                        \ +    "All the fields are extracted from the Dex *type_id_item* structure:\n"                     \ +    "* descriptor_idx: index into the string_ids list for the descriptor string.\n"             \ +    "\n"                                                                                        \ +    "In case of error, the function returns None."                                              \ +) + +    ret = PyArg_ParseTuple(args, "I", &index); +    if (!ret) return NULL; + +    pool = G_DEX_POOL(pygobject_get(self)); + +    status = g_dex_pool_get_raw_type(pool, index, &type_id); + +    if (status) +        result = translate_dex_type_id_to_python(&type_id); + +    else +    { +        result = Py_None; +        Py_INCREF(result); +    } + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : self = objet représentant une table de ressources Dex.       * +*                args = arguments fournis pour l'opération.                   * +*                                                                             * +*  Description : Reconstitue les éléments bruts d'un champ Dex.               * +*                                                                             * +*  Retour      : Instance mise en place.                                      * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static PyObject *py_dex_pool_get_raw_field(PyObject *self, PyObject *args) +{ +    PyObject *result;                       /* Bilan à retourner           */ +    unsigned int index;                     /* Indice de l'élément visé    */ +    int ret;                                /* Bilan de lecture des args.  */ +    GDexPool *pool;                         /* Table de ressources Dex     */ +    field_id_item field_id;                 /* Elément à transmettre       */ +    bool status;                            /* Bilan de l'opération        */ + +#define DEX_POOL_GET_RAW_FIELD_METHOD PYTHON_METHOD_DEF                                         \ +(                                                                                               \ +    "get_raw_field", "$self, index, /",                                                         \ +    METH_VARARGS, py_dex_pool_get_raw_field,                                                    \ +    "Provide the raw data of a given field in the Dex pool as a pychrysalide.PyStructObject"    \ +    " instance."                                                                                \ +    "\n"                                                                                        \ +    "Indexes start at 0.\n"                                                                     \ +    "\n"                                                                                        \ +    "All the fields are extracted from the Dex *field_id_item* structure:\n"                    \ +    "* class_idx: index into the type_ids list for the definer of the field ;\n"                \ +    "* type_idx: index into the type_ids list for the type of the field ;\n"                    \ +    "* name_idx: index into the string_ids list for the name of the field.\n"                   \ +    "\n"                                                                                        \ +    "In case of error, the function returns None."                                              \ +) + +    ret = PyArg_ParseTuple(args, "I", &index); +    if (!ret) return NULL; + +    pool = G_DEX_POOL(pygobject_get(self)); + +    status = g_dex_pool_get_raw_field(pool, index, &field_id); + +    if (status) +        result = translate_dex_field_id_to_python(&field_id); + +    else +    { +        result = Py_None; +        Py_INCREF(result); +    } + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : self = objet représentant une table de ressources Dex.       * +*                args = arguments fournis pour l'opération.                   * +*                                                                             * +*  Description : Reconstitue les éléments bruts d'une routine Dex.            * +*                                                                             * +*  Retour      : Instance mise en place.                                      * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static PyObject *py_dex_pool_get_raw_prototype(PyObject *self, PyObject *args) +{ +    PyObject *result;                       /* Bilan à retourner           */ +    unsigned int index;                     /* Indice de l'élément visé    */ +    int ret;                                /* Bilan de lecture des args.  */ +    GDexPool *pool;                         /* Table de ressources Dex     */ +    proto_id_item proto_id;                 /* Elément à transmettre       */ +    bool status;                            /* Bilan de l'opération        */ + +#define DEX_POOL_GET_RAW_PROTOTYPE_METHOD PYTHON_METHOD_DEF                                         \ +(                                                                                                   \ +    "get_raw_prototype", "$self, index, /",                                                         \ +    METH_VARARGS, py_dex_pool_get_raw_prototype,                                                    \ +    "Provide the raw data of a given prototype in the Dex pool as a pychrysalide.PyStructObject"    \ +    " instance."                                                                                    \ +    "\n"                                                                                            \ +    "Indexes start at 0.\n"                                                                         \ +    "\n"                                                                                            \ +    "All the fields are extracted from the Dex *proto_id_item* structure:\n"                        \ +    "* shorty_idx: index into the *string_ids* list for the short-form descriptor string ;\n"       \ +    "* return_type_idx: index into the *type_ids* list for the return type ;\n"                     \ +    "* parameters_off: offset from the start of the Dex file to the list of parameter types."       \ +    "\n"                                                                                            \ +    "In case of error, the function returns None."                                                  \ +) + +    ret = PyArg_ParseTuple(args, "I", &index); +    if (!ret) return NULL; + +    pool = G_DEX_POOL(pygobject_get(self)); + +    status = g_dex_pool_get_raw_prototype(pool, index, &proto_id); + +    if (status) +        result = translate_dex_proto_id_to_python(&proto_id); + +    else +    { +        result = Py_None; +        Py_INCREF(result); +    } + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : self = objet représentant une table de ressources Dex.       * +*                args = arguments fournis pour l'opération.                   * +*                                                                             * +*  Description : Reconstitue les éléments bruts d'une méthode Dex.            * +*                                                                             * +*  Retour      : Instance mise en place.                                      * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static PyObject *py_dex_pool_get_raw_method(PyObject *self, PyObject *args) +{ +    PyObject *result;                       /* Bilan à retourner           */ +    unsigned int index;                     /* Indice de l'élément visé    */ +    int ret;                                /* Bilan de lecture des args.  */ +    GDexPool *pool;                         /* Table de ressources Dex     */ +    method_id_item method_id;                 /* Elément à transmettre       */ +    bool status;                            /* Bilan de l'opération        */ + +#define DEX_POOL_GET_RAW_METHOD_METHOD PYTHON_METHOD_DEF                                        \ +(                                                                                               \ +    "get_raw_method", "$self, index, /",                                                        \ +    METH_VARARGS, py_dex_pool_get_raw_method,                                                   \ +    "Provide the raw data of a given method in the Dex pool as a pychrysalide.PyStructObject"   \ +    " instance."                                                                                \ +    "\n"                                                                                        \ +    "Indexes start at 0.\n"                                                                     \ +    "\n"                                                                                        \ +    "All the fields are extracted from the Dex *method_id_item* structure:\n"                   \ +    "* class_idx: index into the type_ids list for the definer of the method ;\n"               \ +    "* proto_idx: index into the proto_ids list for the prototype of the method ;\n"            \ +    "* name_idx: index into the string_ids list for the name of the method.\n"                  \ +    "\n"                                                                                        \ +    "In case of error, the function returns None."                                              \ +) + +    ret = PyArg_ParseTuple(args, "I", &index); +    if (!ret) return NULL; + +    pool = G_DEX_POOL(pygobject_get(self)); + +    status = g_dex_pool_get_raw_method(pool, index, &method_id); + +    if (status) +        result = translate_dex_method_id_to_python(&method_id); + +    else +    { +        result = Py_None; +        Py_INCREF(result); +    } + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : self = objet représentant une table de ressources Dex.       * +*                args = arguments fournis pour l'opération.                   * +*                                                                             * +*  Description : Reconstitue les éléments bruts d'une classe Dex.             * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static PyObject *py_dex_pool_get_raw_class(PyObject *self, PyObject *args) +{ +    PyObject *result;                       /* Bilan à retourner           */ +    unsigned int index;                     /* Indice de l'élément visé    */ +    int ret;                                /* Bilan de lecture des args.  */ +    GDexPool *pool;                         /* Table de ressources Dex     */ +    class_def_item class_def;               /* Elément à transmettre       */ +    bool status;                            /* Bilan de l'opération        */ + +#define DEX_POOL_GET_RAW_CLASS_METHOD PYTHON_METHOD_DEF                                         \ +(                                                                                               \ +    "get_raw_class", "$self, index, /",                                                         \ +    METH_VARARGS, py_dex_pool_get_raw_class,                                                    \ +    "Provide the raw data of a given class in the Dex pool as a pychrysalide.PyStructObject"    \ +    " instance."                                                                                \ +    "\n"                                                                                        \ +    "Indexes start at 0.\n"                                                                     \ +    "\n"                                                                                        \ +    "All the fields are extracted from the Dex *class_def_item* structure:\n"                   \ +    "* class_idx: index into the type_ids list for this class ;\n"                              \ +    "* access_flags: access flags for the class (public, final, etc.) ;\n"                      \ +    "* superclass_idx: index into the type_ids list for the superclass, or the constant value"  \ +    " NO_INDEX if the class has no superclass ;\n"                                              \ +    "* interfaces_off: offset from the start of the file to the list of interfaces, or 0"       \ +    " if there are none ;\n"                                                                    \ +    "* source_file_idx: index into the string_ids list for the name of the file containing"     \ +    " the original source for (at least most of) this class, or the special value NO_INDEX to"  \ +    " represent a lack of this information ;\n"                                                 \ +    "* annotations_off: offset from the start of the file to the annotations structure, or 0"   \ +    " if there are no annotation ;\n"                                                           \ +    "* class_data_off: offset from the start of the file to the associated class data, or 0"    \ +    " if there is no class data ;\n"                                                            \ +    "* static_values_off: offset from the start of the file to the list of initial values"      \ +    " for static fields, or 0 if there are none.\n"                                             \ +    "\n"                                                                                        \ +    "In case of error, the function returns None."                                              \ +) + +    ret = PyArg_ParseTuple(args, "I", &index); +    if (!ret) return NULL; + +    pool = G_DEX_POOL(pygobject_get(self)); + +    status = g_dex_pool_get_raw_class(pool, index, &class_def); + +    if (status) +        result = translate_dex_class_definition_to_python(&class_def); + +    else +    { +        result = Py_None; +        Py_INCREF(result); +    } + +    return result; + +} + + +/****************************************************************************** +*                                                                             *  *  Paramètres  : self    = objet Python concerné par l'appel.                 *  *                closure = non utilisé ici.                                   *  *                                                                             * @@ -437,6 +762,11 @@ static PyObject *py_dex_pool_get_classes(PyObject *self, void *closure)  PyTypeObject *get_python_dex_pool_type(void)  {      static PyMethodDef py_dex_pool_methods[] = { +        DEX_POOL_GET_RAW_TYPE_METHOD, +        DEX_POOL_GET_RAW_FIELD_METHOD, +        DEX_POOL_GET_RAW_PROTOTYPE_METHOD, +        DEX_POOL_GET_RAW_METHOD_METHOD, +        DEX_POOL_GET_RAW_CLASS_METHOD,          { NULL }      }; | 
