# This code is in the public domain
#-------------------------------------------------------------------------------
from .enums import (
- ENUM_D_TAG, ENUM_E_VERSION, ENUM_RELOC_TYPE_i386, ENUM_RELOC_TYPE_x64
- )
+ ENUM_D_TAG, ENUM_E_VERSION, ENUM_RELOC_TYPE_i386, ENUM_RELOC_TYPE_x64,
+ ENUM_RELOC_TYPE_ARM, ENUM_RELOC_TYPE_AARCH64)
from .constants import P_FLAGS, SH_FLAGS, SUNW_SYMINFO_FLAGS
from ..common.py3compat import iteritems
return _DESCR_RELOC_TYPE_i386.get(x, _unknown)
elif arch == 'x64':
return _DESCR_RELOC_TYPE_x64.get(x, _unknown)
+ elif arch == 'ARM':
+ return _DESCR_RELOC_TYPE_ARM.get(x, _unknown)
+ elif arch == 'AArch64':
+ return _DESCR_RELOC_TYPE_AARCH64.get(x, _unknown)
else:
return 'unrecognized: %-7x' % (x & 0xFFFFFFFF)
EM_IA_64='Intel IA-64',
EM_X86_64='Advanced Micro Devices X86-64',
EM_AVR='Atmel AVR 8-bit microcontroller',
+ EM_ARM='ARM',
+ EM_AARCH64='AArch64',
RESERVED='RESERVED',
)
PT_GNU_EH_FRAME='GNU_EH_FRAME',
PT_GNU_STACK='GNU_STACK',
PT_GNU_RELRO='GNU_RELRO',
+ PT_ARM_ARCHEXT='ARM_ARCHEXT',
+ PT_ARM_EXIDX='ARM_EXIDX',
+ PT_ARM_UNWIND='ARM_UNWIND',
+ PT_AARCH64_ARCHEXT='AARCH64_ARCHEXT',
+ PT_AARCH64_UNWIND='AARCH64_UNWIND',
)
_DESCR_P_FLAGS = {
SHT_GNU_verneed='VERNEED',
SHT_GNU_versym='VERSYM',
SHT_GNU_LIBLIST='GNU_LIBLIST',
+ SHT_ARM_EXIDX='ARM_EXIDX',
+ SHT_ARM_PREEMPTMAP='ARM_PREEMPTMAP',
+ SHT_ARM_ATTRIBUTES='ARM_ATTRIBUTES',
+ SHT_ARM_DEBUGOVERLAY='ARM_DEBUGOVERLAY',
)
_DESCR_SH_FLAGS = {
_DESCR_RELOC_TYPE_x64 = dict(
(v, k) for k, v in iteritems(ENUM_RELOC_TYPE_x64))
+_DESCR_RELOC_TYPE_ARM = dict(
+ (v, k) for k, v in iteritems(ENUM_RELOC_TYPE_ARM))
+
+_DESCR_RELOC_TYPE_AARCH64 = dict(
+ (v, k) for k, v in iteritems(ENUM_RELOC_TYPE_AARCH64))
+
_DESCR_D_TAG = dict(
(v, k) for k, v in iteritems(ENUM_D_TAG))
ELFOSABI_OPENVMS=13,
ELFOSABI_NSK=14,
ELFOSABI_AROS=15,
+ ELFOSABI_ARM_AEABI=64,
ELFOSABI_ARM=97,
ELFOSABI_STANDALONE=255,
_default_=Pass,
EM_ARCA=109,
EM_UNICORE=110,
EM_L10M=180,
+ EM_AARCH64=183,
_default_=Pass,
)
SHT_HIUSER=0xffffffff,
SHT_AMD64_UNWIND=0x70000001,
SHT_SUNW_syminfo=0x6ffffffc,
+ SHT_ARM_EXIDX=0x70000001,
+ SHT_ARM_PREEMPTMAP=0x70000002,
+ SHT_ARM_ATTRIBUTES=0x70000003,
+ SHT_ARM_DEBUGOVERLAY=0x70000004,
_default_=Pass,
)
PT_GNU_EH_FRAME=0x6474e550,
PT_GNU_STACK=0x6474e551,
PT_GNU_RELRO=0x6474e552,
+ PT_ARM_ARCHEXT=0x70000000,
+ PT_ARM_EXIDX=0x70000001,
+ PT_ARM_UNWIND=0x70000001,
+ PT_AARCH64_ARCHEXT=0x70000000,
+ PT_AARCH64_UNWIND=0x70000001,
_default_=Pass,
)
_default_=Pass,
)
+ENUM_RELOC_TYPE_ARM = dict(
+ R_ARM_NONE=0,
+ R_ARM_PC24=1,
+ R_ARM_ABS32=2,
+ R_ARM_REL32=3,
+ R_ARM_LDR_PC_G0=4,
+ R_ARM_ABS16=5,
+ R_ARM_ABS12=6,
+ R_ARM_THM_ABS5=7,
+ R_ARM_ABS8=8,
+ R_ARM_SBREL32=9,
+ R_ARM_THM_CALL=10,
+ R_ARM_THM_PC8=11,
+ R_ARM_BREL_ADJ=12,
+ R_ARM_SWI24=13,
+ R_ARM_THM_SWI8=14,
+ R_ARM_XPC25=15,
+ R_ARM_THM_XPC22=16,
+ R_ARM_TLS_DTPMOD32=17,
+ R_ARM_TLS_DTPOFF32=18,
+ R_ARM_TLS_TPOFF32=19,
+ R_ARM_COPY=20,
+ R_ARM_GLOB_DAT=21,
+ R_ARM_JUMP_SLOT=22,
+ R_ARM_RELATIVE=23,
+ R_ARM_GOTOFF32=24,
+ R_ARM_BASE_PREL=25,
+ R_ARM_GOT_BREL=26,
+ R_ARM_PLT32=27,
+ R_ARM_CALL=28,
+ R_ARM_JUMP24=29,
+ R_ARM_THM_JUMP24=30,
+ R_ARM_BASE_ABS=31,
+ R_ARM_ALU_PCREL_7_0=32,
+ R_ARM_ALU_PCREL_15_8=33,
+ R_ARM_ALU_PCREL_23_15=34,
+ R_ARM_LDR_SBREL_11_0_NC=35,
+ R_ARM_ALU_SBREL_19_12_NC=36,
+ R_ARM_ALU_SBREL_27_20_CK=37,
+ R_ARM_TARGET1=38,
+ R_ARM_SBREL31=39,
+ R_ARM_V4BX=40,
+ R_ARM_TARGET2=41,
+ R_ARM_PREL31=42,
+ R_ARM_MOVW_ABS_NC=43,
+ R_ARM_MOVT_ABS=44,
+ R_ARM_MOVW_PREL_NC=45,
+ R_ARM_MOVT_PREL=46,
+ R_ARM_THM_MOVW_ABS_NC=47,
+ R_ARM_THM_MOVT_ABS=48,
+ R_ARM_THM_MOVW_PREL_NC=49,
+ R_ARM_THM_MOVT_PREL=50,
+ R_ARM_THM_JUMP19=51,
+ R_ARM_THM_JUMP6=52,
+ R_ARM_THM_ALU_PREL_11_0=53,
+ R_ARM_THM_PC12=54,
+ R_ARM_ABS32_NOI=55,
+ R_ARM_REL32_NOI=56,
+ R_ARM_ALU_PC_G0_NC=57,
+ R_ARM_ALU_PC_G0=58,
+ R_ARM_ALU_PC_G1_NC=59,
+ R_ARM_ALU_PC_G1=60,
+ R_ARM_ALU_PC_G2=61,
+ R_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R_ARM_PRIVATE_3=115,
+ R_ARM_PRIVATE_4=116,
+ R_ARM_PRIVATE_5=117,
+ R_ARM_PRIVATE_6=118,
+ R_ARM_PRIVATE_7=119,
+ R_ARM_PRIVATE_8=120,
+ R_ARM_PRIVATE_9=121,
+ R_ARM_PRIVATE_10=122,
+ R_ARM_PRIVATE_11=123,
+ R_ARM_PRIVATE_12=124,
+ R_ARM_PRIVATE_13=125,
+ R_ARM_PRIVATE_14=126,
+ R_ARM_PRIVATE_15=127,
+ R_ARM_ME_TOO=128,
+ R_ARM_THM_TLS_DESCSEQ16=129,
+ R_ARM_THM_TLS_DESCSEQ32=130,
+ R_ARM_THM_GOT_BREL12=131,
+ R_ARM_IRELATIVE=140,
+)
+
+ENUM_RELOC_TYPE_AARCH64 = dict(
+ R_AARCH64_NONE=256,
+ R_AARCH64_ABS64=257,
+ R_AARCH64_ABS32=258,
+ R_AARCH64_ABS16=259,
+ R_AARCH64_PREL64=260,
+ R_AARCH64_PREL32=261,
+ R_AARCH64_PREL16=262,
+ R_AARCH64_MOVW_UABS_G0=263,
+ R_AARCH64_MOVW_UABS_G0_NC=264,
+ R_AARCH64_MOVW_UABS_G1=265,
+ R_AARCH64_MOVW_UABS_G1_NC=266,
+ R_AARCH64_MOVW_UABS_G2=267,
+ R_AARCH64_MOVW_UABS_G2_NC=268,
+ R_AARCH64_MOVW_UABS_G3=269,
+ R_AARCH64_MOVW_SABS_G0=270,
+ R_AARCH64_MOVW_SABS_G1=271,
+ R_AARCH64_MOVW_SABS_G2=272,
+ R_AARCH64_LD_PREL_LO19=273,
+ R_AARCH64_ADR_PREL_LO21=274,
+ R_AARCH64_ADR_PREL_PG_HI21=275,
+ R_AARCH64_ADR_PREL_PG_HI21_NC=276,
+ R_AARCH64_ADD_ABS_LO12_NC=277,
+ R_AARCH64_LDST8_ABS_LO12_NC=278,
+ R_AARCH64_TSTBR14=279,
+ R_AARCH64_CONDBR19=280,
+ R_AARCH64_JUMP26=282,
+ R_AARCH64_CALL26=283,
+ R_AARCH64_LDST16_ABS_LO12_NC=284,
+ R_AARCH64_LDST32_ABS_LO12_NC=285,
+ R_AARCH64_LDST64_ABS_LO12_NC=286,
+ R_AARCH64_MOVW_PREL_G0=287,
+ R_AARCH64_MOVW_PREL_G0_NC=288,
+ R_AARCH64_MOVW_PREL_G1=289,
+ R_AARCH64_MOVW_PREL_G1_NC=290,
+ R_AARCH64_MOVW_PREL_G2=291,
+ R_AARCH64_MOVW_PREL_G2_NC=292,
+ R_AARCH64_MOVW_PREL_G3=293,
+ R_AARCH64_MOVW_GOTOFF_G0=300,
+ R_AARCH64_MOVW_GOTOFF_G0_NC=301,
+ R_AARCH64_MOVW_GOTOFF_G1=302,
+ R_AARCH64_MOVW_GOTOFF_G1_NC=303,
+ R_AARCH64_MOVW_GOTOFF_G2=304,
+ R_AARCH64_MOVW_GOTOFF_G2_NC=305,
+ R_AARCH64_MOVW_GOTOFF_G3=306,
+ R_AARCH64_GOTREL64=307,
+ R_AARCH64_GOTREL32=308,
+ R_AARCH64_GOT_LD_PREL19=309,
+ R_AARCH64_LD64_GOTOFF_LO15=310,
+ R_AARCH64_ADR_GOT_PAGE=311,
+ R_AARCH64_LD64_GOT_LO12_NC=312,
+ R_AARCH64_TLSGD_ADR_PREL21=512,
+ R_AARCH64_TLSGD_ADR_PAGE21=513,
+ R_AARCH64_TLSGD_ADD_LO12_NC=514,
+ R_AARCH64_TLSGD_MOVW_G1=515,
+ R_AARCH64_TLSGD_MOVW_G0_NC=516,
+ R_AARCH64_TLSLD_ADR_PREL21=517,
+ R_AARCH64_TLSLD_ADR_PAGE21=518,
+ R_AARCH64_TLSLD_ADD_LO12_NC=519,
+ R_AARCH64_TLSLD_MOVW_G1=520,
+ R_AARCH64_TLSLD_MOVW_G0_NC=521,
+ R_AARCH64_TLSLD_LD_PREL19=522,
+ R_AARCH64_TLSLD_MOVW_DTPREL_G2=523,
+ R_AARCH64_TLSLD_MOVW_DTPREL_G1=524,
+ R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC=525,
+ R_AARCH64_TLSLD_MOVW_DTPREL_G0=526,
+ R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC=527,
+ R_AARCH64_TLSLD_ADD_DTPREL_HI12=528,
+ R_AARCH64_TLSLD_ADD_DTPREL_LO12=529,
+ R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC=530,
+ R_AARCH64_TLSLD_LDST8_DTPREL_LO12=531,
+ R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC=532,
+ R_AARCH64_TLSLD_LDST16_DTPREL_LO12=533,
+ R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC=534,
+ R_AARCH64_TLSLD_LDST32_DTPREL_LO12=535,
+ R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC=536,
+ R_AARCH64_TLSLD_LDST64_DTPREL_LO12=537,
+ R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC=538,
+ R_AARCH64_TLSIE_MOVW_GOTTPREL_G1=539,
+ R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC=540,
+ R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21=541,
+ R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC=542,
+ R_AARCH64_TLSIE_LD_GOTTPREL_PREL19=543,
+ R_AARCH64_TLSLE_MOVW_TPREL_G2=544,
+ R_AARCH64_TLSLE_MOVW_TPREL_G1=545,
+ R_AARCH64_TLSLE_MOVW_TPREL_G1_NC=546,
+ R_AARCH64_TLSLE_MOVW_TPREL_G0=547,
+ R_AARCH64_TLSLE_MOVW_TPREL_G0_NC=548,
+ R_AARCH64_TLSLE_ADD_TPREL_HI12=549,
+ R_AARCH64_TLSLE_ADD_TPREL_LO12=550,
+ R_AARCH64_TLSLE_ADD_TPREL_LO12_NC=551,
+ R_AARCH64_TLSLE_LDST8_TPREL_LO12=552,
+ R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC=553,
+ R_AARCH64_TLSLE_LDST16_TPREL_LO12=554,
+ R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC=555,
+ R_AARCH64_TLSLE_LDST32_TPREL_LO12=556,
+ R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC=557,
+ R_AARCH64_TLSLE_LDST64_TPREL_LO12=558,
+ R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC=559,
+ R_AARCH64_COPY=1024,
+ R_AARCH64_GLOB_DAT=1025,
+ R_AARCH64_JUMP_SLOT=1026,
+ R_AARCH64_RELATIVE=1027,
+ R_AARCH64_TLS_DTPREL64=1028,
+ R_AARCH64_TLS_DTPMOD64=1029,
+ R_AARCH64_TLS_TPREL64=1030,
+ R_AARCH64_TLS_DTPREL32=1031,
+ R_AARCH64_TLS_DTPMOD32=1032,
+ R_AARCH64_TLS_TPREL32=1033,
+)
describe_symbol_type, describe_symbol_bind, describe_symbol_visibility,
describe_symbol_shndx, describe_reloc_type, describe_dyn_tag,
)
+from elftools.elf.constants import E_FLAGS
from elftools.dwarf.dwarfinfo import DWARFInfo
from elftools.dwarf.descriptions import (
describe_reg_name, describe_attr_value, set_global_machine_arch,
self._emit(' Start of section headers: %s' %
header['e_shoff'])
self._emitline(' (bytes into file)')
- self._emitline(' Flags: %s' %
- self._format_hex(header['e_flags']))
+ self._emitline(' Flags: %s%s' %
+ (self._format_hex(header['e_flags']),
+ self.decode_flags(header['e_flags'])))
self._emitline(' Size of this header: %s (bytes)' %
header['e_ehsize'])
self._emitline(' Size of program headers: %s (bytes)' %
self._emitline(' Section header string table index: %s' %
header['e_shstrndx'])
+ def decode_flags(self, flags):
+ description = ""
+ if self.elffile['e_machine'] == "EM_ARM":
+ if flags & E_FLAGS.EF_ARM_HASENTRY:
+ description += ", has entry point"
+
+ version = flags & E_FLAGS.EF_ARM_EABIMASK
+ if version == E_FLAGS.EF_ARM_EABI_VER5:
+ description += ", Version5 EABI"
+ return description
+
def display_program_headers(self, show_heading=True):
""" Display the ELF program headers.
If show_heading is True, displays the heading for this information
def display_dynamic_tags(self):
""" Display the dynamic tags contained in the file
"""
+ has_dynamic_sections = False
for section in self.elffile.iter_sections():
if not isinstance(section, DynamicSection):
continue
+ has_dynamic_sections = True
self._emitline("\nDynamic section at offset %s contains %s entries:" % (
self._format_hex(section['sh_offset']),
section.num_tags()))
padding,
'(%s)' % (tag.entry.d_tag[3:],),
parsed))
+ if not has_dynamic_sections:
+ # readelf only prints this if there is at least one segment
+ if self.elffile.num_segments():
+ self._emitline("\nThere is no dynamic section in this file.")
def display_relocations(self):
""" Display the relocations contained in the file