Implemented ELFFile.get_section_by_name and changed readelf.py to use it
[pyelftools.git] / z.py
1 # Just a script for playing around with pyelftools during testing
2 # please ignore it!
3 #
4
5 import sys
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
18 print '===> %s sections!' % efile.num_sections()
19
20 print efile.get_section_by_name('.debug_info').name
21
22 #~ print '===> %s segments!' % efile.num_segments()
23
24 for sec in efile.iter_sections():
25 print type(sec), sec.name
26 if isinstance(sec, SymbolTableSection):
27 print ' linked string table:', sec.stringtable.name
28
29 #~ for seg in efile.iter_segments():
30 #~ print type(seg), seg['p_type'], seg['p_offset']
31
32 #~ for sec in efile.iter_sections():
33 #~ if isinstance(sec, SymbolTableSection):
34 #~ print 'symbol table "%s ~~~"' % sec.name
35 #~ for sym in sec.iter_symbols():
36 #~ print '%-26s %s %s' % (sym.name, sym['st_info']['type'], sym['st_info']['bind'])
37