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/z.elf', 'rb')
14 #stream = open('binfiles/z32.elf', 'rb')
16 efile
= ELFFile(stream
)
17 print efile
.elfclass
, efile
.little_endian
18 print '===> %s sections!' % efile
.num_sections()
20 print efile
.has_dwarf_info()
22 dwarfinfo
= efile
.get_dwarf_info()
24 #~ print dwarfinfo.structs.Dwarf_abbrev_entry.parse('\x13\x01\x01\x03\x50\x04\x00\x00')
26 print id(dwarfinfo
.get_abbrev_table(0))
27 print id(dwarfinfo
.get_abbrev_table(0))
28 pprint
.pprint(dwarfinfo
.get_abbrev_table(0)._abbrev
_map
)
30 print dwarfinfo
.get_abbrev_table(0).get_abbrev(1).decl
31 print dwarfinfo
.get_abbrev_table(0).get_abbrev(1).has_children()
33 #~ for cu in dwarfinfo._CU:
34 #~ print cu, cu.header
39 #~ print efile.get_section_by_name('.debug_info').name
41 #~ print '===> %s segments!' % efile.num_segments()
43 #~ for sec in efile.iter_sections():
44 #~ print type(sec), sec.name
45 #~ if isinstance(sec, SymbolTableSection):
46 #~ print ' linked string table:', sec.stringtable.name
48 #~ for seg in efile.iter_segments():
49 #~ print type(seg), seg['p_type'], seg['p_offset']
51 #~ for sec in efile.iter_sections():
52 #~ if isinstance(sec, SymbolTableSection):
53 #~ print 'symbol table "%s ~~~"' % sec.name
54 #~ for sym in sec.iter_symbols():
55 #~ print '%-26s %s %s' % (sym.name, sym['st_info']['type'], sym['st_info']['bind'])