* also create other stuff in struct constructor
[pyelftools.git] / z.py
1 import sys
2 from elftools.elf.structs import ELFStructs
3
4 # read a little-endian, 64-bit file
5 es = ELFStructs(True, 64)
6
7 stream = open('binfiles/z.elf', 'rb')
8 eheader = es.Elf_Ehdr.parse_stream(stream)
9
10 print eheader
11
12 shtable_offset = eheader.e_shoff
13 strtable_section_offset = shtable_offset + eheader.e_shstrndx * eheader.e_shentsize
14
15 # get to the section header for the sh string table
16 print strtable_section_offset
17 stream.seek(strtable_section_offset)
18 sheader = es.Elf_Shdr.parse_stream(stream)
19 print sheader
20
21 # yay, looks correct!!
22 stream.seek(sheader.sh_offset)
23 buf = stream.read(sheader.sh_size)
24 for c in buf:
25 sys.stdout.write('%02X' % ord(c))
26
27
28
29
30 #~ print es.Elf_Ehdr