def bytes2str(b): return b.decode('latin-1')
def str2bytes(s): return s.encode('latin-1')
- def int2byte(i): return bytes((i,))
- def byte2int(b): return b
-
-else:
- def bytes2str(b): return b
- def str2bytes(s): return s
- int2byte = chr
- byte2int = ord
- def iterbytes(b):
- return iter(b)
#-------------------------------------------------------------------------------
from contextlib import contextmanager
from .exceptions import ELFParseError, ELFError, DWARFError
-from .py3compat import int2byte
from ..construct import ConstructError, ULInt8
import os
""" Convert a list of byte values (e.g. [0x10 0x20 0x00]) to a bytes object
(e.g. b'\x10\x20\x00').
"""
- return b''.join(int2byte(b) for b in bytelist)
+ return b''.join(bytes((b,)) for b in bytelist)
def struct_parse(struct, stream, stream_pos=None):
from elftools import __version__
from elftools.common.exceptions import ELFError
from elftools.common.py3compat import (
- byte2int, bytes2str, str2bytes)
+ bytes2str, str2bytes)
from elftools.common.utils import iterbytes
from elftools.elf.elffile import ELFFile
from elftools.elf.dynamic import DynamicSection, DynamicSegment
"""
self._emitline('ELF Header:')
self._emit(' Magic: ')
- self._emit(' '.join('%2.2x' % byte2int(b)
+ self._emit(' '.join('%2.2x' % b
for b in self.elffile.e_ident_raw))
self._emitline(' ')
header = self.elffile.header
self._emit(' %s ' % self._format_hex(addr, fieldsize=8))
for i in range(16):
if i < linebytes:
- self._emit('%2.2x' % byte2int(data[dataptr + i]))
+ self._emit('%2.2x' % data[dataptr + i])
else:
self._emit(' ')
if i % 4 == 3:
for i in range(linebytes):
c = data[dataptr + i : dataptr + i + 1]
- if byte2int(c[0]) >= 32 and byte2int(c[0]) < 0x7f:
+ if c[0] >= 32 and c[0] < 0x7f:
self._emit(bytes2str(c))
else:
self._emit(bytes2str(b'.'))
while dataptr < len(data):
while ( dataptr < len(data) and
- not (32 <= byte2int(data[dataptr]) <= 127)):
+ not (32 <= data[dataptr] <= 127)):
dataptr += 1
if dataptr >= len(data):
break
endptr = dataptr
- while endptr < len(data) and byte2int(data[endptr]) != 0:
+ while endptr < len(data) and data[endptr] != 0:
endptr += 1
found = True
from io import BytesIO
from random import randint
-from elftools.common.py3compat import int2byte
from elftools.common.utils import (parse_cstring_from_stream, merge_dicts,
preserve_stream_pos)
class Test_parse_cstring_from_stream(unittest.TestCase):
def _make_random_bytes(self, n):
- return b''.join(int2byte(randint(32, 127)) for i in range(n))
+ return b''.join(bytes((randint(32, 127),)) for i in range(n))
def test_small1(self):
sio = BytesIO(b'abcdefgh\x0012345')