blob: b16ef690e7232b9723a2a95fc88515b5b2bc1eec [file] [log] [blame]
Eli Benderskyc4a4c072011-09-17 15:28:28 +03001# Just a script for playing around with pyelftools during testing
2# please ignore it!
3#
4
Eli Benderskye0735d52011-09-08 20:12:44 +03005import sys
6from elftools.elf.structs import ELFStructs
7from elftools.elf.elffile import ELFFile
8from elftools.elf.sections import *
9
10# read a little-endian, 64-bit file
11es = ELFStructs(True, 64)
12
eliben44556512011-09-19 12:54:32 +030013stream = open('tests/testfiles/z.elf', 'rb')
Eli Benderskye0735d52011-09-08 20:12:44 +030014#stream = open('binfiles/z32.elf', 'rb')
15
16efile = ELFFile(stream)
eliben033b44f2011-09-19 15:48:39 +030017print efile.elfclass, efile.little_endian
Eli Benderskye0735d52011-09-08 20:12:44 +030018print '===> %s sections!' % efile.num_sections()
eliben54e39b22011-09-19 13:10:57 +030019
eliben033b44f2011-09-19 15:48:39 +030020print efile.has_dwarf_info()
21
elibence5ec712011-09-20 10:20:32 +030022dwarfinfo = efile.get_dwarf_info()
23print dwarfinfo
24for cu in dwarfinfo._CU:
25 print cu, cu.header
eliben033b44f2011-09-19 15:48:39 +030026
27
28#~ print efile.get_section_by_name('.debug_info').name
eliben54e39b22011-09-19 13:10:57 +030029
30#~ print '===> %s segments!' % efile.num_segments()
Eli Benderskye0735d52011-09-08 20:12:44 +030031
eliben033b44f2011-09-19 15:48:39 +030032#~ for sec in efile.iter_sections():
33 #~ print type(sec), sec.name
34 #~ if isinstance(sec, SymbolTableSection):
35 #~ print ' linked string table:', sec.stringtable.name
Eli Benderskye0735d52011-09-08 20:12:44 +030036
eliben54e39b22011-09-19 13:10:57 +030037#~ for seg in efile.iter_segments():
38 #~ print type(seg), seg['p_type'], seg['p_offset']
Eli Benderskye0735d52011-09-08 20:12:44 +030039
eliben54e39b22011-09-19 13:10:57 +030040#~ for sec in efile.iter_sections():
41 #~ if isinstance(sec, SymbolTableSection):
42 #~ print 'symbol table "%s ~~~"' % sec.name
43 #~ for sym in sec.iter_symbols():
44 #~ print '%-26s %s %s' % (sym.name, sym['st_info']['type'], sym['st_info']['bind'])
Eli Benderskya42f82d2011-09-09 06:02:47 +030045