get_string of StringTableSection return ascii-decoded strings now
authorJaySon-Huang <jayson.hjs@gmail.com>
Sun, 10 May 2015 17:30:49 +0000 (01:30 +0800)
committerJaySon-Huang <jayson.hjs@gmail.com>
Wed, 3 Jun 2015 13:52:48 +0000 (21:52 +0800)
fix bugs

13 files changed:
elftools/elf/dynamic.py
elftools/elf/elffile.py
elftools/elf/relocation.py
elftools/elf/sections.py
elftools/elf/segments.py
examples/elf_low_high_api.py
examples/elf_relocations.py
examples/elf_show_debug_sections.py
scripts/readelf.py
test/test_double_dynstr_section.py
test/test_get_symbol_by_name.py
test/test_gnuversions.py
test/test_solaris_support.py

index 0b3e3e99b9c110c47f210065a24d71f76e934ef1..dabf7d71ab1080addab2a98d6d6ea732f6613887 100644 (file)
@@ -115,7 +115,7 @@ class Dynamic(object):
 
         # That didn't work for some reason.  Let's use the section header
         # even though this ELF is super weird.
-        self._stringtable = self._elffile.get_section_by_name(b'.dynstr')
+        self._stringtable = self._elffile.get_section_by_name('.dynstr')
         return self._stringtable
 
     def _iter_tags(self, type=None):
index cbb1428bde2591a41d8ad0de122fee878e7c9d40..f9171dfdedcf5c0eb5c34d7420888beb2516cc73 100644 (file)
@@ -125,7 +125,7 @@ class ELFFile(object):
             We assume that if it has the debug_info section, it has all theother
             required sections as well.
         """
-        return bool(self.get_section_by_name(b'.debug_info'))
+        return bool(self.get_section_by_name('.debug_info'))
 
     def get_dwarf_info(self, relocate_dwarf_sections=True):
         """ Return a DWARFInfo object representing the debugging information in
@@ -139,9 +139,9 @@ class ELFFile(object):
         # Sections that aren't found will be passed as None to DWARFInfo.
         #
         debug_sections = {}
-        for secname in (b'.debug_info', b'.debug_abbrev', b'.debug_str',
-                        b'.debug_line', b'.debug_frame',
-                        b'.debug_loc', b'.debug_ranges'):
+        for secname in ('.debug_info', '.debug_abbrev', '.debug_str',
+                        '.debug_line', '.debug_frame',
+                        '.debug_loc', '.debug_ranges'):
             section = self.get_section_by_name(secname)
             if section is None:
                 debug_sections[secname] = None
@@ -155,15 +155,15 @@ class ELFFile(object):
                     little_endian=self.little_endian,
                     default_address_size=self.elfclass // 8,
                     machine_arch=self.get_machine_arch()),
-                debug_info_sec=debug_sections[b'.debug_info'],
-                debug_abbrev_sec=debug_sections[b'.debug_abbrev'],
-                debug_frame_sec=debug_sections[b'.debug_frame'],
+                debug_info_sec=debug_sections['.debug_info'],
+                debug_abbrev_sec=debug_sections['.debug_abbrev'],
+                debug_frame_sec=debug_sections['.debug_frame'],
                 # TODO(eliben): reading of eh_frame is not hooked up yet
                 eh_frame_sec=None,
-                debug_str_sec=debug_sections[b'.debug_str'],
-                debug_loc_sec=debug_sections[b'.debug_loc'],
-                debug_ranges_sec=debug_sections[b'.debug_ranges'],
-                debug_line_sec=debug_sections[b'.debug_line'])
+                debug_str_sec=debug_sections['.debug_str'],
+                debug_loc_sec=debug_sections['.debug_loc'],
+                debug_ranges_sec=debug_sections['.debug_ranges'],
+                debug_line_sec=debug_sections['.debug_line'])
 
     def get_machine_arch(self):
         """ Return the machine architecture, as detected from the ELF header.
index 9d9701ff68bf673982e19dff412bfadaceb65412..2b9a48bf1351cdf05fc109870261121c06b84cb2 100644 (file)
@@ -102,8 +102,8 @@ class RelocationHandler(object):
             found.
         """
         reloc_section_names = (
-                b'.rel' + section.name,
-                b'.rela' + section.name)
+                '.rel' + section.name,
+                '.rela' + section.name)
         # Find the relocation section aimed at this one. Currently assume
         # that either .rel or .rela section exists for this section, but
         # not both.
