<commit_before>import logging
l = logging.getLogger("angr.block")

import pyvex
from archinfo import ArchARM
from .engines import SimEngineVEX

DEFAULT_VEX_ENGINE = SimEngineVEX(None)  # this is only used when Block is not initialized with a project


class Block(object):
    BLOCK_MAX_SIZE = 4096

    __slots__ = ['_project', '_bytes', '_vex', 'thumb', '_capstone', 'addr', 'size', 'arch', 'instructions',
                 '_instruction_addrs', '_opt_level'
                 ]

    def __init__(self, addr, project=None, arch=None, size=None, byte_string=None, vex=None, thumb=False, backup_state=None,
                 opt_level=None, num_inst=None, traceflags=0):

        # set up arch
        if project is not None:
            self.arch = project.arch
        else:
            self.arch = arch

        if self.arch is None:
            raise ValueError('Either "project" or "arch" has to be specified.')

        if isinstance(self.arch, ArchARM):
            if addr & 1 == 1:
                thumb = True
            if thumb:
                addr |= 1
        else:
            thumb = False

        self._project = project
        self.thumb = thumb
        self.addr = addr
        self._opt_level = opt_level

        if self._project is None and byte_string is None:
            raise ValueError('"byte_string" has to be specified if "project" is not provided.')

        if size is None:
            if byte_string is not None:
                size = len(byte_string)
            elif vex is not None:
                size = vex.size
            else:
                vex = self._vex_engine.lift(
                        clemory=project.loader.memory,
                        state=backup_state,
                        insn_bytes=byte_string,
                        addr=addr,
                        thumb=thumb,
                        opt_level=opt_level,
                        num_inst=num_inst,
                        traceflags=traceflags)
                size = vex.size

        self._vex = vex
        self._capstone = None
        self.size = size

        self.instructions = num_inst
        self._instruction_addrs = []

        self._parse_vex_info()

        if byte_string is None:
            if backup_state is not None:
                self._bytes = self._vex_engine._load_bytes(addr - thumb, size, state=backup_state)[0]
                if type(self._bytes) is not str:
                    self._bytes = str(pyvex.ffi.buffer(self._bytes, size))
            else:
                self._bytes = None
        elif type(byte_string) is str:
            if self.size is not None:
                self._bytes = byte_string[:self.size]
            else:
                self._bytes = byte_string<commit_msg>Make archinfo py3k compatible (#950)<commit_after>import logging
l = logging.getLogger("angr.block")

import pyvex
from archinfo import ArchARM
from .engines import SimEngineVEX

DEFAULT_VEX_ENGINE = SimEngineVEX(None)  # this is only used when Block is not initialized with a project


class Block(object):
    BLOCK_MAX_SIZE = 4096

    __slots__ = ['_project', '_bytes', '_vex', 'thumb', '_capstone', 'addr', 'size', 'arch', 'instructions',
                 '_instruction_addrs', '_opt_level'
                 ]

    def __init__(self, addr, project=None, arch=None, size=None, byte_string=None, vex=None, thumb=False, backup_state=None,
                 opt_level=None, num_inst=None, traceflags=0):

        # set up arch
        if project is not None:
            self.arch = project.arch
        else:
            self.arch = arch

        if self.arch is None:
            raise ValueError('Either "project" or "arch" has to be specified.')

        if isinstance(self.arch, ArchARM):
            if addr & 1 == 1:
                thumb = True
            if thumb:
                addr |= 1
        else:
            thumb = False

        self._project = project
        self.thumb = thumb
        self.addr = addr
        self._opt_level = opt_level

        if self._project is None and byte_string is None:
            raise ValueError('"byte_string" has to be specified if "project" is not provided.')

        if size is None:
            if byte_string is not None:
                size = len(byte_string)
            elif vex is not None:
                size = vex.size
            else:
                vex = self._vex_engine.lift(
                        clemory=project.loader.memory,
                        state=backup_state,
                        insn_bytes=byte_string,
                        addr=addr,
                        thumb=thumb,
                        opt_level=opt_level,
                        num_inst=num_inst,
                        traceflags=traceflags)
                size = vex.size

        self._vex = vex
        self._capstone = None
        self.size = size

        self.instructions = num_inst
        self._instruction_addrs = []

        self._parse_vex_info()

        if byte_string is None:
            if backup_state is not None:
                self._bytes = self._vex_engine._load_bytes(addr - thumb, size, state=backup_state)[0]
                if type(self._bytes) is not str:
                    self._bytes = str(pyvex.ffi.buffer(self._bytes, size))
            else:
                self._bytes = None
        elif type(byte_string) is bytes:
            if self.size is not None:
                self._bytes = byte_string[:self.size]
            else:
                self._bytes = byte_string
{'fraction_non_alphanumeric': 0.08177697189483228, 'fraction_numerical': 0.003989120580235721, 'mean_word_length': 1.5572554473806213, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2040090', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1444, 'n_words': 415}