# and strings are different types and bytes hold numeric values when
# iterated over.
- def bytes2hex(b, sep=''):
- if not sep:
- return b.hex()
- return sep.join(map('{:02x}'.format, b))
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
- def iterbytes(b):
- """Return an iterator over the elements of a bytes object.
-
- For example, for b'abc' yields b'a', b'b' and then b'c'.
- """
- for i in range(len(b)):
- yield b[i:i+1]
-
- ifilter = filter
-
maxint = sys.maxsize
def path_to_posix(s):
StringIO = BytesIO = cStringIO.StringIO
- def bytes2hex(b, sep=''):
- res = b.encode('hex')
- if not sep:
- return res
- return sep.join(res[i:i+2] for i in range(0, len(res), 2))
-
def bytes2str(b): return b
def str2bytes(s): return s
int2byte = chr
def iterbytes(b):
return iter(b)
- from itertools import ifilter
-
maxint = sys.maxint
def path_to_posix(s):
file.write(data)
stream.seek(pos, os.SEEK_SET)
+def iterbytes(b):
+ """Return an iterator over the elements of a bytes object.
+
+ For example, for b'abc' yields b'a', b'b' and then b'c'.
+ """
+ for i in range(len(b)):
+ yield b[i:i+1]
+
+def bytes2hex(b, sep=''):
+ if not sep:
+ return b.hex()
+ return sep.join(map('{:02x}'.format, b))
+
#------------------------- PRIVATE -------------------------
def _assert_with_exception(cond, msg, exception_type):
#-------------------------------------------------------------------------------
import copy
from collections import namedtuple
-from ..common.utils import (struct_parse, dwarf_assert, preserve_stream_pos)
-from ..common.py3compat import iterbytes
+from ..common.utils import (
+ struct_parse, dwarf_assert, preserve_stream_pos, iterbytes)
from ..construct import Struct, Switch
from .enums import DW_EH_encoding_flags
from .structs import DWARFStructs
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 bytes2hex
+from ..common.utils import bytes2hex
def describe_ei_class(x):
# Eli Bendersky (eliben@gmail.com)
# This code is in the public domain
#-------------------------------------------------------------------------------
-from ..common.py3compat import bytes2hex, bytes2str
-from ..common.utils import struct_parse, roundup
+from ..common.py3compat import bytes2str
+from ..common.utils import struct_parse, bytes2hex, roundup
from ..construct import CString
from elftools.elf.elffile import ELFFile
from elftools.elf.sections import NoteSection
-from elftools.common.py3compat import bytes2hex
+from elftools.common.utils import bytes2hex
def process_file(filename):
from elftools import __version__
from elftools.common.exceptions import ELFError
from elftools.common.py3compat import (
- ifilter, byte2int, bytes2str, str2bytes, iterbytes)
+ byte2int, bytes2str, str2bytes)
+from elftools.common.utils import iterbytes
from elftools.elf.elffile import ELFFile
from elftools.elf.dynamic import DynamicSection, DynamicSegment
from elftools.elf.enums import ENUM_D_TAG
# registers are sorted by their number, and the register matching
# ra_regnum is always listed last with a special heading.
decoded_table = entry.get_decoded()
- reg_order = sorted(ifilter(
+ reg_order = sorted(filter(
lambda r: r != ra_regnum,
decoded_table.reg_order))
if len(decoded_table.reg_order):