當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。