index b198868b1fccf1ba2dc09dbd9964a91cb0aba7b9..ea7abaf6269edee083a34f6c58b7cd3f77a7d860 100644 (file)
@@ -65,7 +65,7 @@ class StringTableSection(Section):
         """
         table_offset = self['sh_offset']
         s = parse_cstring_from_stream(self.stream, table_offset + offset)
-        return s
+        return s.decode('ascii')
 
 
 class SymbolTableSection(Section):
index 8b98def516a8c300e4e18d8b4ce8b14e83f341b6..15f9b0bbc89657860d5e9c632896a725d511e273 100644 (file)
@@ -92,7 +92,7 @@ class InterpSegment(Segment):
         """
         path_offset = self['p_offset']
         return struct_parse(
-            CString(''),
+            CString('', encoding='ascii'),
             self.stream,
             stream_pos=path_offset)
 
index e2d7f495bd745dfe277408f0d62f134d893edf1a..72b4daaabd856f91b465334ddf8f7d24b0926451 100644 (file)
@@ -61,10 +61,9 @@ def section_info_highlevel(stream):
     elffile = ELFFile(stream)
 
     # Just use the public methods of ELFFile to get what we need
-    # Note that section names, like everything read from the file, are bytes
-    # objects.
+    # Note that section names are strings.
     print('  %s sections' % elffile.num_sections())
-    section = elffile.get_section_by_name(b'.symtab')
+    section = elffile.get_section_by_name('.symtab')
 
     if not section:
         print('  No symbol table found. Perhaps this ELF has been stripped?')
@@ -72,10 +71,8 @@ def section_info_highlevel(stream):
 
     # A section type is in its header, but the name was decoded and placed in
     # a public attribute.
-    # bytes2str is used to print the name of the section for consistency of
-    # output between Python 2 and 3. The section name is a bytes object.
     print('  Section name: %s, type: %s' %(
-        bytes2str(section.name), section['sh_type']))
+        section.name, section['sh_type']))
 
     # But there's more... If this section is a symbol table section (which is
     # the case in the sample ELF file that comes with the examples), we can
@@ -84,7 +81,7 @@ def section_info_highlevel(stream):
         num_symbols = section.num_symbols()
         print("  It's a symbol section with %s symbols" % num_symbols)
         print("  The name of the last symbol in the section is: %s" % (
-            bytes2str(section.get_symbol(num_symbols - 1).name)))
+            section.get_symbol(num_symbols - 1).name))
 
 
 if __name__ == '__main__':
index 008626619f53b5eb2548698adc60804df9d9f548..70e8b3a029d364663a305bb03883241921afd6eb 100644 (file)
@@ -27,15 +27,15 @@ def process_file(filename):
 
         # Read the .rela.dyn section from the file, by explicitly asking
         # ELFFile for this section
-        # Recall that section names are bytes objects
-        reladyn_name = b'.rela.dyn'
+        # The section names are strings
+        reladyn_name = '.rela.dyn'
         reladyn = elffile.get_section_by_name(reladyn_name)
 
         if not isinstance(reladyn, RelocationSection):
-            print('  The file has no %s section' % bytes2str(reladyn_name))
+            print('  The file has no %s section' % reladyn_name)
 
         print('  %s section with %s relocations' % (
-            bytes2str(reladyn_name), reladyn.num_relocations()))
+            reladyn_name, reladyn.num_relocations()))
 
         for reloc in reladyn.iter_relocations():
             print('    Relocation (%s)' % 'RELA' if reloc.is_RELA() else 'REL')
index 4e4da61e259056edf6eebf6c287199592c992678..07202ce6ac944d2ffad531c5f431a81941ce69bc 100644 (file)
@@ -23,9 +23,9 @@ def process_file(filename):
         elffile = ELFFile(f)
 
         for section in elffile.iter_sections():
-            # Section names are bytes objects
-            if section.name.startswith(b'.debug'):
-                print('  ' + bytes2str(section.name))
+            # Section names are string
+            if section.name.startswith('.debug'):
+                print('  ' + section.name)
 
 
 if __name__ == '__main__':
index 02508d2caccbbd9ab2da90d78503b59cb2f119a5..6bcab9b6d685600b4789c711e6a25d6ed4b4f447 100755 (executable)
@@ -204,7 +204,7 @@ class ReadElf(object):
 
             if isinstance(segment, InterpSegment):
                 self._emitline('      [Requesting program interpreter: %s]' %
-                    bytes2str(segment.get_interp_name()))
+                    segment.get_interp_name())
 
         # Sections to segments mapping
         #
