+import sys\r
from elftools.elf.structs import ELFStructs\r
\r
+# read a little-endian, 64-bit file\r
es = ELFStructs(True, 64)\r
\r
-\r
stream = open('binfiles/z.elf', 'rb')\r
-print es.Elf_Ehdr.parse_stream(stream)\r
+eheader = es.Elf_Ehdr.parse_stream(stream)\r
+\r
+print eheader\r
+\r
+shtable_offset = eheader.e_shoff\r
+strtable_section_offset = shtable_offset + eheader.e_shstrndx * eheader.e_shentsize\r
+\r
+# get to the section header for the sh string table\r
+print strtable_section_offset\r
+stream.seek(strtable_section_offset)\r
+sheader = es.Elf_Shdr.parse_stream(stream)\r
+print sheader\r
+\r
+# yay, looks correct!!\r
+stream.seek(sheader.sh_offset)\r
+buf = stream.read(sheader.sh_size)\r
+for c in buf:\r
+ sys.stdout.write('%02X' % ord(c))\r
+\r
+\r
\r
\r
#~ print es.Elf_Ehdr\r