How to use the archinfo.archerror.ArchError function in archinfo

To help you get started, we’ve selected a few archinfo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github angr / archinfo / archinfo / arch_s390x.py View on Github external
def __init__(self, endness=Endness.BE):
        super(ArchS390X, self).__init__(endness)
        if endness != Endness.BE:
            raise ArchError('Arch s390x must be big endian')
        self.argument_register_positions = {
            self.registers['r2'][0]: 0,
            self.registers['r3'][0]: 1,
            self.registers['r4'][0]: 2,
            self.registers['r5'][0]: 3,
            self.registers['r6'][0]: 4,
            # fp registers
            self.registers['f0'][0]: 0,
            self.registers['f2'][0]: 1,
            self.registers['f4'][0]: 2,
            self.registers['f6'][0]: 3,
        } if _pyvex is not None else None
github angr / archinfo / archinfo / arch_x86.py View on Github external
"""
        Compile the assembly instruction represented by string using Keystone

        :param string:      The textual assembly instructions, separated by semicolons
        :param addr:        The address at which the text should be assembled, to deal with PC-relative access. Default 0
        :param as_bytes:    Set to False to return a list of integers instead of a python byte string
        :param thumb:       If working with an ARM processor, set to True to assemble in thumb mode.
        :return:            The assembled bytecode
        """
        if thumb is True:
            l.warning("Specified thumb=True on non-ARM architecture")
        if _keystone is None:
            l.warning("Keystone is not found!")
            return None
        if self.ks_arch is None:
            raise ArchError("Arch %s does not support assembly with Keystone" % self.name)
        if self._ks is None:
            self._ks = _keystone.Ks(self.ks_arch, self.ks_mode)
            self._ks.syntax = _keystone.KS_OPT_SYNTAX_INTEL
            if self._ks_x86_syntax == 'at&t':
                self._ks.syntax = _keystone.KS_OPT_SYNTAX_ATT
            elif self._ks_x86_syntax == 'nasm':
                self._ks.syntax = _keystone.KS_OPT_SYNTAX_NASM
            elif self._ks_x86_syntax == 'masm':
                self._ks.syntax = _keystone.KS_OPT_SYNTAX_MASM
            elif self._ks_x86_syntax == 'gas':
                self._ks.syntax = _keystone.KS_OPT_SYNTAX_GAS
            elif self._ks_x86_syntax == 'radix16':
                self._ks.syntax = _keystone.KS_OPT_SYNTAX_RADIX16
        try:
            encoding, _ = self._ks.asm(string, addr, as_bytes) # pylint: disable=too-many-function-args
        except TypeError:
github angr / archinfo / archinfo / arch_x86.py View on Github external
def capstone_x86_syntax(self, new_syntax):
        """
        Set the syntax that Capstone outputs for x86.
        """

        if new_syntax not in ('intel', 'at&t'):
            raise ArchError('Unsupported Capstone x86 syntax. It must be either "intel" or "at&t".')

        if new_syntax != self._cs_x86_syntax:
            self._cs = None
            self._cs_x86_syntax = new_syntax
github angr / archinfo / archinfo / arch.py View on Github external
def keystone(self):
        """
        A Keystone instance for this arch
        """
        if self._ks is None:
            if _keystone is None:
                l.warning("Keystone is not installed!")
                return None
            if self.ks_arch is None:
                raise ArchError("Arch %s does not support disassembly with Keystone" % self.name)
            self._ks = _keystone.Ks(self.ks_arch, self.ks_mode)
            self._configure_keystone()
        return self._ks
github angr / archinfo / archinfo / arch_x86.py View on Github external
def keystone_x86_syntax(self, new_syntax):
        """
        Set the syntax that Keystone uses for x86.
        """

        if new_syntax not in ('intel', 'at&t', 'nasm', 'masm', 'gas', 'radix16'):
            e_str = 'Unsupported Keystone x86 syntax. It must be one of the following: '
            e_str += '"intel", "at&t", "nasm", "masm", "gas" or "radix16".'
            raise ArchError(e_str)

        if new_syntax != self._ks_x86_syntax:
            # clear the existing keystone instance
            self._ks = None
            self._ks_x86_syntax = new_syntax
github angr / archinfo / archinfo / arch_amd64.py View on Github external
def keystone_x86_syntax(self, new_syntax):
        if new_syntax not in ('intel', 'at&t', 'nasm', 'masm', 'gas', 'radix16'):
            raise ArchError('Unsupported Keystone x86 syntax. It must be one of the following: '
                            '"intel", "at&t", "nasm", "masm", "gas" or "radix16".')

        if new_syntax != self._ks_x86_syntax:
            self._ks = None
            self._ks_x86_syntax = new_syntax
github angr / archinfo / archinfo / arch_x86.py View on Github external
def capstone(self):
        if _capstone is None:
            l.warning("Capstone is not found!")
            return None
        if self.cs_arch is None:
            raise ArchError("Arch %s does not support disassembly with Capstone" % self.name)
        if self._cs is None:
            self._cs = _capstone.Cs(self.cs_arch, self.cs_mode)
            self._cs.syntax = _capstone.CS_OPT_SYNTAX_ATT if self._cs_x86_syntax == 'at&t' else _capstone.CS_OPT_SYNTAX_INTEL
            self._cs.detail = True
        return self._cs
github angr / archinfo / archinfo / arch.py View on Github external
def unicorn(self):
        """
        A Unicorn engine instance for this arch
        """
        if _unicorn is None or self.uc_arch is None:
            raise ArchError("Arch %s does not support with Unicorn" % self.name)
        # always create a new Unicorn instance
        return _unicorn.Uc(self.uc_arch, self.uc_mode)
github angr / archinfo / archinfo / arch.py View on Github external
def capstone(self):
        """
        A Capstone instance for this arch
        """
        if _capstone is None:
            l.warning("Capstone is not installed!")
            return None
        if self.cs_arch is None:
            raise ArchError("Arch %s does not support disassembly with Capstone" % self.name)
        if self._cs is None:
            self._cs = _capstone.Cs(self.cs_arch, self.cs_mode)
            self._configure_capstone()
            self._cs.detail = True
        return self._cs
github angr / archinfo / archinfo / arch_amd64.py View on Github external
def __init__(self, endness=Endness.LE):
        if endness != Endness.LE:
            raise ArchError('Arch AMD64 must be little endian')
        super(ArchAMD64, self).__init__(endness)
        self.argument_register_positions = {
            self.registers['rdi'][0]: 0,
            self.registers['rsi'][0]: 1,
            self.registers['rdx'][0]: 2,
            self.registers['rcx'][0]: 3,  # Used for user calls
            self.registers['r10'][0]: 3,  # Used for Linux kernel calls
            self.registers['r8'][0]: 4,
            self.registers['r9'][0]: 5,
            # fp registers
            self.registers['xmm0'][0]: 0,
            self.registers['xmm1'][0]: 1,
            self.registers['xmm2'][0]: 2,
            self.registers['xmm3'][0]: 3,
            self.registers['xmm4'][0]: 4,
            self.registers['xmm5'][0]: 5,