cleanup and cosmetics - for a healthy future!! er... what?
[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/z.elf', 'rb')
14 #stream = open('binfiles/z32.elf', 'rb')
15
16 efile = ELFFile(stream)
17 print efile.elfclass, efile.little_endian
18 print '===> %s sections!' % efile.num_sections()
19
20 print efile.has_dwarf_info()
21
22 dwarfinfo = efile.get_dwarf_info()
23 tt = dwarfinfo.structs.Dwarf_dw_form['DW_FORM_block1'].parse('\x03\x12\x34\x46')
24
25 cu = dwarfinfo.get_CU(0)
26 print 'CU header', cu.header
27 topdie = cu.get_top_DIE()
28
29 print topdie.size, topdie.tag
30 for attrname, val in topdie.attributes.iteritems():
31 print attrname, val
32
33 #~ print dwarfinfo.structs.Dwarf_abbrev_entry.parse('\x13\x01\x01\x03\x50\x04\x00\x00')
34
35 #~ abbrevtable = dwarfinfo.get_abbrev_table(95)
36 #~ print id(abbrevtable)
37 #~ pprint.pprint(abbrevtable._abbrev_map)
38
39 #~ ab1 = abbrevtable.get_abbrev(2)
40 #~ print ab1.has_children()
41 #~ for name, form in ab1.iter_attr_specs():
42 #~ print name, form
43
44 #~ print dwarfinfo.get_abbrev_table(0).get_abbrev(1).has_children()
45
46 #~ for cu in dwarfinfo._CU:
47 #~ print cu, cu.header
48
49
50
51
52 #~ print efile.get_section_by_name('.debug_info').name
53
54 #~ print '===> %s segments!' % efile.num_segments()
55
56 #~ for sec in efile.iter_sections():
57 #~ print type(sec), sec.name
58 #~ if isinstance(sec, SymbolTableSection):
59 #~ print ' linked string table:', sec.stringtable.name
60
61 #~ for seg in efile.iter_segments():
62 #~ print type(seg), seg['p_type'], seg['p_offset']
63
64 #~ for sec in efile.iter_sections():
65 #~ if isinstance(sec, SymbolTableSection):
66 #~ print 'symbol table "%s ~~~"' % sec.name
67 #~ for sym in sec.iter_symbols():
68 #~ print '%-26s %s %s' % (sym.name, sym['st_info']['type'], sym['st_info']['bind'])
69