diff options
Diffstat (limited to 'plugins/elf/python')
| -rw-r--r-- | plugins/elf/python/Makefile.am | 1 | ||||
| -rw-r--r-- | plugins/elf/python/constants.c | 6 | ||||
| -rw-r--r-- | plugins/elf/python/dynamic.c | 46 | ||||
| -rw-r--r-- | plugins/elf/python/dynamic.h | 3 | ||||
| -rw-r--r-- | plugins/elf/python/elf_def.c | 195 | ||||
| -rw-r--r-- | plugins/elf/python/elf_def.h | 53 | ||||
| -rw-r--r-- | plugins/elf/python/format.c | 30 | ||||
| -rw-r--r-- | plugins/elf/python/program.c | 2 | ||||
| -rw-r--r-- | plugins/elf/python/section.c | 2 | 
9 files changed, 335 insertions, 3 deletions
| diff --git a/plugins/elf/python/Makefile.am b/plugins/elf/python/Makefile.am index 6080e86..ce2fe74 100644 --- a/plugins/elf/python/Makefile.am +++ b/plugins/elf/python/Makefile.am @@ -4,6 +4,7 @@ noinst_LTLIBRARIES = libelfpython.la  libelfpython_la_SOURCES =				\  	constants.h constants.c				\  	dynamic.h dynamic.c					\ +	elf_def.h elf_def.c					\  	format.h format.c					\  	module.h module.c					\  	program.h program.c					\ diff --git a/plugins/elf/python/constants.c b/plugins/elf/python/constants.c index 1e92616..098443c 100644 --- a/plugins/elf/python/constants.c +++ b/plugins/elf/python/constants.c @@ -62,10 +62,16 @@ static bool define_python_binary_format_common_constants(PyTypeObject *obj_type)      /* Composition du champ e_ident */ +    if (result) result = PyDict_AddIntMacro(obj_type, EI_MAG0); +    if (result) result = PyDict_AddIntMacro(obj_type, EI_MAG1); +    if (result) result = PyDict_AddIntMacro(obj_type, EI_MAG2); +    if (result) result = PyDict_AddIntMacro(obj_type, EI_MAG3);      if (result) result = PyDict_AddIntMacro(obj_type, EI_CLASS);      if (result) result = PyDict_AddIntMacro(obj_type, EI_DATA);      if (result) result = PyDict_AddIntMacro(obj_type, EI_VERSION);      if (result) result = PyDict_AddIntMacro(obj_type, EI_OSABI); +    if (result) result = PyDict_AddIntMacro(obj_type, EI_ABIVERSION); +    if (result) result = PyDict_AddIntMacro(obj_type, EI_PAD);      /* ... EI_CLASS */ diff --git a/plugins/elf/python/dynamic.c b/plugins/elf/python/dynamic.c index 5c060c1..9fe6eb4 100644 --- a/plugins/elf/python/dynamic.c +++ b/plugins/elf/python/dynamic.c @@ -1,6 +1,6 @@  /* Chrysalide - Outil d'analyse de fichiers binaires - * dynamic.c - prototypes pour l'équivalent Python du fichier "plugins/elf/dynamic.c" + * dynamic.c - équivalent Python du fichier "plugins/elf/dynamic.c"   *   * Copyright (C) 2017 Cyrille Bagard   * @@ -29,12 +29,56 @@  #include <pygobject.h> +#include "translate.h"  #include "../dynamic.h"  /******************************************************************************  *                                                                             * +*  Paramètres  : self = format Elf à manipuler.                               * +*                args = indice de la section visée.                           * +*                                                                             * +*  Description : Retrouve un élément dans la section dynamique par son indice.* +*                                                                             * +*  Retour      : Elément trouvé ou rien (None).                               * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +PyObject *py_elf_format_find_dynamic_item_by_index(PyObject *self, PyObject *args) +{ +    PyObject *result;                       /* Trouvaille à retourner      */ +    GElfFormat *format;                     /* Version GLib du format      */ +    unsigned long index;                    /* Indice de l'élément visé    */ +    int ret;                                /* Bilan de lecture des args.  */ +    elf_dyn item;                           /* Informations remontées      */ +    bool found;                             /* Recherches concluantes ?    */ + +    format = G_ELF_FORMAT(pygobject_get(self)); + +    ret = PyArg_ParseTuple(args, "k", &index); +    if (!ret) return NULL; + +    found = find_elf_dynamic_item_by_index(format, index, &item); + +    if (found) +        result = translate_elf_dyn_to_python(format, &item); + +    else +    { +        result = Py_None; +        Py_INCREF(result); +    } + +    return result; + +} + + +/****************************************************************************** +*                                                                             *  *  Paramètres  : self    = classe représentant un format ELF.                 *  *                closure = adresse non utilisée ici.                          *  *                                                                             * diff --git a/plugins/elf/python/dynamic.h b/plugins/elf/python/dynamic.h index b1c4008..4ef2936 100644 --- a/plugins/elf/python/dynamic.h +++ b/plugins/elf/python/dynamic.h @@ -30,6 +30,9 @@ +/* Retrouve un élément dans la section dynamique par son indice. */ +PyObject *py_elf_format_find_dynamic_item_by_index(PyObject *, PyObject *); +  /* Fournit la liste des objets partagés requis. */  PyObject *py_elf_format_get_needed(PyObject *, void *); diff --git a/plugins/elf/python/elf_def.c b/plugins/elf/python/elf_def.c new file mode 100644 index 0000000..0721020 --- /dev/null +++ b/plugins/elf/python/elf_def.c @@ -0,0 +1,195 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * elf_def.c - équivalent Python du fichier "plugins/elf/elf_def.c" + * + * Copyright (C) 2017 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 "elf_def.h" + + +#include <pygobject.h> + + +#include "../elf_def.h" +#include "../elf-int.h" + + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : self    = classe représentant un format ELF.                 * +*                closure = adresse non utilisée ici.                          * +*                                                                             * +*  Description : Indique la taille d'un entête ELF.                           * +*                                                                             * +*  Retour      : Taille d'une structure ELF adaptée à l'architecture.         * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +PyObject *py_elf_format_get_sizeof_hdr(PyObject *self, void *closure) +{ +    PyObject *result;                       /* Liste éventuelle à renvoyer */ +    GElfFormat *format;                     /* Version native              */ + +    format = G_ELF_FORMAT(pygobject_get(self)); + +    result = PyLong_FromSize_t(ELF_SIZEOF_HDR(format)); + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : self    = classe représentant un format ELF.                 * +*                closure = adresse non utilisée ici.                          * +*                                                                             * +*  Description : Indique la taille d'un entête de programme ELF.              * +*                                                                             * +*  Retour      : Taille d'une structure ELF adaptée à l'architecture.         * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +PyObject *py_elf_format_get_sizeof_phdr(PyObject *self, void *closure) +{ +    PyObject *result;                       /* Liste éventuelle à renvoyer */ +    GElfFormat *format;                     /* Version native              */ + +    format = G_ELF_FORMAT(pygobject_get(self)); + +    result = PyLong_FromSize_t(ELF_SIZEOF_PHDR(format)); + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : self    = classe représentant un format ELF.                 * +*                closure = adresse non utilisée ici.                          * +*                                                                             * +*  Description : Indique la taille d'un entête de section ELF.                * +*                                                                             * +*  Retour      : Taille d'une structure ELF adaptée à l'architecture.         * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +PyObject *py_elf_format_get_sizeof_shdr(PyObject *self, void *closure) +{ +    PyObject *result;                       /* Liste éventuelle à renvoyer */ +    GElfFormat *format;                     /* Version native              */ + +    format = G_ELF_FORMAT(pygobject_get(self)); + +    result = PyLong_FromSize_t(ELF_SIZEOF_SHDR(format)); + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : self    = classe représentant un format ELF.                 * +*                closure = adresse non utilisée ici.                          * +*                                                                             * +*  Description : Indique la taille d'une entité dynamique de format ELF.      * +*                                                                             * +*  Retour      : Taille d'une structure ELF adaptée à l'architecture.         * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +PyObject *py_elf_format_get_sizeof_dyn(PyObject *self, void *closure) +{ +    PyObject *result;                       /* Liste éventuelle à renvoyer */ +    GElfFormat *format;                     /* Version native              */ + +    format = G_ELF_FORMAT(pygobject_get(self)); + +    result = PyLong_FromSize_t(ELF_SIZEOF_DYN(format)); + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : self    = classe représentant un format ELF.                 * +*                closure = adresse non utilisée ici.                          * +*                                                                             * +*  Description : Indique la taille d'une information sur un symbole ELF.      * +*                                                                             * +*  Retour      : Taille d'une structure ELF adaptée à l'architecture.         * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +PyObject *py_elf_format_get_sizeof_sym(PyObject *self, void *closure) +{ +    PyObject *result;                       /* Liste éventuelle à renvoyer */ +    GElfFormat *format;                     /* Version native              */ + +    format = G_ELF_FORMAT(pygobject_get(self)); + +    result = PyLong_FromSize_t(ELF_SIZEOF_SYM(format)); + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : self    = classe représentant un format ELF.                 * +*                closure = adresse non utilisée ici.                          * +*                                                                             * +*  Description : Indique la taille d'une information de relocalisation ELF.   * +*                                                                             * +*  Retour      : Taille d'une structure ELF adaptée à l'architecture.         * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +PyObject *py_elf_format_get_sizeof_rel(PyObject *self, void *closure) +{ +    PyObject *result;                       /* Liste éventuelle à renvoyer */ +    GElfFormat *format;                     /* Version native              */ + +    format = G_ELF_FORMAT(pygobject_get(self)); + +    result = PyLong_FromSize_t(ELF_SIZEOF_REL(format)); + +    return result; + +} diff --git a/plugins/elf/python/elf_def.h b/plugins/elf/python/elf_def.h new file mode 100644 index 0000000..134dd13 --- /dev/null +++ b/plugins/elf/python/elf_def.h @@ -0,0 +1,53 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * elf_def.h - prototypes pour l'équivalent Python du fichier "plugins/elf/elf_def.h" + * + * 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 + */ + + +#ifndef _PLUGINS_ELF_PYTHON_ELF_DEF_H +#define _PLUGINS_ELF_PYTHON_ELF_DEF_H + + +#include <Python.h> + + + +/* Indique la taille d'un entête ELF. */ +PyObject *py_elf_format_get_sizeof_hdr(PyObject *, void *); + +/* Indique la taille d'un entête de programme ELF. */ +PyObject *py_elf_format_get_sizeof_phdr(PyObject *, void *); + +/* Indique la taille d'un entête de section ELF. */ +PyObject *py_elf_format_get_sizeof_shdr(PyObject *, void *); + +/* Indique la taille d'une entité dynamique de format ELF. */ +PyObject *py_elf_format_get_sizeof_dyn(PyObject *, void *); + +/* Indique la taille d'une information sur un symbole ELF. */ +PyObject *py_elf_format_get_sizeof_sym(PyObject *, void *); + +/* Indique la taille d'une information de relocalisation ELF. */ +PyObject *py_elf_format_get_sizeof_rel(PyObject *, void *); + + + +#endif  /* _PLUGINS_ELF_PYTHON_ELF_DEF_H */ diff --git a/plugins/elf/python/format.c b/plugins/elf/python/format.c index 6b44703..a3d8758 100644 --- a/plugins/elf/python/format.c +++ b/plugins/elf/python/format.c @@ -38,6 +38,7 @@  #include "constants.h"  #include "dynamic.h" +#include "elf_def.h"  #include "program.h"  #include "section.h"  #include "translate.h" @@ -219,11 +220,40 @@ PyTypeObject *get_python_elf_format_type(void)              METH_VARARGS,              "find_sections_by_type($self, type, /)\n--\n\nFind sections using a given type."          }, +        { +            "find_dynamic_item_by_index", py_elf_format_find_dynamic_item_by_index, +            METH_VARARGS, +            "find_dynamic_item_by_type($self, type, /)\n--\n\nFind an item from the dynamic segment using a given index." +        },          { NULL }      };      static PyGetSetDef py_elf_format_getseters[] = {          { +            "sizeof_hdr", py_elf_format_get_sizeof_hdr, NULL, +            "Provide the size of Elf_Ehdr structures for the loaded format.", NULL +        }, +        { +            "sizeof_phdr", py_elf_format_get_sizeof_phdr, NULL, +            "Provide the size of Elf_Phdr structures for the loaded format.", NULL +        }, +        { +            "sizeof_shdr", py_elf_format_get_sizeof_shdr, NULL, +            "Provide the size of Elf_Shdr structures for the loaded format.", NULL +        }, +        { +            "sizeof_dyn", py_elf_format_get_sizeof_dyn, NULL, +            "Provide the size of Elf_Dyn structures for the loaded format.", NULL +        }, +        { +            "sizeof_sym", py_elf_format_get_sizeof_sym, NULL, +            "Provide the size of Elf_Sym structures for the loaded format.", NULL +        }, +        { +            "sizeof_rel", py_elf_format_get_sizeof_rel, NULL, +            "Provide the size of Elf_Rel structures for the loaded format.", NULL +        }, +        {              "needed", py_elf_format_get_needed, NULL,              "Provide the list of requiered shared objects.", NULL          }, diff --git a/plugins/elf/python/program.c b/plugins/elf/python/program.c index 198a76b..401b0d0 100644 --- a/plugins/elf/python/program.c +++ b/plugins/elf/python/program.c @@ -1,6 +1,6 @@  /* Chrysalide - Outil d'analyse de fichiers binaires - * program.c - prototypes pour l'équivalent Python du fichier "plugins/elf/program.c" + * program.c - équivalent Python du fichier "plugins/elf/program.c"   *   * Copyright (C) 2017 Cyrille Bagard   * diff --git a/plugins/elf/python/section.c b/plugins/elf/python/section.c index 537babc..b40681d 100644 --- a/plugins/elf/python/section.c +++ b/plugins/elf/python/section.c @@ -1,6 +1,6 @@  /* Chrysalide - Outil d'analyse de fichiers binaires - * section.c - prototypes pour l'équivalent Python du fichier "plugins/elf/section.c" + * section.c - équivalent Python du fichier "plugins/elf/section.c"   *   * Copyright (C) 2017 Cyrille Bagard   * | 
