From 332da5c182e576400a0b1e2ae62c2b990a5e52f1 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Sun, 12 Nov 2017 22:00:45 +0100 Subject: Updated the list of tags for ELF dynamic entries. --- ChangeLog | 15 ++ plugins/elf/elf_def.h | 51 ++++-- plugins/elf/python/Makefile.am | 1 + plugins/elf/python/constants.c | 384 +++++++++++++++++++++++++++++++++++++++++ plugins/elf/python/constants.h | 39 +++++ plugins/elf/python/format.c | 4 + 6 files changed, 478 insertions(+), 16 deletions(-) create mode 100644 plugins/elf/python/constants.c create mode 100644 plugins/elf/python/constants.h diff --git a/ChangeLog b/ChangeLog index 3424bbf..d3699b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,20 @@ 17-11-12 Cyrille Bagard + * plugins/elf/elf_def.h: + Update the list of tags for ELF dynamic entries. + + * plugins/elf/python/Makefile.am: + Add the 'constants.[ch]' files to libelfpython_la_SOURCES. + + * plugins/elf/python/constants.c: + * plugins/elf/python/constants.h: + New entries: export the ELF tags to the Python bindings. + + * plugins/elf/python/format.c: + Update code. + +17-11-12 Cyrille Bagard + * plugins/pychrysa/analysis/content.c: Improve the type of data read from loaded contents. diff --git a/plugins/elf/elf_def.h b/plugins/elf/elf_def.h index 5ab915a..8c2bb45 100644 --- a/plugins/elf/elf_def.h +++ b/plugins/elf/elf_def.h @@ -474,22 +474,41 @@ typedef union _elf_dyn /* Valeurs possibles pour d_tag */ -#define DT_SYMTAB 6 /* Table des symboles */ -#define DT_JMPREL 23 /* Relocalisations PLT */ - - -#define DT_PLTGOT 3 /* Processor defined value */ - -#define DT_INIT 12 /* Address of init function */ -#define DT_FINI 13 /* Address of termination function */ - -#define DT_INIT_ARRAY 25 /* Array with addresses of init fct */ -#define DT_FINI_ARRAY 26 /* Array with addresses of fini fct */ -#define DT_INIT_ARRAYSZ 27 /* Size in bytes of DT_INIT_ARRAY */ -#define DT_FINI_ARRAYSZ 28 /* Size in bytes of DT_FINI_ARRAY */ - -#define DT_PREINIT_ARRAY 32 /* Array with addresses of preinit fct*/ -#define DT_PREINIT_ARRAYSZ 33 /* size in bytes of DT_PREINIT_ARRAY */ +#define DT_NULL 0 /* Marque de fin de section */ +#define DT_NEEDED 1 /* Nom d'une dépendance */ +#define DT_PLTRELSZ 2 /* Taille des relocation PLT */ +#define DT_PLTGOT 3 /* Valeur spécifique au processeur */ +#define DT_HASH 4 /* Adresse de la table d'empreintes*/ +#define DT_STRTAB 5 /* Adresse de la table des chaînes */ +#define DT_SYMTAB 6 /* Adresse de la table des symboles*/ +#define DT_RELA 7 /* Adresse des relocations Rela */ +#define DT_RELASZ 8 /* Taille totale de ces relocations*/ +#define DT_RELAENT 9 /* Taille d'une relocation Rela */ +#define DT_STRSZ 10 /* Taille de la table de chaînes */ +#define DT_SYMENT 11 /* Taille d'un élément des symboles*/ +#define DT_INIT 12 /* Adresse de fonction init */ +#define DT_FINI 13 /* Adresse de fonction fini */ +#define DT_SONAME 14 /* Nom d'un objet partagé */ +#define DT_RPATH 15 /* Chemin de recherche (déprécié) */ +#define DT_SYMBOLIC 16 /* Départ de recherche de symbole */ +#define DT_REL 17 /* Adresse des relocations Rel */ +#define DT_RELSZ 18 /* Taille totale de ces relocations*/ +#define DT_RELENT 19 /* Taille d'une relocation Rel */ +#define DT_PLTREL 20 /* Type de relocation dans PLT */ +#define DT_DEBUG 21 /* Pour le débogage ; ??? */ +#define DT_TEXTREL 22 /* Les relocs. peuvent maj le code */ +#define DT_JMPREL 23 /* Adresse des relocations PLT */ +#define DT_BIND_NOW 24 /* Force la relocation des objets */ +#define DT_INIT_ARRAY 25 /* Tableau de fonctions init */ +#define DT_FINI_ARRAY 26 /* Tableau de fonctions fini */ +#define DT_INIT_ARRAYSZ 27 /* Taille de DT_INIT_ARRAY */ +#define DT_FINI_ARRAYSZ 28 /* Taille de DT_FINI_ARRAY */ +#define DT_RUNPATH 29 /* Chemin de recherche */ +#define DT_FLAGS 30 /* Fanions pour le chargement */ +#define DT_ENCODING 32 /* Départ d'encodage */ +#define DT_PREINIT_ARRAY 32 /* Tableau de fonctions preinit */ +#define DT_PREINIT_ARRAYSZ 33 /* Taille de DT_PREINIT_ARRAY */ +#define DT_NUM 34 /* Nombre utilisé */ diff --git a/plugins/elf/python/Makefile.am b/plugins/elf/python/Makefile.am index c39d170..91e86f0 100644 --- a/plugins/elf/python/Makefile.am +++ b/plugins/elf/python/Makefile.am @@ -2,6 +2,7 @@ noinst_LTLIBRARIES = libelfpython.la libelfpython_la_SOURCES = \ + constants.h constants.c \ format.h format.c \ module.h module.c diff --git a/plugins/elf/python/constants.c b/plugins/elf/python/constants.c new file mode 100644 index 0000000..91c07ee --- /dev/null +++ b/plugins/elf/python/constants.c @@ -0,0 +1,384 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * constants.c - équivalent Python partiel du fichier "plugins/elf/elf_def.h" + * + * 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 "constants.h" + + +#include + + +#include "../elf_def.h" + + + +/* Définit les constantes communes pour le format Elf. */ +static bool define_python_binary_format_common_constants(PyTypeObject *); + + +/****************************************************************************** +* * +* Paramètres : obj_type = type dont le dictionnaire est à compléter. * +* * +* Description : Définit les constantes communes pour le format Elf. * +* * +* Retour : true en cas de succès de l'opération, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool define_python_binary_format_common_constants(PyTypeObject *obj_type) +{ + bool result; /* Bilan à retourner */ + + result = true; + + /** + * En-tête de fichier ELF (32 et 64 bits) + */ + + if (result) result = PyDict_AddIntMacro(obj_type, EI_NIDENT); + + /* Composition du champ e_ident */ + + 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); + + /* ... EI_CLASS */ + + if (result) result = PyDict_AddIntMacro(obj_type, ELFCLASSNONE); + if (result) result = PyDict_AddIntMacro(obj_type, ELFCLASS32); + if (result) result = PyDict_AddIntMacro(obj_type, ELFCLASS64); + + /* ... EI_DATA */ + + if (result) result = PyDict_AddIntMacro(obj_type, ELFDATANONE); + if (result) result = PyDict_AddIntMacro(obj_type, ELFDATA2LSB); + if (result) result = PyDict_AddIntMacro(obj_type, ELFDATA2MSB); + + /* ... EI_VERSION */ + + if (result) result = PyDict_AddIntMacro(obj_type, EV_NONE); + if (result) result = PyDict_AddIntMacro(obj_type, EV_CURRENT); + + /* ... EI_OSABI */ + + if (result) result = PyDict_AddIntMacro(obj_type, ELFOSABI_NONE); + if (result) result = PyDict_AddIntMacro(obj_type, ELFOSABI_SYSV); + if (result) result = PyDict_AddIntMacro(obj_type, ELFOSABI_HPUX); + if (result) result = PyDict_AddIntMacro(obj_type, ELFOSABI_NETBSD); + if (result) result = PyDict_AddIntMacro(obj_type, ELFOSABI_GNU); + if (result) result = PyDict_AddIntMacro(obj_type, ELFOSABI_LINUX); + if (result) result = PyDict_AddIntMacro(obj_type, ELFOSABI_SOLARIS); + if (result) result = PyDict_AddIntMacro(obj_type, ELFOSABI_AIX); + if (result) result = PyDict_AddIntMacro(obj_type, ELFOSABI_IRIX); + if (result) result = PyDict_AddIntMacro(obj_type, ELFOSABI_FREEBSD); + if (result) result = PyDict_AddIntMacro(obj_type, ELFOSABI_TRU64); + if (result) result = PyDict_AddIntMacro(obj_type, ELFOSABI_MODESTO); + if (result) result = PyDict_AddIntMacro(obj_type, ELFOSABI_OPENBSD); + if (result) result = PyDict_AddIntMacro(obj_type, ELFOSABI_ARM_AEABI); + if (result) result = PyDict_AddIntMacro(obj_type, ELFOSABI_ARM); + if (result) result = PyDict_AddIntMacro(obj_type, ELFOSABI_STANDALONE); + + /* Valeurs possibles pour e_type */ + + if (result) result = PyDict_AddIntMacro(obj_type, ET_NONE); + if (result) result = PyDict_AddIntMacro(obj_type, ET_REL); + if (result) result = PyDict_AddIntMacro(obj_type, ET_EXEC); + if (result) result = PyDict_AddIntMacro(obj_type, ET_DYN); + if (result) result = PyDict_AddIntMacro(obj_type, ET_CORE); + if (result) result = PyDict_AddIntMacro(obj_type, ET_LOOS); + if (result) result = PyDict_AddIntMacro(obj_type, ET_HIOS); + if (result) result = PyDict_AddIntMacro(obj_type, ET_LOPROC); + if (result) result = PyDict_AddIntMacro(obj_type, ET_HIPROC); + + /* Valeurs possibles pour e_machine */ + + if (result) result = PyDict_AddIntMacro(obj_type, EM_NONE); + if (result) result = PyDict_AddIntMacro(obj_type, EM_M32); + if (result) result = PyDict_AddIntMacro(obj_type, EM_SPARC); + if (result) result = PyDict_AddIntMacro(obj_type, EM_386); + if (result) result = PyDict_AddIntMacro(obj_type, EM_68K); + if (result) result = PyDict_AddIntMacro(obj_type, EM_88K); + if (result) result = PyDict_AddIntMacro(obj_type, EM_860); + if (result) result = PyDict_AddIntMacro(obj_type, EM_MIPS); + if (result) result = PyDict_AddIntMacro(obj_type, EM_S370); + if (result) result = PyDict_AddIntMacro(obj_type, EM_MIPS_RS3_LE); + if (result) result = PyDict_AddIntMacro(obj_type, EM_PARISC); + if (result) result = PyDict_AddIntMacro(obj_type, EM_VPP500); + if (result) result = PyDict_AddIntMacro(obj_type, EM_SPARC32PLUS); + if (result) result = PyDict_AddIntMacro(obj_type, EM_960); + if (result) result = PyDict_AddIntMacro(obj_type, EM_PPC); + if (result) result = PyDict_AddIntMacro(obj_type, EM_PPC64); + if (result) result = PyDict_AddIntMacro(obj_type, EM_S390); + if (result) result = PyDict_AddIntMacro(obj_type, EM_V800); + if (result) result = PyDict_AddIntMacro(obj_type, EM_FR20); + if (result) result = PyDict_AddIntMacro(obj_type, EM_RH32); + if (result) result = PyDict_AddIntMacro(obj_type, EM_RCE); + if (result) result = PyDict_AddIntMacro(obj_type, EM_ARM); + if (result) result = PyDict_AddIntMacro(obj_type, EM_FAKE_ALPHA); + if (result) result = PyDict_AddIntMacro(obj_type, EM_SH); + if (result) result = PyDict_AddIntMacro(obj_type, EM_SPARCV9); + if (result) result = PyDict_AddIntMacro(obj_type, EM_TRICORE); + if (result) result = PyDict_AddIntMacro(obj_type, EM_ARC); + if (result) result = PyDict_AddIntMacro(obj_type, EM_H8_300); + if (result) result = PyDict_AddIntMacro(obj_type, EM_H8_300H); + if (result) result = PyDict_AddIntMacro(obj_type, EM_H8S); + if (result) result = PyDict_AddIntMacro(obj_type, EM_H8_500); + if (result) result = PyDict_AddIntMacro(obj_type, EM_IA_64); + if (result) result = PyDict_AddIntMacro(obj_type, EM_MIPS_X); + if (result) result = PyDict_AddIntMacro(obj_type, EM_COLDFIRE); + if (result) result = PyDict_AddIntMacro(obj_type, EM_68HC12); + if (result) result = PyDict_AddIntMacro(obj_type, EM_MMA); + if (result) result = PyDict_AddIntMacro(obj_type, EM_PCP); + if (result) result = PyDict_AddIntMacro(obj_type, EM_NCPU); + if (result) result = PyDict_AddIntMacro(obj_type, EM_NDR1); + if (result) result = PyDict_AddIntMacro(obj_type, EM_STARCORE); + if (result) result = PyDict_AddIntMacro(obj_type, EM_ME16); + if (result) result = PyDict_AddIntMacro(obj_type, EM_ST100); + if (result) result = PyDict_AddIntMacro(obj_type, EM_TINYJ); + if (result) result = PyDict_AddIntMacro(obj_type, EM_X86_64); + if (result) result = PyDict_AddIntMacro(obj_type, EM_PDSP); + if (result) result = PyDict_AddIntMacro(obj_type, EM_FX66); + if (result) result = PyDict_AddIntMacro(obj_type, EM_ST9PLUS); + if (result) result = PyDict_AddIntMacro(obj_type, EM_ST7); + if (result) result = PyDict_AddIntMacro(obj_type, EM_68HC16); + if (result) result = PyDict_AddIntMacro(obj_type, EM_68HC11); + if (result) result = PyDict_AddIntMacro(obj_type, EM_68HC08); + if (result) result = PyDict_AddIntMacro(obj_type, EM_68HC05); + if (result) result = PyDict_AddIntMacro(obj_type, EM_SVX); + if (result) result = PyDict_AddIntMacro(obj_type, EM_ST19); + if (result) result = PyDict_AddIntMacro(obj_type, EM_VAX); + if (result) result = PyDict_AddIntMacro(obj_type, EM_CRIS); + if (result) result = PyDict_AddIntMacro(obj_type, EM_JAVELIN); + if (result) result = PyDict_AddIntMacro(obj_type, EM_FIREPATH); + if (result) result = PyDict_AddIntMacro(obj_type, EM_ZSP); + if (result) result = PyDict_AddIntMacro(obj_type, EM_MMIX); + if (result) result = PyDict_AddIntMacro(obj_type, EM_HUANY); + if (result) result = PyDict_AddIntMacro(obj_type, EM_PRISM); + if (result) result = PyDict_AddIntMacro(obj_type, EM_AVR); + if (result) result = PyDict_AddIntMacro(obj_type, EM_FR30); + if (result) result = PyDict_AddIntMacro(obj_type, EM_D10V); + if (result) result = PyDict_AddIntMacro(obj_type, EM_D30V); + if (result) result = PyDict_AddIntMacro(obj_type, EM_V850); + if (result) result = PyDict_AddIntMacro(obj_type, EM_M32R); + if (result) result = PyDict_AddIntMacro(obj_type, EM_MN10300); + if (result) result = PyDict_AddIntMacro(obj_type, EM_MN10200); + if (result) result = PyDict_AddIntMacro(obj_type, EM_PJ); + if (result) result = PyDict_AddIntMacro(obj_type, EM_OPENRISC); + if (result) result = PyDict_AddIntMacro(obj_type, EM_ARC_A5); + if (result) result = PyDict_AddIntMacro(obj_type, EM_XTENSA); + if (result) result = PyDict_AddIntMacro(obj_type, EM_AARCH64); + if (result) result = PyDict_AddIntMacro(obj_type, EM_TILEPRO); + if (result) result = PyDict_AddIntMacro(obj_type, EM_MICROBLAZE); + if (result) result = PyDict_AddIntMacro(obj_type, EM_TILEGX); + + /** + * En-tête des programmes Elf + */ + + /* Valeurs possibles pour p_type */ + + if (result) result = PyDict_AddIntMacro(obj_type, PT_NULL); + if (result) result = PyDict_AddIntMacro(obj_type, PT_LOAD); + if (result) result = PyDict_AddIntMacro(obj_type, PT_DYNAMIC); + if (result) result = PyDict_AddIntMacro(obj_type, PT_INTERP); + if (result) result = PyDict_AddIntMacro(obj_type, PT_NOTE); + if (result) result = PyDict_AddIntMacro(obj_type, PT_SHLIB); + if (result) result = PyDict_AddIntMacro(obj_type, PT_PHDR); + if (result) result = PyDict_AddIntMacro(obj_type, PT_TLS); + if (result) result = PyDict_AddIntMacro(obj_type, PT_NUM); + if (result) result = PyDict_AddIntMacro(obj_type, PT_LOOS); + if (result) result = PyDict_AddIntMacro(obj_type, PT_GNU_EH_FRAME); + if (result) result = PyDict_AddIntMacro(obj_type, PT_GNU_STACK); + if (result) result = PyDict_AddIntMacro(obj_type, PT_GNU_RELRO); + if (result) result = PyDict_AddIntMacro(obj_type, PT_LOSUNW); + if (result) result = PyDict_AddIntMacro(obj_type, PT_SUNWBSS); + if (result) result = PyDict_AddIntMacro(obj_type, PT_SUNWSTACK); + if (result) result = PyDict_AddIntMacro(obj_type, PT_HISUNW); + if (result) result = PyDict_AddIntMacro(obj_type, PT_HIOS); + if (result) result = PyDict_AddIntMacro(obj_type, PT_LOPROC); + if (result) result = PyDict_AddIntMacro(obj_type, PT_HIPROC); + + /* Valeurs possibles pour p_flags */ + + if (result) result = PyDict_AddIntMacro(obj_type, PF_X); + if (result) result = PyDict_AddIntMacro(obj_type, PF_W); + if (result) result = PyDict_AddIntMacro(obj_type, PF_R); + if (result) result = PyDict_AddIntMacro(obj_type, PF_MASKOS); + if (result) result = PyDict_AddIntMacro(obj_type, PF_MASKPROC); + + /** + * En-tête des sections Elf + */ + + /* Valeurs possibles pour sh_type */ + + if (result) result = PyDict_AddIntMacro(obj_type, SHT_NULL); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_PROGBITS); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_SYMTAB); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_STRTAB); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_RELA); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_HASH); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_DYNAMIC); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_NOTE); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_NOBITS); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_REL); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_SHLIB); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_DYNSYM); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_INIT_ARRAY); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_FINI_ARRAY); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_PREINIT_ARRAY); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_GROUP); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_SYMTAB_SHNDX); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_NUM); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_LOOS); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_GNU_ATTRIBUTES); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_GNU_HASH); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_GNU_LIBLIST); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_CHECKSUM); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_LOSUNW); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_SUNW_move); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_SUNW_COMDAT); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_SUNW_syminfo); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_GNU_verdef); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_GNU_verneed); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_GNU_versym); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_HISUNW); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_HIOS); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_LOPROC); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_HIPROC); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_LOUSER); + if (result) result = PyDict_AddIntMacro(obj_type, SHT_HIUSER); + + /* Valeurs possibles pour sh_flags */ + + if (result) result = PyDict_AddIntMacro(obj_type, SHF_WRITE); + if (result) result = PyDict_AddIntMacro(obj_type, SHF_ALLOC); + if (result) result = PyDict_AddIntMacro(obj_type, SHF_EXECINSTR); + if (result) result = PyDict_AddIntMacro(obj_type, SHF_MERGE); + if (result) result = PyDict_AddIntMacro(obj_type, SHF_STRINGS); + if (result) result = PyDict_AddIntMacro(obj_type, SHF_INFO_LINK); + if (result) result = PyDict_AddIntMacro(obj_type, SHF_LINK_ORDER); + if (result) result = PyDict_AddIntMacro(obj_type, SHF_OS_NONCONFORMING); + if (result) result = PyDict_AddIntMacro(obj_type, SHF_GROUP); + if (result) result = PyDict_AddIntMacro(obj_type, SHF_TLS); + if (result) result = PyDict_AddIntMacro(obj_type, SHF_MASKOS); + if (result) result = PyDict_AddIntMacro(obj_type, SHF_MASKPROC); + if (result) result = PyDict_AddIntMacro(obj_type, SHF_ORDERED); + if (result) result = PyDict_AddIntMacro(obj_type, SHF_EXCLUDE); + + /** + * Données pour le linker + */ + + /* Valeurs possibles pour d_tag */ + + if (result) result = PyDict_AddIntMacro(obj_type, DT_NULL); + if (result) result = PyDict_AddIntMacro(obj_type, DT_NEEDED); + if (result) result = PyDict_AddIntMacro(obj_type, DT_PLTRELSZ); + if (result) result = PyDict_AddIntMacro(obj_type, DT_PLTGOT); + if (result) result = PyDict_AddIntMacro(obj_type, DT_HASH); + if (result) result = PyDict_AddIntMacro(obj_type, DT_STRTAB); + if (result) result = PyDict_AddIntMacro(obj_type, DT_SYMTAB); + if (result) result = PyDict_AddIntMacro(obj_type, DT_RELA); + if (result) result = PyDict_AddIntMacro(obj_type, DT_RELASZ); + if (result) result = PyDict_AddIntMacro(obj_type, DT_RELAENT); + if (result) result = PyDict_AddIntMacro(obj_type, DT_STRSZ); + if (result) result = PyDict_AddIntMacro(obj_type, DT_SYMENT); + if (result) result = PyDict_AddIntMacro(obj_type, DT_INIT); + if (result) result = PyDict_AddIntMacro(obj_type, DT_FINI); + if (result) result = PyDict_AddIntMacro(obj_type, DT_SONAME); + if (result) result = PyDict_AddIntMacro(obj_type, DT_RPATH); + if (result) result = PyDict_AddIntMacro(obj_type, DT_SYMBOLIC); + if (result) result = PyDict_AddIntMacro(obj_type, DT_REL); + if (result) result = PyDict_AddIntMacro(obj_type, DT_RELSZ); + if (result) result = PyDict_AddIntMacro(obj_type, DT_RELENT); + if (result) result = PyDict_AddIntMacro(obj_type, DT_PLTREL); + if (result) result = PyDict_AddIntMacro(obj_type, DT_DEBUG); + if (result) result = PyDict_AddIntMacro(obj_type, DT_TEXTREL); + if (result) result = PyDict_AddIntMacro(obj_type, DT_JMPREL); + if (result) result = PyDict_AddIntMacro(obj_type, DT_BIND_NOW); + if (result) result = PyDict_AddIntMacro(obj_type, DT_INIT_ARRAY); + if (result) result = PyDict_AddIntMacro(obj_type, DT_FINI_ARRAY); + if (result) result = PyDict_AddIntMacro(obj_type, DT_INIT_ARRAYSZ); + if (result) result = PyDict_AddIntMacro(obj_type, DT_FINI_ARRAYSZ); + if (result) result = PyDict_AddIntMacro(obj_type, DT_RUNPATH); + if (result) result = PyDict_AddIntMacro(obj_type, DT_FLAGS); + if (result) result = PyDict_AddIntMacro(obj_type, DT_ENCODING); + if (result) result = PyDict_AddIntMacro(obj_type, DT_PREINIT_ARRAY); + if (result) result = PyDict_AddIntMacro(obj_type, DT_PREINIT_ARRAYSZ); + if (result) result = PyDict_AddIntMacro(obj_type, DT_NUM); + + /** + * Symboles de binaires Elf + */ + + /* Valeurs pour le sous-champ ST_TYPE de st_info */ + + if (result) result = PyDict_AddIntMacro(obj_type, STT_NOTYPE); + if (result) result = PyDict_AddIntMacro(obj_type, STT_OBJECT); + if (result) result = PyDict_AddIntMacro(obj_type, STT_FUNC); + + /** + * Informations de relocalisation + */ + + /* Type de relocalisation (x86) */ + + if (result) result = PyDict_AddIntMacro(obj_type, R_386_NONE); + if (result) result = PyDict_AddIntMacro(obj_type, R_386_JMP_SLOT); + + /* Type de relocalisation (ARM) */ + + if (result) result = PyDict_AddIntMacro(obj_type, R_ARM_JUMP_SLOT); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : obj_type = type dont le dictionnaire est à compléter. * +* * +* Description : Définit les constantes pour le format Elf. * +* * +* Retour : true en cas de succès de l'opération, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool define_python_binary_format_constants(PyTypeObject *obj_type) +{ + bool result; /* Bilan à retourner */ + + result = define_python_binary_format_common_constants(obj_type); + + return result; + +} diff --git a/plugins/elf/python/constants.h b/plugins/elf/python/constants.h new file mode 100644 index 0000000..95b840c --- /dev/null +++ b/plugins/elf/python/constants.h @@ -0,0 +1,39 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * constants.h - prototypes pour l'équivalent Python partiel du fichier "plugins/elf/elf_def.h" + * + * 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 + */ + + +#ifndef _PLUGINS_ELF_PYTHON_CONSTANTS_H +#define _PLUGINS_ELF_PYTHON_CONSTANTS_H + + +#include +#include + + + +/* Définit les constantes pour le format Elf. */ +bool define_python_binary_format_constants(PyTypeObject *); + + + +#endif /* _PLUGINS_ELF_PYTHON_CONSTANTS_H */ diff --git a/plugins/elf/python/format.c b/plugins/elf/python/format.c index 84aa68c..1ff22bd 100644 --- a/plugins/elf/python/format.c +++ b/plugins/elf/python/format.c @@ -36,6 +36,7 @@ #include +#include "constants.h" #include "../format.h" @@ -193,6 +194,9 @@ bool register_python_elf_format(PyObject *module) py_elf_format_type, get_python_executable_format_type())) return false; + if (!define_python_binary_format_constants(py_elf_format_type)) + return false; + return true; } -- cgit v0.11.2-87-g4458