1 # Just a script for playing around with pyelftools during testing
6 from elftools
.elf
.structs
import ELFStructs
7 from elftools
.elf
.elffile
import ELFFile
8 from elftools
.elf
.sections
import *
10 from elftools
.dwarf
.dwarfrelocationmanager
import DWARFRelocationManager
12 # read a little-endian, 64-bit file
13 es
= ELFStructs(True, 64)
15 stream
= open('tests/testfiles/penalty_64.o.elf', 'rb')
16 #stream = open('binfiles/z32.elf', 'rb')
18 efile
= ELFFile(stream
)
19 print 'elfclass', efile
.elfclass
20 print '===> %s sections!' % efile
.num_sections()
22 #~ print efile.has_dwarf_info()
24 dwarfinfo
= efile
.get_dwarf_info()
25 print dwarfinfo
.get_string_from_table(0x4bc0)
26 cu
= dwarfinfo
.get_CU(0)
28 print cu
.structs
.Dwarf_dw_form
['DW_FORM_strp'].parse('\x01\x00\x00\x00\x01\x00\x00\x00')
29 print 'CU header', cu
.header
30 topdie
= cu
.get_top_DIE()
33 dinfo_sec
= efile
.get_section_by_name('.debug_info')
34 relman
= DWARFRelocationManager(efile
, dinfo_sec
.name
)
36 print relman
._reloc
_section
.name
, relman
._reloc
_section
['sh_offset']
37 #pprint.pprint(relman._relocs)