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


Python dis.opmap方法代码示例

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


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

示例1: build_op

# 需要导入模块: import dis [as 别名]
# 或者: from dis import opmap [as 别名]
def build_op(self, op, arg=None):
            """Return a byte representation of a Python instruction."""
            if isinstance(op, str):
                op = dis.opmap[op]
            if arg is None and op >= dis.HAVE_ARGUMENT:
                raise ValueError("Operation requires an argument: %s" % dis.opname[op])
            if arg is not None and op < dis.HAVE_ARGUMENT:
                raise ValueError("Operation takes no argument: %s" % dis.opname[op])
            if arg is None:
                arg = 0
            # Python 3.6 changed the argument to an 8-bit integer, so this
            # could be a practical consideration
            if arg >= self.OPARG_SIZE:
                return self.build_op(
                    "EXTENDED_ARG", arg // self.OPARG_SIZE
                ) + self.build_op(op, arg % self.OPARG_SIZE)
            if not self.OPARG_VARI:
                return bytearray((op, arg))
            elif op >= dis.HAVE_ARGUMENT:
                return bytearray((op, arg % 256, arg // 256))
            else:
                return bytearray((op,)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:24,代码来源:routing.py

示例2: clean_ROT_TWO

# 需要导入模块: import dis [as 别名]
# 或者: from dis import opmap [as 别名]
def clean_ROT_TWO(bcg, skip_xrefs=True):
    '''
    Replace two sequential ROT_TWO sequences with NOPS
    '''
    count = 0

    for current in bcg.nodes():
        if current.next is None:
            break

        if current.opcode == opmap['ROT_TWO'] and \
           current.next.opcode == opmap['ROT_TWO']:
            if current.next.xrefs != [] and skip_xrefs:
                continue
            else:
                current.opcode = opmap['NOP']
                current.next.opcode = opmap['NOP']
                count += 1
    return count 
开发者ID:fireeye,项目名称:flare-bytecode_graph,代码行数:21,代码来源:bytecode_deobf_blog.py

示例3: clean_ROT_THREE

# 需要导入模块: import dis [as 别名]
# 或者: from dis import opmap [as 别名]
def clean_ROT_THREE(bcg, skip_xrefs=True):
    '''
    Replace three sequential ROT_THREE sequences with NOPS
    '''
    count = 0

    for current in bcg.nodes():
        if current.next is None or current.next.next is None:
            break

        if current.opcode == opmap['ROT_THREE'] and \
                current.next.opcode == opmap['ROT_THREE'] and \
                current.next.next.opcode == opmap['ROT_THREE']:

            if (current.next.xrefs != [] or current.next.next.xrefs != []) \
                    and skip_xrefs:
                        continue
            else:
                    current.opcode = opmap['NOP']
                    current.next.opcode = opmap['NOP']
                    current.next.next.opcode = opmap['NOP']
                    count += 1
    return count 
开发者ID:fireeye,项目名称:flare-bytecode_graph,代码行数:25,代码来源:bytecode_deobf_blog.py

示例4: clean_LOAD_POP

# 需要导入模块: import dis [as 别名]
# 或者: from dis import opmap [as 别名]
def clean_LOAD_POP(bcg, skip_xrefs=True):
    '''
    Replace LOAD_CONST/POP_TOP sequences with NOPS
    '''
    count = 0

    for current in bcg.nodes():
        if current.next is None:
            break

        if current.opcode == opmap['LOAD_CONST'] and \
                current.next.opcode == opmap['POP_TOP']:

            if current.next.xrefs != [] and skip_xrefs:
                continue
            else:
                current.opcode = opmap['NOP']
                current.next.opcode = opmap['NOP']
                count += 1
    return count 
开发者ID:fireeye,项目名称:flare-bytecode_graph,代码行数:22,代码来源:bytecode_deobf_blog.py

示例5: build_string

# 需要导入模块: import dis [as 别名]
# 或者: from dis import opmap [as 别名]
def build_string(self, n):
            """Return the correct opcode(s) for building a string from
            ``n`` elements. If the ``''.join`` crutch is needed, it must
            already be immediately below the string elements on the
            stack.
            """
            if "BUILD_STRING" in dis.opmap:
                return self.build_op("BUILD_STRING", n)
            else:
                return self.build_op("BUILD_TUPLE", n) + self.build_op(
                    "CALL_FUNCTION", 1
                ) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:14,代码来源:routing.py

示例6: test_opmap

# 需要导入模块: import dis [as 别名]
# 或者: from dis import opmap [as 别名]
def test_opmap(self):
        self.assertEqual(dis.opmap["STOP_CODE"], 0)
        self.assertIn(dis.opmap["LOAD_CONST"], dis.hasconst)
        self.assertIn(dis.opmap["STORE_NAME"], dis.hasname) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_dis.py

示例7: test_opname

# 需要导入模块: import dis [as 别名]
# 或者: from dis import opmap [as 别名]
def test_opname(self):
        self.assertEqual(dis.opname[dis.opmap["LOAD_FAST"]], "LOAD_FAST") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_dis.py

示例8: test_boundaries

# 需要导入模块: import dis [as 别名]
# 或者: from dis import opmap [as 别名]
def test_boundaries(self):
        self.assertEqual(dis.opmap["EXTENDED_ARG"], dis.EXTENDED_ARG)
        self.assertEqual(dis.opmap["STORE_NAME"], dis.HAVE_ARGUMENT) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_dis.py

示例9: _is_allowed

# 需要导入模块: import dis [as 别名]
# 或者: from dis import opmap [as 别名]
def _is_allowed(self, frame):
        """Check for allowed op code in the calling frame"""
        allowed = [dis.opmap['STORE_ATTR'], dis.opmap['LOAD_CONST'],
                   dis.opmap.get('STOP_CODE', 0)]
        bytecode = frame.f_code.co_code
        instruction = bytecode[frame.f_lasti + 3]
        instruction = ord(instruction) if PY2 else instruction
        return instruction in allowed 
开发者ID:spyder-ide,项目名称:spyder-kernels,代码行数:10,代码来源:iofuncs.py

示例10: test_opmap

# 需要导入模块: import dis [as 别名]
# 或者: from dis import opmap [as 别名]
def test_opmap(self):
        self.assertEqual(dis.opmap["NOP"], 9)
        self.assertIn(dis.opmap["LOAD_CONST"], dis.hasconst)
        self.assertIn(dis.opmap["STORE_NAME"], dis.hasname) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_dis.py

示例11: test_stack_effect

# 需要导入模块: import dis [as 别名]
# 或者: from dis import opmap [as 别名]
def test_stack_effect(self):
        self.assertEqual(_opcode.stack_effect(dis.opmap['POP_TOP']), -1)
        self.assertEqual(_opcode.stack_effect(dis.opmap['DUP_TOP_TWO']), 2)
        self.assertEqual(_opcode.stack_effect(dis.opmap['BUILD_SLICE'], 0), -1)
        self.assertEqual(_opcode.stack_effect(dis.opmap['BUILD_SLICE'], 1), -1)
        self.assertEqual(_opcode.stack_effect(dis.opmap['BUILD_SLICE'], 3), -2)
        self.assertRaises(ValueError, _opcode.stack_effect, 30000)
        self.assertRaises(ValueError, _opcode.stack_effect, dis.opmap['BUILD_SLICE'])
        self.assertRaises(ValueError, _opcode.stack_effect, dis.opmap['POP_TOP'], 0) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test__opcode.py

示例12: expecting

# 需要导入模块: import dis [as 别名]
# 或者: from dis import opmap [as 别名]
def expecting():
    """Return how many values the caller is expecting"""
    f = inspect.currentframe()
    f = f.f_back.f_back
    c = f.f_code
    i = f.f_lasti
    bytecode = c.co_code
    instruction = ord(bytecode[i+3])
    if instruction == dis.opmap['UNPACK_SEQUENCE']:
        howmany = ord(bytecode[i+4])
        return howmany
    elif instruction == dis.opmap['POP_TOP']:
        return 0
    return 1 
开发者ID:ActiveState,项目名称:code,代码行数:16,代码来源:recipe-284742.py

示例13: expecting

# 需要导入模块: import dis [as 别名]
# 或者: from dis import opmap [as 别名]
def expecting():
    """Return how many values the caller is expecting"""
    f = inspect.currentframe()
    f = f.f_back.f_back
    c = f.f_code
    i = f.f_lasti
    bytecode = c.co_code
    instruction = bytecode[i + 3]
    if instruction == dis.opmap['UNPACK_SEQUENCE']:
        howmany = bytecode[i + 4]
        return howmany
    elif instruction == dis.opmap['POP_TOP']:
        return 0
    return 1 
开发者ID:thomaskuestner,项目名称:CNNArt,代码行数:16,代码来源:Training_Test_Split_FCN.py

示例14: expecting

# 需要导入模块: import dis [as 别名]
# 或者: from dis import opmap [as 别名]
def expecting():
    """Return how many values the caller is expecting"""
    f = inspect.currentframe()
    f = f.f_back.f_back
    c = f.f_code
    i = f.f_lasti
    bytecode = c.co_code
    instruction = bytecode[i+3]
    if instruction == dis.opmap['UNPACK_SEQUENCE']:
        howmany = bytecode[i+4]
        return howmany
    elif instruction == dis.opmap['POP_TOP']:
        return 0
    return 1 
开发者ID:thomaskuestner,项目名称:CNNArt,代码行数:16,代码来源:Training_Test_Split.py

示例15: _get_instruction_size

# 需要导入模块: import dis [as 别名]
# 或者: from dis import opmap [as 别名]
def _get_instruction_size(opname, oparg=0):
    size = 1

    extended_arg = oparg >> _BYTECODE.argument_bits
    if extended_arg != 0:
        size += _get_instruction_size('EXTENDED_ARG', extended_arg)
        oparg &= (1 << _BYTECODE.argument_bits) - 1

    opcode = dis.opmap[opname]
    if opcode >= _BYTECODE.have_argument:
        size += _BYTECODE.argument.size

    return size 
开发者ID:snoack,项目名称:python-goto,代码行数:15,代码来源:goto.py


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