@@ -221,7 +221,7 @@ class ReadElf(object):
             for section in self.elffile.iter_sections():
                 if (    not section.is_null() and
                         segment.section_in_segment(section)):
-                    self._emit('%s ' % bytes2str(section.name))
+                    self._emit('%s ' % section.name)
 
             self._emitline('')
 
@@ -248,7 +248,7 @@ class ReadElf(object):
         #
         for nsec, section in enumerate(self.elffile.iter_sections()):
             self._emit('  [%2u] %-17.17s %-15.15s ' % (
-                nsec, bytes2str(section.name), describe_sh_type(section['sh_type'])))
+                nsec, section.name, describe_sh_type(section['sh_type'])))
 
             if self.elffile.elfclass == 32:
                 self._emitline('%s %s %s %s %3s %2s %3s %2s' % (
@@ -292,11 +292,11 @@ class ReadElf(object):
 
             if section['sh_entsize'] == 0:
                 self._emitline("\nSymbol table '%s' has a sh_entsize of zero!" % (
-                    bytes2str(section.name)))
+                    section.name))
                 continue
 
             self._emitline("\nSymbol table '%s' contains %s entries:" % (
-                bytes2str(section.name), section.num_symbols()))
+                section.name, section.num_symbols()))
 
             if self.elffile.elfclass == 32:
                 self._emitline('   Num:    Value  Size Type    Bind   Vis      Ndx Name')
@@ -310,7 +310,7 @@ class ReadElf(object):
                 if (section['sh_type'] == 'SHT_DYNSYM' and
                         self._versioninfo['type'] == 'GNU'):
                     version = self._symbol_version(nsym)
-                    if (version['name'] != bytes2str(symbol.name) and
+                    if (version['name'] != symbol.name and
                         version['index'] not in ('VER_NDX_LOCAL',
                                                  'VER_NDX_GLOBAL')):
                         if version['filename']:
@@ -333,7 +333,7 @@ class ReadElf(object):
                     describe_symbol_bind(symbol['st_info']['bind']),
                     describe_symbol_visibility(symbol['st_other']['visibility']),
                     describe_symbol_shndx(symbol['st_shndx']),
-                    bytes2str(symbol.name),
+                    symbol.name,
                     version_info))
 
     def display_dynamic_tags(self):
@@ -353,13 +353,13 @@ class ReadElf(object):
             padding = 20 + (8 if self.elffile.elfclass == 32 else 0)
             for tag in section.iter_tags():
                 if tag.entry.d_tag == 'DT_NEEDED':
-                    parsed = 'Shared library: [%s]' % bytes2str(tag.needed)
+                    parsed = 'Shared library: [%s]' % tag.needed
                 elif tag.entry.d_tag == 'DT_RPATH':
-                    parsed = 'Library rpath: [%s]' % bytes2str(tag.rpath)
+                    parsed = 'Library rpath: [%s]' % tag.rpath
                 elif tag.entry.d_tag == 'DT_RUNPATH':
-                    parsed = 'Library runpath: [%s]' % bytes2str(tag.runpath)
+                    parsed = 'Library runpath: [%s]' % tag.runpath
                 elif tag.entry.d_tag == 'DT_SONAME':
-                    parsed = 'Library soname: [%s]' % bytes2str(tag.soname)
+                    parsed = 'Library soname: [%s]' % tag.soname
                 elif tag.entry.d_tag.endswith(('SZ', 'ENT')):
                     parsed = '%i (bytes)' % tag['d_val']
                 elif tag.entry.d_tag.endswith(('NUM', 'COUNT')):
@@ -410,7 +410,7 @@ class ReadElf(object):
 
             has_relocation_sections = True
             self._emitline("\nRelocation section '%s' at offset %s contains %s entries:" % (
-                bytes2str(section.name),
+                section.name,
                 self._format_hex(section['sh_offset']),
                 section.num_relocations()))
             if section.is_RELA():
@@ -448,7 +448,7 @@ class ReadElf(object):
                         symbol['st_value'],
                         fullhex=True, lead0x=False),
                     '  ' if self.elffile.elfclass == 32 else '',
