Fix formatting of some dynamic tag fields to match readelf
[pyelftools.git] / examples / elf_relocations.py
index 181759506d560c0645f6ee0a018f56ba686e4518..fd65541954c70119a2621a11f3bf244d61ea5e1b 100644 (file)
@@ -17,6 +17,7 @@ try:
 except ImportError:
     sys.path.extend(['.', '..'])
 
+from elftools.common.py3compat import bytes2str
 from elftools.elf.elffile import ELFFile
 from elftools.elf.relocation import RelocationSection
 
@@ -28,14 +29,15 @@ def process_file(filename):
 
         # Read the .rela.dyn section from the file, by explicitly asking
         # ELFFile for this section
-        reladyn_name = '.rela.dyn'
+        # Recall that section names are bytes objects
+        reladyn_name = b'.rela.dyn'
         reladyn = elffile.get_section_by_name(reladyn_name)
 
         if not isinstance(reladyn, RelocationSection):
-            print('  The file has no %s section' % reladyn_name)
+            print('  The file has no %s section' % bytes2str(reladyn_name))
 
         print('  %s section with %s relocations' % (
-            reladyn_name, reladyn.num_relocations()))
+            bytes2str(reladyn_name), reladyn.num_relocations()))
 
         for reloc in reladyn.iter_relocations():
             print('    Relocation (%s)' % 'RELA' if reloc.is_RELA() else 'REL')