From: gahag Date: Sun, 25 Nov 2018 22:06:14 +0000 (-0200) Subject: Implemented ELFFile.get_machine_arch for the remaining architectures. (#206) X-Git-Tag: v0.26~32 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d60d952075c8120a1f7f22d0463c8cbeaba9d6ff;p=pyelftools.git Implemented ELFFile.get_machine_arch for the remaining architectures. (#206) * Implemented ELFFile.get_machine_arch for the remaining architectures. Added all architectures according to the ENUM_E_MACHINE. * Refactored if statement into dict.get. --- diff --git a/elftools/elf/elffile.py b/elftools/elf/elffile.py index 289a5f9..6c02948 100644 --- a/elftools/elf/elffile.py +++ b/elftools/elf/elffile.py @@ -211,20 +211,193 @@ class ELFFile(object): def get_machine_arch(self): """ Return the machine architecture, as detected from the ELF header. - Not all architectures are supported at the moment. """ - if self['e_machine'] == 'EM_X86_64': - return 'x64' - elif self['e_machine'] in ('EM_386', 'EM_486'): - return 'x86' - elif self['e_machine'] == 'EM_ARM': - return 'ARM' - elif self['e_machine'] == 'EM_AARCH64': - return 'AArch64' - elif self['e_machine'] == 'EM_MIPS': - return 'MIPS' - else: - return '' + architectures = { + 'EM_M32' : 'AT&T WE 32100', + 'EM_SPARC' : 'SPARC', + 'EM_386' : 'x86', + 'EM_68K' : 'Motorola 68000', + 'EM_88K' : 'Motorola 88000', + 'EM_IAMCU' : 'Intel MCU', + 'EM_860' : 'Intel 80860', + 'EM_MIPS' : 'MIPS', + 'EM_S370' : 'IBM System/370', + 'EM_MIPS_RS3_LE' : 'MIPS RS3000 Little-endian', + 'EM_PARISC' : 'Hewlett-Packard PA-RISC', + 'EM_VPP500' : 'Fujitsu VPP500', + 'EM_SPARC32PLUS' : 'Enhanced SPARC', + 'EM_960' : 'Intel 80960', + 'EM_PPC' : 'PowerPC', + 'EM_PPC64' : '64-bit PowerPC', + 'EM_S390' : 'IBM System/390', + 'EM_SPU' : 'IBM SPU/SPC', + 'EM_V800' : 'NEC V800', + 'EM_FR20' : 'Fujitsu FR20', + 'EM_RH32' : 'TRW RH-32', + 'EM_RCE' : 'Motorola RCE', + 'EM_ARM' : 'ARM', + 'EM_ALPHA' : 'Digital Alpha', + 'EM_SH' : 'Hitachi SH', + 'EM_SPARCV9' : 'SPARC Version 9', + 'EM_TRICORE' : 'Siemens TriCore embedded processor', + 'EM_ARC' : 'Argonaut RISC Core, Argonaut Technologies Inc.', + 'EM_H8_300' : 'Hitachi H8/300', + 'EM_H8_300H' : 'Hitachi H8/300H', + 'EM_H8S' : 'Hitachi H8S', + 'EM_H8_500' : 'Hitachi H8/500', + 'EM_IA_64' : 'Intel IA-64', + 'EM_MIPS_X' : 'MIPS-X', + 'EM_COLDFIRE' : 'Motorola ColdFire', + 'EM_68HC12' : 'Motorola M68HC12', + 'EM_MMA' : 'Fujitsu MMA', + 'EM_PCP' : 'Siemens PCP', + 'EM_NCPU' : 'Sony nCPU', + 'EM_NDR1' : 'Denso NDR1', + 'EM_STARCORE' : 'Motorola Star*Core', + 'EM_ME16' : 'Toyota ME16', + 'EM_ST100' : 'STMicroelectronics ST100', + 'EM_TINYJ' : 'Advanced Logic TinyJ', + 'EM_X86_64' : 'x64', + 'EM_PDSP' : 'Sony DSP', + 'EM_PDP10' : 'Digital Equipment PDP-10', + 'EM_PDP11' : 'Digital Equipment PDP-11', + 'EM_FX66' : 'Siemens FX66', + 'EM_ST9PLUS' : 'STMicroelectronics ST9+ 8/16 bit', + 'EM_ST7' : 'STMicroelectronics ST7 8-bit', + 'EM_68HC16' : 'Motorola MC68HC16', + 'EM_68HC11' : 'Motorola MC68HC11', + 'EM_68HC08' : 'Motorola MC68HC08', + 'EM_68HC05' : 'Motorola MC68HC05', + 'EM_SVX' : 'Silicon Graphics SVx', + 'EM_ST19' : 'STMicroelectronics ST19 8-bit', + 'EM_VAX' : 'Digital VAX', + 'EM_CRIS' : 'Axis Communications 32-bit', + 'EM_JAVELIN' : 'Infineon Technologies 32-bit', + 'EM_FIREPATH' : 'Element 14 64-bit DSP', + 'EM_ZSP' : 'LSI Logic 16-bit DSP', + 'EM_MMIX' : 'Donald Knuth\'s educational 64-bit', + 'EM_HUANY' : 'Harvard University machine-independent object files', + 'EM_PRISM' : 'SiTera Prism', + 'EM_AVR' : 'Atmel AVR 8-bit', + 'EM_FR30' : 'Fujitsu FR30', + 'EM_D10V' : 'Mitsubishi D10V', + 'EM_D30V' : 'Mitsubishi D30V', + 'EM_V850' : 'NEC v850', + 'EM_M32R' : 'Mitsubishi M32R', + 'EM_MN10300' : 'Matsushita MN10300', + 'EM_MN10200' : 'Matsushita MN10200', + 'EM_PJ' : 'picoJava', + 'EM_OPENRISC' : 'OpenRISC 32-bit', + 'EM_ARC_COMPACT' : 'ARC International ARCompact', + 'EM_XTENSA' : 'Tensilica Xtensa', + 'EM_VIDEOCORE' : 'Alphamosaic VideoCore', + 'EM_TMM_GPP' : 'Thompson Multimedia', + 'EM_NS32K' : 'National Semiconductor 32000 series', + 'EM_TPC' : 'Tenor Network TPC', + 'EM_SNP1K' : 'Trebia SNP 1000', + 'EM_ST200' : 'STMicroelectronics ST200', + 'EM_IP2K' : 'Ubicom IP2xxx', + 'EM_MAX' : 'MAX', + 'EM_CR' : 'National Semiconductor CompactRISC', + 'EM_F2MC16' : 'Fujitsu F2MC16', + 'EM_MSP430' : 'Texas Instruments msp430', + 'EM_BLACKFIN' : 'Analog Devices Blackfin', + 'EM_SE_C33' : 'Seiko Epson S1C33', + 'EM_SEP' : 'Sharp', + 'EM_ARCA' : 'Arca RISC', + 'EM_UNICORE' : 'PKU-Unity MPRC', + 'EM_EXCESS' : 'eXcess', + 'EM_DXP' : 'Icera Semiconductor Deep Execution Processor', + 'EM_ALTERA_NIOS2' : 'Altera Nios II', + 'EM_CRX' : 'National Semiconductor CompactRISC CRX', + 'EM_XGATE' : 'Motorola XGATE', + 'EM_C166' : 'Infineon C16x/XC16x', + 'EM_M16C' : 'Renesas M16C', + 'EM_DSPIC30F' : 'Microchip Technology dsPIC30F', + 'EM_CE' : 'Freescale Communication Engine RISC core', + 'EM_M32C' : 'Renesas M32C', + 'EM_TSK3000' : 'Altium TSK3000', + 'EM_RS08' : 'Freescale RS08', + 'EM_SHARC' : 'Analog Devices SHARC', + 'EM_ECOG2' : 'Cyan Technology eCOG2', + 'EM_SCORE7' : 'Sunplus S+core7 RISC', + 'EM_DSP24' : 'New Japan Radio (NJR) 24-bit DSP', + 'EM_VIDEOCORE3' : 'Broadcom VideoCore III', + 'EM_LATTICEMICO32' : 'Lattice FPGA RISC', + 'EM_SE_C17' : 'Seiko Epson C17', + 'EM_TI_C6000' : 'TI TMS320C6000', + 'EM_TI_C2000' : 'TI TMS320C2000', + 'EM_TI_C5500' : 'TI TMS320C55x', + 'EM_TI_ARP32' : 'TI Application Specific RISC, 32bit', + 'EM_TI_PRU' : 'TI Programmable Realtime Unit', + 'EM_MMDSP_PLUS' : 'STMicroelectronics 64bit VLIW', + 'EM_CYPRESS_M8C' : 'Cypress M8C', + 'EM_R32C' : 'Renesas R32C', + 'EM_TRIMEDIA' : 'NXP Semiconductors TriMedia', + 'EM_QDSP6' : 'QUALCOMM DSP6', + 'EM_8051' : 'Intel 8051', + 'EM_STXP7X' : 'STMicroelectronics STxP7x', + 'EM_NDS32' : 'Andes Technology RISC', + 'EM_ECOG1' : 'Cyan Technology eCOG1X', + 'EM_ECOG1X' : 'Cyan Technology eCOG1X', + 'EM_MAXQ30' : 'Dallas Semiconductor MAXQ30', + 'EM_XIMO16' : 'New Japan Radio (NJR) 16-bit', + 'EM_MANIK' : 'M2000 Reconfigurable RISC', + 'EM_CRAYNV2' : 'Cray Inc. NV2', + 'EM_RX' : 'Renesas RX', + 'EM_METAG' : 'Imagination Technologies META', + 'EM_MCST_ELBRUS' : 'MCST Elbrus', + 'EM_ECOG16' : 'Cyan Technology eCOG16', + 'EM_CR16' : 'National Semiconductor CompactRISC CR16 16-bit', + 'EM_ETPU' : 'Freescale', + 'EM_SLE9X' : 'Infineon Technologies SLE9X', + 'EM_L10M' : 'Intel L10M', + 'EM_K10M' : 'Intel K10M', + 'EM_AARCH64' : 'AArch64', + 'EM_AVR32' : 'Atmel 32-bit', + 'EM_STM8' : 'STMicroeletronics STM8 8-bit', + 'EM_TILE64' : 'Tilera TILE64', + 'EM_TILEPRO' : 'Tilera TILEPro', + 'EM_MICROBLAZE' : 'Xilinx MicroBlaze 32-bit RISC', + 'EM_CUDA' : 'NVIDIA CUDA', + 'EM_TILEGX' : 'Tilera TILE-Gx', + 'EM_CLOUDSHIELD' : 'CloudShield', + 'EM_COREA_1ST' : 'KIPO-KAIST Core-A 1st generation', + 'EM_COREA_2ND' : 'KIPO-KAIST Core-A 2nd generation', + 'EM_ARC_COMPACT2' : 'Synopsys ARCompact V2', + 'EM_OPEN8' : 'Open8 8-bit RISC', + 'EM_RL78' : 'Renesas RL78', + 'EM_VIDEOCORE5' : 'Broadcom VideoCore V', + 'EM_78KOR' : 'Renesas 78KOR', + 'EM_56800EX' : 'Freescale 56800EX', + 'EM_BA1' : 'Beyond BA1', + 'EM_BA2' : 'Beyond BA2', + 'EM_XCORE' : 'XMOS xCORE', + 'EM_MCHP_PIC' : 'Microchip 8-bit PIC', + 'EM_INTEL205' : 'Reserved by Intel', + 'EM_INTEL206' : 'Reserved by Intel', + 'EM_INTEL207' : 'Reserved by Intel', + 'EM_INTEL208' : 'Reserved by Intel', + 'EM_INTEL209' : 'Reserved by Intel', + 'EM_KM32' : 'KM211 KM32 32-bit', + 'EM_KMX32' : 'KM211 KMX32 32-bit', + 'EM_KMX16' : 'KM211 KMX16 16-bit', + 'EM_KMX8' : 'KM211 KMX8 8-bit', + 'EM_KVARC' : 'KM211 KVARC', + 'EM_CDP' : 'Paneve CDP', + 'EM_COGE' : 'Cognitive', + 'EM_COOL' : 'Bluechip Systems CoolEngine', + 'EM_NORC' : 'Nanoradio Optimized RISC', + 'EM_CSR_KALIMBA' : 'CSR Kalimba', + 'EM_Z80' : 'Zilog Z80', + 'EM_VISIUM' : 'VISIUMcore', + 'EM_FT32' : 'FTDI Chip FT32 32-bit RISC', + 'EM_MOXIE' : 'Moxie', + 'EM_AMDGPU' : 'AMD GPU', + 'EM_RISCV' : 'RISC-V' + } + + return architectures.get(self['e_machine'], '') #-------------------------------- PRIVATE --------------------------------#