-                    bytes2str(symbol_name)))
+                    symbol_name))
                 if section.is_RELA():
                     self._emit(' %s %x' % (
                         '+' if rel['r_addend'] >= 0 else '-',
@@ -520,14 +520,14 @@ class ReadElf(object):
                             self._format_hex(offset, fieldsize=6,
                                              alternate=True),
                             verdef['vd_version'], flags, verdef['vd_ndx'],
-                            verdef['vd_cnt'], bytes2str(name)))
+                            verdef['vd_cnt'], name))
 
                     verdaux_offset = (
                             offset + verdef['vd_aux'] + verdaux['vda_next'])
                     for idx, verdaux in enumerate(verdaux_iter, start=1):
                         self._emitline('  %s: Parent %i: %s' %
                             (self._format_hex(verdaux_offset, fieldsize=4),
-                                              idx, bytes2str(verdaux.name)))
+                                              idx, verdaux.name))
                         verdaux_offset += verdaux['vda_next']
 
                     offset += verdef['vd_next']
@@ -541,7 +541,7 @@ class ReadElf(object):
                     self._emitline('  %s: Version: %i  File: %s  Cnt: %i' % (
                             self._format_hex(offset, fieldsize=6,
                                              alternate=True),
-                            verneed['vn_version'], bytes2str(verneed.name),
+                            verneed['vn_version'], verneed.name,
                             verneed['vn_cnt']))
 
                     vernaux_offset = offset + verneed['vn_aux']
@@ -556,7 +556,7 @@ class ReadElf(object):
                         self._emitline(
                             '  %s:   Name: %s  Flags: %s  Version: %i' % (
                                 self._format_hex(vernaux_offset, fieldsize=4),
-                                bytes2str(vernaux.name), flags,
+                                vernaux.name, flags,
                                 vernaux['vna_other']))
 
                         vernaux_offset += vernaux['vna_next']
@@ -573,7 +573,7 @@ class ReadElf(object):
                 section_spec))
             return
 
-        self._emitline("\nHex dump of section '%s':" % bytes2str(section.name))
+        self._emitline("\nHex dump of section '%s':" % section.name)
         self._note_relocs_for_section(section)
         addr = section['sh_addr']
         data = section.data()
@@ -616,7 +616,7 @@ class ReadElf(object):
                 section_spec))
             return
 
-        self._emitline("\nString dump of section '%s':" % bytes2str(section.name))
+        self._emitline("\nString dump of section '%s':" % section.name)
 
         found = False
         data = section.data()
@@ -717,7 +717,7 @@ class ReadElf(object):
             num_entries = version_section.num_symbols()
 
         self._emitline("\n%s section '%s' contains %s entries:" %
-            (name, bytes2str(version_section.name), num_entries))
+            (name, version_section.name, num_entries))
         self._emitline('%sAddr: %s  Offset: %s  Link: %i (%s)' % (
             ' ' * indent,
             self._format_hex(
@@ -725,8 +725,7 @@ class ReadElf(object):
             self._format_hex(
                 version_section['sh_offset'], fieldsize=6, lead0x=True),
             version_section['sh_link'],
-            bytes2str(
-                self.elffile.get_section(version_section['sh_link']).name)
+                self.elffile.get_section(version_section['sh_link']).name
             )
         )
 
@@ -785,12 +784,12 @@ class ReadElf(object):
                     index <= self._versioninfo['verdef'].num_versions()):
                 _, verdaux_iter = \
                         self._versioninfo['verdef'].get_version(index)
-                symbol_version['name'] = bytes2str(next(verdaux_iter).name)
+                symbol_version['name'] = next(verdaux_iter).name
             else:
                 verneed, vernaux = \
                         self._versioninfo['verneed'].get_version(index)
-                symbol_version['name'] = bytes2str(vernaux.name)
-                symbol_version['filename'] = bytes2str(verneed.name)
+                symbol_version['name'] = vernaux.name
+                symbol_version['filename'] = verneed.name
 
         symbol_version['index'] = index
         return symbol_version
@@ -807,7 +806,7 @@ class ReadElf(object):
                 return None
         except ValueError:
             # Not a number. Must be a name then
