# and strings are different types and bytes hold numeric values when
# iterated over.
+ def bytes2hex(b): return b.hex()
def bytes2str(b): return b.decode('latin-1')
def str2bytes(s): return s.encode('latin-1')
def int2byte(i): return bytes((i,))
import cStringIO
StringIO = BytesIO = cStringIO.StringIO
+ def bytes2hex(b): return b.encode('hex')
def bytes2str(b): return b
def str2bytes(s): return s
int2byte = chr
ENUM_RELOC_TYPE_MIPS, ENUM_ATTR_TAG_ARM, ENUM_DT_FLAGS, ENUM_DT_FLAGS_1)
from .constants import (
P_FLAGS, RH_FLAGS, SH_FLAGS, SUNW_SYMINFO_FLAGS, VER_FLAGS)
-from ..common.py3compat import iteritems
+from ..common.py3compat import bytes2hex, iteritems
def describe_ei_class(x):
desc = ''
if x['n_type'] == 'NT_GNU_ABI_TAG':
if x['n_name'] == 'Android':
- desc = '\n description data: %s ' % ' '.join("%02x" % ord(b) for b in x['n_descdata'])
+ desc = '\n description data: %s ' % bytes2hex(x['n_descdata'])
else:
desc = '\n OS: %s, ABI: %d.%d.%d' % (
_DESCR_NOTE_ABI_TAG_OS.get(n_desc['abi_os'], _unknown),
elif x['n_type'] == 'NT_GNU_GOLD_VERSION':
desc = '\n Version: %s' % (n_desc)
else:
- desc = '\n description data: {}'.format(' '.join(
- '{:02x}'.format(ord(byte)) for byte in n_desc
- ))
+ desc = '\n description data: {}'.format(bytes2hex(n_desc))
if x['n_type'] == 'NT_GNU_ABI_TAG' and x['n_name'] == 'Android':
note_type = 'NT_VERSION'
# Eli Bendersky (eliben@gmail.com)
# This code is in the public domain
#-------------------------------------------------------------------------------
-from ..common.py3compat import bytes2str
+from ..common.py3compat import bytes2hex, bytes2str
from ..common.utils import struct_parse, roundup
from ..construct import CString
CString('').parse(elffile.stream.read(disk_namesz)))
offset += disk_namesz
- desc_data = bytes2str(elffile.stream.read(note['n_descsz']))
+ desc_data = elffile.stream.read(note['n_descsz'])
note['n_descdata'] = desc_data
if note['n_type'] == 'NT_GNU_ABI_TAG':
note['n_desc'] = struct_parse(elffile.structs.Elf_abi,
elffile.stream,
offset)
elif note['n_type'] == 'NT_GNU_BUILD_ID':
- note['n_desc'] = ''.join('%.2x' % ord(b) for b in desc_data)
+ note['n_desc'] = bytes2hex(desc_data)
+ elif note['n_type'] == 'NT_GNU_GOLD_VERSION':
+ note['n_desc'] = bytes2str(desc_data)
elif note['n_type'] == 'NT_PRPSINFO':
note['n_desc'] = struct_parse(elffile.structs.Elf_Prpsinfo,
elffile.stream,
from elftools.elf.elffile import ELFFile
from elftools.elf.sections import NoteSection
+from elftools.common.py3compat import bytes2hex
def process_file(filename):
desc['abi_major'],
desc['abi_minor'],
desc['abi_tiny']))
- elif note['n_type'] == 'NT_GNU_BUILD_ID':
+ elif note['n_type'] in {'NT_GNU_BUILD_ID', 'NT_GNU_GOLD_VERSION'}:
print(' Desc:', desc)
else:
- print(' Desc:', ''.join('%.2x' % ord(b) for b in desc))
+ print(' Desc:', bytes2hex(desc))
if __name__ == '__main__':