Python源码示例:capstone.CsError()

示例1
def _set_arch(self, arch, *modes):
        """
        Try and set the current architecture
        """
        try:
            a = self.valid_archs[''.join(['CS_ARCH_', arch.upper()])]
            if a is None:
                l.error("Invalid architecture selected - run lsarch for valid options")
                return False
            ms = [self.modes[''.join(['CS_MODE_', m.upper()])] for m in modes]
        except KeyError:
            l.error("ERROR: Invalid architecture or mode string specified")
            return False
        try:
            _cs = cs.Cs(a, sum(ms))
            self._arch = (arch, modes)
            l.debug("Architecture set to %s, mode(s): %s", arch, ', '.join(modes))
            self._cs = _cs
        except cs.CsError as e:
            l.error("ERROR: %s", e)
            return False
        return True 
示例2
def default(self, line):
        """
        Default behaviour - if no other commands are detected,
        try and disassemble the current input according to the
        currently set architecture and modes..

        :param line: Current line's text to try and disassemble.
        """
        # quick, brittle hack to enforce backslash encoding for now
        regex = re.compile('^(\\\\x[a-fA-F0-9]{2})+$')
        if not regex.match(line.strip()):
            l.error("\\xXX\\xXX... is the only valid input format (XX = hex digits)")
            return

        try:
            self._last_decoding = []
            stripped_line = re.sub(r'\\x([0-9a-fA-F]+)', r'\1', line)
            for (addr, size, mn, op_str) in \
                    self._cs.disasm_lite(binascii.a2b_hex(stripped_line), self._firstaddr):
                self._last_decoding.append((addr, size, mn, op_str))
                disas_str = "0x{:x}:\t{}\t{}".format(addr, mn, op_str)
                l.info(disas_str)
        except cs.CsError as e:
            l.error("ERROR: %s", e)
        except ValueError:
            l.error("\\xXX\\xXX... is the only valid input format (XX = hex digits)") 
示例3
def unprocess(self, data):
        super(AsmBase, self).unprocess(data)
        output = ''
        try:
            for (address, size, mnemonic, op_str) in \
                    self.cs.disasm_lite(bytes(data), 0x1000):
                if len(output) > 0:
                    output += '\n'
                output += '%s\t%s' % (mnemonic, op_str)
        except capstone.CsError as e:
            self.error = e
            self.log.error(self.error)
            self.log.debug(self.error, exc_info=True)
            return b''
        return output.encode()