"""
table_offset = self['sh_offset']
s = parse_cstring_from_stream(self.stream, table_offset + offset)
- return s.decode('ascii') if s else ''
+ return s.decode('utf-8') if s else ''
class SymbolTableSection(Section):
elif self.tag in ('TAG_CPU_RAW_NAME', 'TAG_CPU_NAME', 'TAG_CONFORMANCE'):
self.value = struct_parse(structs.Elf_ntbs('value',
- encoding='ascii'),
+ encoding='utf-8'),
stream)
elif self.tag == 'TAG_COMPATIBILITY':
self.value = struct_parse(structs.Elf_uleb128('value'), stream)
self.extra = struct_parse(structs.Elf_ntbs('vendor_name',
- encoding='ascii'),
+ encoding='utf-8'),
stream)
elif self.tag == 'TAG_ALSO_COMPATIBLE_WITH':
"""
path_offset = self['p_offset']
return struct_parse(
- CString('', encoding='ascii'),
+ CString('', encoding='utf-8'),
self.stream,
stream_pos=path_offset)
self.Elf_Attr_Subsection_Header = Struct('Elf_Attr_Subsection',
self.Elf_word('length'),
self.Elf_ntbs('vendor_name',
- encoding='ascii')
+ encoding='utf-8')
)
# Structure of a build attribute tag.
--- /dev/null
+# coding: utf-8
+#-------------------------------------------------------------------------------
+# elftools tests
+#
+# Audrey Dutcher (audrey@rhelmot.io)
+# Eli Bendersky (eliben@gmail.com)
+# This code is in the public domain
+#-------------------------------------------------------------------------------
+
+from __future__ import unicode_literals
+import unittest
+import os
+
+from elftools.elf.elffile import ELFFile
+
+class TestUnicodeSymbols(unittest.TestCase):
+ """Test that we can handle a unicode symbol as produced by clang"""
+
+ def test_delta(self):
+ fname = os.path.join('test', 'testfiles_for_unittests',
+ 'unicode_symbols.elf')
+
+ with open(fname, 'rb') as f:
+ elf = ELFFile(f)
+ symtab = elf.get_section_by_name('.symtab')
+ list(symtab.iter_symbols()) # this used to just fail
+ self.assertEqual(len(symtab.get_symbol_by_name('Δ')), 1)
+
+if __name__ == '__main__':
+ unittest.main()