-            return self.elffile.get_section_by_name(str2bytes(spec))
+            return self.elffile.get_section_by_name(spec)
 
     def _note_relocs_for_section(self, section):
         """ If there are relocation sections pointing to the givne section,
index 307855446174f022aa32b34d856a5ca4739f1fde..5f0c42ef37a7262e2956dc98d9138eb5a6e1d2df 100644 (file)
@@ -22,9 +22,9 @@ class TestDoubleDynstrSections(unittest.TestCase):
     """
 
     reference_data = [
-        b'libz.so.1',
-        b'libc.so.6',
-        b'lib_versioned.so.1',
+        'libz.so.1',
+        'libc.so.6',
+        'lib_versioned.so.1',
     ]
 
     def _test_double_dynstr_section_generic(self, testfile):
index d5e7f440a84fdf75e37b351bf71d0d3b79a9b4ab..ce5370ecd42e26f17a4192dc1db357a8cde06c35 100644 (file)
@@ -16,18 +16,18 @@ class TestGetSymbolByName(unittest.TestCase):
             elf = ELFFile(f)
 
             # Find the symbol table.
-            symtab = elf.get_section_by_name(b'.symtab')
+            symtab = elf.get_section_by_name('.symtab')
             self.assertIsNotNone(symtab)
 
             # Test we can find a symbol by its name.
-            mains = symtab.get_symbol_by_name(b'main')
+            mains = symtab.get_symbol_by_name('main')
             self.assertIsNotNone(mains)
 
             # Test it is actually the symbol we expect.
             self.assertIsInstance(mains, list)
             self.assertEqual(len(mains), 1)
             main = mains[0]
-            self.assertEqual(main.name, b'main')
+            self.assertEqual(main.name, 'main')
             self.assertEqual(main['st_value'], 0x8068)
             self.assertEqual(main['st_size'], 0x28)
 
@@ -37,11 +37,11 @@ class TestGetSymbolByName(unittest.TestCase):
             elf = ELFFile(f)
 
             # Find the symbol table.
-            symtab = elf.get_section_by_name(b'.symtab')
+            symtab = elf.get_section_by_name('.symtab')
             self.assertIsNotNone(symtab)
 
             # Test we get None when we look up a symbol that doesn't exist.
-            undef = symtab.get_symbol_by_name(b'non-existent symbol')
+            undef = symtab.get_symbol_by_name('non-existent symbol')
             self.assertIsNone(undef)
 
     def test_duplicated_symbol(self):
@@ -50,7 +50,7 @@ class TestGetSymbolByName(unittest.TestCase):
             elf = ELFFile(f)
 
             # Find the symbol table.
-            symtab = elf.get_section_by_name(b'.symtab')
+            symtab = elf.get_section_by_name('.symtab')
             self.assertIsNotNone(symtab)
 
             # The '$a' symbols that are present in the test file.
@@ -58,12 +58,12 @@ class TestGetSymbolByName(unittest.TestCase):
                                 0x8068]
 
             # Test we get all expected instances of the symbol '$a'.
-            arm_markers = symtab.get_symbol_by_name(b'$a')
+            arm_markers = symtab.get_symbol_by_name('$a')
             self.assertIsNotNone(arm_markers)
             self.assertIsInstance(arm_markers, list)
             self.assertEqual(len(arm_markers), len(expected_symbols))
             for symbol in arm_markers:
-                self.assertEqual(symbol.name, b'$a')
+                self.assertEqual(symbol.name, '$a')
                 self.assertIn(symbol['st_value'], expected_symbols)
 
 if __name__ == '__main__':
