blob: 6fc8ff6d739a1ad3c3db6d82bd98389f93b27868 [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
22print efile.get_dwarf_info()
23
24
25#~ print efile.get_section_by_name('.debug_info').name
eliben54e39b22011-09-19 13:10:57 +030026
27#~ print '===> %s segments!' % efile.num_segments()
Eli Benderskye0735d52011-09-08 20:12:44 +030028
eliben033b44f2011-09-19 15:48:39 +030029#~ for sec in efile.iter_sections():
30 #~ print type(sec), sec.name
31 #~ if isinstance(sec, SymbolTableSection):
32 #~ print ' linked string table:', sec.stringtable.name
Eli Benderskye0735d52011-09-08 20:12:44 +030033
eliben54e39b22011-09-19 13:10:57 +030034#~ for seg in efile.iter_segments():
35 #~ print type(seg), seg['p_type'], seg['p_offset']
Eli Benderskye0735d52011-09-08 20:12:44 +030036
eliben54e39b22011-09-19 13:10:57 +030037#~ for sec in efile.iter_sections():
38 #~ if isinstance(sec, SymbolTableSection):
39 #~ print 'symbol table "%s ~~~"' % sec.name
40 #~ for sym in sec.iter_symbols():
41 #~ print '%-26s %s %s' % (sym.name, sym['st_info']['type'], sym['st_info']['bind'])
Eli Benderskya42f82d2011-09-09 06:02:47 +030042