small fixes to have formatting consistent with readelf
[pyelftools.git] / z.py
1 # Just a script for playing around with pyelftools during testing
2 # please ignore it!
3 #
4
5 import sys, pprint
6 from elftools.elf.structs import ELFStructs
7 from elftools.elf.elffile import ELFFile
8 from elftools.elf.sections import *
9
10 # read a little-endian, 64-bit file
11 es = ELFStructs(True, 64)
12
13 stream = open('tests/testfiles/penalty_64.o.elf', 'rb')
14 #stream = open('binfiles/z32.elf', 'rb')
15
16 efile = ELFFile(stream)
17 print 'elfclass', efile.elfclass
18 print '===> %s sections!' % efile.num_sections()
19
20 #~ print efile.has_dwarf_info()
21
22 dwarfinfo = efile.get_dwarf_info()
23 print dwarfinfo.get_string_from_table(0x4bc0)
24 cu = dwarfinfo.get_CU(0)
25
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()
29
30 print topdie
31
32 #~ print 'siblings.....'
33
34 #~ for s in c.iter_siblings():
35 #~ print s
36
37 #~ from elftools.dwarf.location_expr import DW_OP_name2opcode, DW_OP_opcode2name
38
39 #~ print hex(DW_OP_name2opcode['DW_OP_lit14'])
40 #~ print DW_OP_opcode2name[0x0e]
41
42