index 8c1786a1faecdf769529108c75cc8c98ed6aba79..546e0c8ec1d85d115104e1b02e7bb4ab66085b79 100644 (file)
@@ -22,30 +22,30 @@ from elftools.elf.gnuversions import (
 class TestSymbolVersioning(unittest.TestCase):
 
     versym_reference_data = [
-        {'name': b'', 'ndx': 'VER_NDX_LOCAL'},
-        {'name': b'', 'ndx': 'VER_NDX_LOCAL'},
-        {'name': b'_ITM_deregisterTMCloneTable', 'ndx': 'VER_NDX_LOCAL'},
-        {'name': b'puts', 'ndx': 5},
-        {'name': b'strlcat', 'ndx': 'VER_NDX_LOCAL'},
-        {'name': b'__stack_chk_fail', 'ndx': 6},
-        {'name': b'__gmon_start__', 'ndx': 'VER_NDX_LOCAL'},
-        {'name': b'gzoffset', 'ndx': 7},
-        {'name': b'_Jv_RegisterClasses', 'ndx': 'VER_NDX_LOCAL'},
-        {'name': b'_ITM_registerTMCloneTable', 'ndx': 'VER_NDX_LOCAL'},
-        {'name': b'__cxa_finalize', 'ndx': 5},
-        {'name': b'_edata', 'ndx': 'VER_NDX_GLOBAL'},
-        {'name': b'VER_1.0', 'ndx': 2},
-        {'name': b'function1_ver1_1', 'ndx': 'VER_NDX_GLOBAL'},
-        {'name': b'_end', 'ndx': 'VER_NDX_GLOBAL'},
-        {'name': b'function1', 'ndx': 4 | 0x8000},
-        {'name': b'__bss_start', 'ndx': 'VER_NDX_GLOBAL'},
-        {'name': b'function1', 'ndx': 2},
-        {'name': b'VER_1.1', 'ndx': 3},
-        {'name': b'_init', 'ndx': 'VER_NDX_GLOBAL'},
-        {'name': b'function1_ver1_0', 'ndx': 'VER_NDX_GLOBAL'},
-        {'name': b'_fini', 'ndx': 'VER_NDX_GLOBAL'},
-        {'name': b'VER_1.2', 'ndx': 4},
-        {'name': b'function2', 'ndx': 3},
+        {'name': '', 'ndx': 'VER_NDX_LOCAL'},
+        {'name': '', 'ndx': 'VER_NDX_LOCAL'},
+        {'name': '_ITM_deregisterTMCloneTable', 'ndx': 'VER_NDX_LOCAL'},
+        {'name': 'puts', 'ndx': 5},
+        {'name': 'strlcat', 'ndx': 'VER_NDX_LOCAL'},
+        {'name': '__stack_chk_fail', 'ndx': 6},
+        {'name': '__gmon_start__', 'ndx': 'VER_NDX_LOCAL'},
+        {'name': 'gzoffset', 'ndx': 7},
+        {'name': '_Jv_RegisterClasses', 'ndx': 'VER_NDX_LOCAL'},
+        {'name': '_ITM_registerTMCloneTable', 'ndx': 'VER_NDX_LOCAL'},
+        {'name': '__cxa_finalize', 'ndx': 5},
+        {'name': '_edata', 'ndx': 'VER_NDX_GLOBAL'},
+        {'name': 'VER_1.0', 'ndx': 2},
+        {'name': 'function1_ver1_1', 'ndx': 'VER_NDX_GLOBAL'},
+        {'name': '_end', 'ndx': 'VER_NDX_GLOBAL'},
+        {'name': 'function1', 'ndx': 4 | 0x8000},
+        {'name': '__bss_start', 'ndx': 'VER_NDX_GLOBAL'},
+        {'name': 'function1', 'ndx': 2},
+        {'name': 'VER_1.1', 'ndx': 3},
+        {'name': '_init', 'ndx': 'VER_NDX_GLOBAL'},
+        {'name': 'function1_ver1_0', 'ndx': 'VER_NDX_GLOBAL'},
+        {'name': '_fini', 'ndx': 'VER_NDX_GLOBAL'},
+        {'name': 'VER_1.2', 'ndx': 4},
+        {'name': 'function2', 'ndx': 3},
     ]
 
     def test_versym_section(self):
@@ -69,13 +69,13 @@ class TestSymbolVersioning(unittest.TestCase):
                 self.assertEqual(versym['ndx'], ref_versym['ndx'])
 
     verneed_reference_data = [
-        {'name': b'libz.so.1', 'vn_version': 1, 'vn_cnt': 1,
+        {'name': 'libz.so.1', 'vn_version': 1, 'vn_cnt': 1,
          'vernaux': [
-            {'name': b'ZLIB_1.2.3.5', 'vna_flags': 0, 'vna_other': 7}]},
-        {'name': b'libc.so.6', 'vn_version': 1, 'vn_cnt': 2,
+            {'name': 'ZLIB_1.2.3.5', 'vna_flags': 0, 'vna_other': 7}]},
+        {'name': 'libc.so.6', 'vn_version': 1, 'vn_cnt': 2,
          'vernaux': [
-            {'name': b'GLIBC_2.4', 'vna_flags': 0, 'vna_other': 6},
-            {'name': b'GLIBC_2.2.5', 'vna_flags': 0, 'vna_other': 5}]},
+            {'name': 'GLIBC_2.4', 'vna_flags': 0, 'vna_other': 6},
+            {'name': 'GLIBC_2.2.5', 'vna_flags': 0, 'vna_other': 5}]},
         ]
 
     def test_verneed_section(self):
