当前位置: 首页>>代码示例>>Python>>正文


Python keystone.KsError方法代码示例

本文整理汇总了Python中keystone.KsError方法的典型用法代码示例。如果您正苦于以下问题:Python keystone.KsError方法的具体用法?Python keystone.KsError怎么用?Python keystone.KsError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在keystone的用法示例。


在下文中一共展示了keystone.KsError方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _set_arch

# 需要导入模块: import keystone [as 别名]
# 或者: from keystone import KsError [as 别名]
def _set_arch(self, arch, *modes):
        """
        Try and set the current architecture
        """
        try:
            a = self.valid_archs[''.join(['KS_ARCH_', arch.upper()])]
            if a is None:
                l.error("Invalid architecture selected - run lsarch for valid options")
                return False
            ms = [self.modes[''.join(['KS_MODE_', m.upper()])] for m in modes]
        except KeyError:
            l.error("ERROR: Invalid architecture or mode string specified")
            return False
        try:
            _ks = ks.Ks(a, sum(ms))
            self._arch = (arch, modes)
            l.debug("Architecture set to %s, mode(s): %s", arch, ', '.join(modes))
            self._ks = _ks
        except ks.KsError as e:
            l.error("ERROR: %s", e)
            return False
        return True 
开发者ID:0xbc,项目名称:chiasm-shell,代码行数:24,代码来源:assembler.py

示例2: default

# 需要导入模块: import keystone [as 别名]
# 或者: from keystone import KsError [as 别名]
def default(self, line):
        """
        Default behaviour - if no other commands are detected,
        try and assemble the current input according to the
        currently set architecture.

        :param line: Current line's text to try and assemble.
        """
        try:
            encoding, dummy_insn_count = self._ks.asm(line)
            self._last_encoding = encoding
            l.info("".join('\\x{:02x}'.format(opcode) for opcode in encoding))
        except ks.KsError as e:
            l.error("ERROR: %s", e) 
开发者ID:0xbc,项目名称:chiasm-shell,代码行数:16,代码来源:assembler.py

示例3: process

# 需要导入模块: import keystone [as 别名]
# 或者: from keystone import KsError [as 别名]
def process(self, data):
        super(AsmBase, self).process(data)
        try:
            encoding, count = self.ks.asm(data.decode())
        except keystone.KsError as e:
            self.error = e
            self.log.error(self.error)
            self.log.debug(self.error, exc_info=True)
            return b''
        return bytearray(encoding) 
开发者ID:takeshixx,项目名称:deen,代码行数:12,代码来源:__base__.py

示例4: _interactive_assembly

# 需要导入模块: import keystone [as 别名]
# 或者: from keystone import KsError [as 别名]
def _interactive_assembly(self):
        # Import readline module to make arrow keys
        # and command history work in the interactive
        # mode.
        import readline
        prompt = self.display_name + ' > '
        if self.args.revert:
            prompt = 'dsm:' + prompt
        else:
            prompt = 'asm:' + prompt
        while True:
            try:
                data = input(prompt)
                if not data:
                    continue
                try:
                    if self.args.revert:
                        try:
                            data = codecs.decode(data, 'hex')
                        except Exception:
                            self.write_to_stdout(b'Invalid hex encoding')
                            continue
                        output = self.unprocess(data)
                        if not self.args.plain:
                            output = self._syntax_highlighting(output)
                        self.write_to_stdout(output, nonewline=True)
                    else:
                        encoding, count = self.ks.asm(data)
                        if self.args.raw:
                            output = bytes(bytearray(encoding))
                        else:
                            output = codecs.encode(bytearray(encoding), 'hex')
                        self.write_to_stdout(output)
                except keystone.KsError as e:
                    self.log.error(e)
                    self.log.debug(e, exc_info=True)
                    self.write_to_stdout(str(e).encode())
            except (KeyboardInterrupt, EOFError):
                return b'' 
开发者ID:takeshixx,项目名称:deen,代码行数:41,代码来源:__base__.py

示例5: patch_code

# 需要导入模块: import keystone [as 别名]
# 或者: from keystone import KsError [as 别名]
def patch_code(self, instructions='ret;',va=0):
        """ put instruction(s), at the end of the basic block specified"""
        #TODO: get capstone instruction at the end of the basic_block
        try:
            k = ks.Ks(ks.KS_ARCH_X86, ks.KS_MODE_32)
            encoding, count = k.asm(instructions, va+self.OPTIONAL_HEADER.ImageBase)
        except ks.KsError as e:
            l.error("Error! %s", e)
            raise

        if not self.set_bytes_at_rva(va, ''.join(map(chr, encoding))):
            raise Exception('Cannot patch bytes at %x!', va) 
开发者ID:necst,项目名称:crave,代码行数:14,代码来源:pe.py

示例6: RelaxInstructions

# 需要导入模块: import keystone [as 别名]
# 或者: from keystone import KsError [as 别名]
def RelaxInstructions(self, store, list_of_fixups, labels):
        """
        Relax assembly instructions as necessary.

        Args:
          store: An AssemblyStore instance.
          list_of_fixups: a dictionary of instructions and their indices that need to be
                          adjusted.
          labels: A dictionary of label names to addresses.

        Returns:
          N / A

        Side Effects:
          This will adjust the assembled instructions using wider versions
          when a labels address is beyond the range of the short forms 
          (e.g. jumps and calls on x86)
        """
        done_relaxing = False

        #last rounds label addresses
        last_rounds_label_addresses = labels

        while not done_relaxing:
            for row in store.GetRowsIterator():
                if row.index not in list_of_fixups:
                    continue

                mnemonic, label = list_of_fixups[row.index]
                label_addr_st = hex(labels[label]).replace('L', '')
                mnemonic = mnemonic.replace(label, label_addr_st)

                try:
                    encoded_bytes, inst_count  = self.assembler.asm(mnemonic,
                                                                    addr=row.address)
                    if inst_count != 1:
                        raise AssemblerError("mnemonic in row %d contains multiple statements" % row.index)

                    opcode_str = "".join(["%02x" % byte for byte in encoded_bytes])
                    row.opcode = binascii.unhexlify(opcode_str)
                    store.UpdateRow(row.index, row)

                except keystone.KsError as exc:
                    LOGGER.error(str(exc))
                    store.SetErrorAtIndex(row.index)
                    break

            # collect the labels updated addresses
            for row in store.GetRowsIterator():
                if row.label != '':
                    labels[row.label.upper()] = row.address
                    
            # check to see if any labels differ at all if yes then continue 
            # relaxing
            if labels == last_rounds_label_addresses:
                done_relaxing = True
                for row in store.GetRowsIterator():
                    self.CheckOpcodeBytes(row, store)
            else:
                last_rounds_label_addresses = labels 
开发者ID:pmarkowsky,项目名称:dash,代码行数:62,代码来源:assembler.py


注:本文中的keystone.KsError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。