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 # read a little-endian, 64-bit file
11 es
= ELFStructs(True, 64)
13 stream
= open('tests/testfiles/penalty_64.o.elf', 'rb')
14 #stream = open('binfiles/z32.elf', 'rb')
16 efile
= ELFFile(stream
)
17 print 'elfclass', efile
.elfclass
18 print '===> %s sections!' % efile
.num_sections()
20 #~ print efile.has_dwarf_info()
22 dwarfinfo
= efile
.get_dwarf_info()
23 print dwarfinfo
.get_string_from_table(0x4bc0)
24 cu
= dwarfinfo
.get_CU(0)
26 print cu
.structs
.Dwarf_dw_form
['DW_FORM_strp'].parse('\x01\x00\x00\x00\x01\x00\x00\x00')
27 print 'CU header', cu
.header
28 topdie
= cu
.get_top_DIE()
32 #~ print 'siblings.....'
34 #~ for s in c.iter_siblings():
37 #~ from elftools.dwarf.location_expr import DW_OP_name2opcode, DW_OP_opcode2name
39 #~ print hex(DW_OP_name2opcode['DW_OP_lit14'])
40 #~ print DW_OP_opcode2name[0x0e]