@@ -114,18 +114,18 @@ class TestSymbolVersioning(unittest.TestCase):
         {'vd_ndx': 1, 'vd_version': 1, 'vd_flags': VER_FLAGS.VER_FLG_BASE,
          'vd_cnt': 1,
          'verdaux': [
-            {'name': b'lib_versioned.so.1'}]},
+            {'name': 'lib_versioned.so.1'}]},
         {'vd_ndx': 2, 'vd_version': 1, 'vd_flags': 0, 'vd_cnt': 1,
          'verdaux': [
-            {'name': b'VER_1.0'}]},
+            {'name': 'VER_1.0'}]},
         {'vd_ndx': 3, 'vd_version': 1, 'vd_flags': 0, 'vd_cnt': 2,
          'verdaux': [
-            {'name': b'VER_1.1'},
-            {'name': b'VER_1.0'}]},
+            {'name': 'VER_1.1'},
+            {'name': 'VER_1.0'}]},
         {'vd_ndx': 4, 'vd_version': 1, 'vd_flags': 0, 'vd_cnt': 2,
          'verdaux': [
-            {'name': b'VER_1.2'},
-            {'name': b'VER_1.1'}]},
+            {'name': 'VER_1.2'},
+            {'name': 'VER_1.1'}]},
         ]
 
     def test_verdef_section(self):
index d243fe99789683d0fbe4d088d9eb2556067c5847..12410f04259d85fd045f994061d47e27a9a4f537 100644 (file)
@@ -22,7 +22,7 @@ class TestSolarisSupport(unittest.TestCase):
         with open(os.path.join('test', 'testfiles_for_unittests',
                                testfile), 'rb') as f:
             elf = ELFFile(f)
-            syminfo_section = elf.get_section_by_name(b'.SUNW_syminfo')
+            syminfo_section = elf.get_section_by_name('.SUNW_syminfo')
             self.assertIsNotNone(syminfo_section)
 
             # The test files were compiled against libc.so.1 with
@@ -31,7 +31,7 @@ class TestSolarisSupport(unittest.TestCase):
             # in the syminfo table.
             # We check that this is properly detected.
             exit_symbols = [s for s in syminfo_section.iter_symbols()
-                            if b'exit' in s.name]
+                            if 'exit' in s.name]
             self.assertNotEqual(len(exit_symbols), 0)
 
             for symbol in exit_symbols:
@@ -53,15 +53,15 @@ class TestSolarisSupport(unittest.TestCase):
     def test_SUNW_syminfo_section_sparc64(self):
         self._test_SUNW_syminfo_section_generic('exe_solaris64_cc.sparc.elf')
 
-    ldsynsym_reference_data = [b'', b'exe_solaris32.elf', b'crti.s', b'crt1.o',
-                               b'crt1.s', b'fsr.s', b'values-Xa.c',
-                               b'exe_solaris64.elf.c', b'crtn.s']
+    ldsynsym_reference_data = ['', 'exe_solaris32.elf', 'crti.s', 'crt1.o',
+                               'crt1.s', 'fsr.s', 'values-Xa.c',
+                               'exe_solaris64.elf.c', 'crtn.s']
 
     def _test_SUNW_ldynsym_section_generic(self, testfile, reference_data):
         with open(os.path.join('test', 'testfiles_for_unittests',
                                testfile), 'rb') as f:
             elf = ELFFile(f)
-            ldynsym_section = elf.get_section_by_name(b'.SUNW_ldynsym')
+            ldynsym_section = elf.get_section_by_name('.SUNW_ldynsym')
             self.assertIsNotNone(ldynsym_section)
 
             for symbol, ref_symbol_name in zip(
@@ -77,9 +77,9 @@ class TestSolarisSupport(unittest.TestCase):
     def test_SUNW_ldynsym_section_x64(self):
         reference_data = copy.deepcopy(
             TestSolarisSupport.ldsynsym_reference_data)
-        reference_data[1] = b'exe_solaris64.elf'
-        reference_data[3] = b'crt1x.o'
-        reference_data[5] = b'fsrx.s'
+        reference_data[1] = 'exe_solaris64.elf'
+        reference_data[3] = 'crt1x.o'
+        reference_data[5] = 'fsrx.s'
         self._test_SUNW_ldynsym_section_generic('exe_solaris64_cc.elf',
                                                 reference_data)