+#-------------------------------------------------------------------------------
+# elftools
+#
+# Eli Bendersky (eliben@gmail.com)
+# This code is in the public domain
+#-------------------------------------------------------------------------------
+
# Just a script for playing around with pyelftools during testing
# please ignore it!
#
+from __future__ import print_function
-import sys
+import sys, pprint
from elftools.elf.structs import ELFStructs
from elftools.elf.elffile import ELFFile
from elftools.elf.sections import *
-# read a little-endian, 64-bit file
-es = ELFStructs(True, 64)
-
-stream = open('tests/testfiles/z.elf', 'rb')
-#stream = open('binfiles/z32.elf', 'rb')
-
-efile = ELFFile(stream)
-
-print '===> %s sections!' % efile.num_sections()
+from elftools.elf.relocation import *
-print efile.get_section_by_name('.debug_info').name
-#~ print '===> %s segments!' % efile.num_segments()
+stream = open('test/testfiles/exe_simple64.elf', 'rb')
-for sec in efile.iter_sections():
- print type(sec), sec.name
- if isinstance(sec, SymbolTableSection):
- print ' linked string table:', sec.stringtable.name
-
-#~ for seg in efile.iter_segments():
- #~ print type(seg), seg['p_type'], seg['p_offset']
+efile = ELFFile(stream)
+print('elfclass', efile.elfclass)
+print('===> %s sections!' % efile.num_sections())
+print(efile.header)
+
+dinfo = efile.get_dwarf_info()
+from elftools.dwarf.locationlists import LocationLists
+from elftools.dwarf.descriptions import describe_DWARF_expr
+llists = LocationLists(dinfo.debug_loc_sec.stream, dinfo.structs)
+for loclist in llists.iter_location_lists():
+ print('----> loclist!')
+ for li in loclist:
+ print(li)
+ print(describe_DWARF_expr(li.loc_expr, dinfo.structs))
-#~ for sec in efile.iter_sections():
- #~ if isinstance(sec, SymbolTableSection):
- #~ print 'symbol table "%s ~~~"' % sec.name
- #~ for sym in sec.iter_symbols():
- #~ print '%-26s %s %s' % (sym.name, sym['st_info']['type'], sym['st_info']['bind'])