Remove int2byte and byte2int utilities from py3compat
[pyelftools.git] / z.py
diff --git a/z.py b/z.py
index 8bf4743f32bbbf87abf7843f1a38af90f6c058a1..18f7d35b844d2585e3905c8e21ca03e95d4952d3 100644 (file)
--- a/z.py
+++ b/z.py
@@ -1,38 +1,38 @@
+#-------------------------------------------------------------------------------
+# 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, pprint
 from elftools.elf.structs import ELFStructs
 from elftools.elf.elffile import ELFFile
 from elftools.elf.sections import *
 
-from elftools.dwarf.dwarfrelocationmanager import DWARFRelocationManager
+from elftools.elf.relocation import *
 
-# read a little-endian, 64-bit file
-es = ELFStructs(True, 64)
 
-stream = open('tests/testfiles/penalty_64.o.elf', 'rb')
-#stream = open('binfiles/z32.elf', 'rb')
+stream = open('test/testfiles/exe_simple64.elf', 'rb')
 
 efile = ELFFile(stream)
-print 'elfclass', efile.elfclass
-print '===> %s sections!' % efile.num_sections() 
-
-#~ print efile.has_dwarf_info()
-
-dwarfinfo = efile.get_dwarf_info()
-print dwarfinfo.get_string_from_table(0x4bc0)
-cu = dwarfinfo.get_CU(0)
-
-print cu.structs.Dwarf_dw_form['DW_FORM_strp'].parse('\x01\x00\x00\x00\x01\x00\x00\x00')
-print 'CU header', cu.header
-topdie = cu.get_top_DIE()
-
-print topdie
-dinfo_sec = efile.get_section_by_name('.debug_info')
-relman = DWARFRelocationManager(efile, dinfo_sec.name)
+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))
 
-print relman._reloc_section.name, relman._reloc_section['sh_offset']
-#pprint.pprint(relman._relocs)