本文整理汇总了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,))
示例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
示例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
示例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
示例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
)
示例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)
示例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")
示例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)
示例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
示例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)
示例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)
示例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
示例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
示例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
示例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