Python opcode.hasconst() Examples
The following are 5
code examples of opcode.hasconst().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
opcode
, or try the search function
.
Example #1
Source File: merger.py From equip with Apache License 2.0 | 5 votes |
def get_op_oparg(self, op, arg, bc_index=0): """ Retrieve the opcode (`op`) and its argument (`oparg`) from the supplied opcode and argument. :param op: The current opcode. :param arg: The current dereferenced argument. :param bc_index: The current bytecode index. """ # Conversion of LOAD_NAME opcode based on injected references (global, vars) if op == LOAD_NAME: if arg in self.name_to_fast: op = LOAD_FAST elif arg in self.name_to_global: op = LOAD_GLOBAL oparg = None if op >= opcode.HAVE_ARGUMENT: if op in opcode.hasconst: oparg = self.add_get_constant(arg) elif op in opcode.hasname: oparg = self.add_get_names(arg) elif op in opcode.haslocal: oparg = self.add_get_varnames(arg) elif op in opcode.hascompare: oparg = opcode.cmp_op.index(arg) elif op in opcode.hasfree: oparg = self.add_get_cellvars_freevars(arg) elif op in opcode.hasjrel or op in opcode.hasjabs: oparg = arg else: oparg = arg return op, oparg
Example #2
Source File: teleportation.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def decode_codeobj(codeobj): # adapted from dis.dis extended_arg = 0 if is_py3k: codestr = codeobj.co_code else: codestr = [ord(ch) for ch in codeobj.co_code] free = None i = 0 while i < len(codestr): op = codestr[i] opname = opcode.opname[op] i += 1 argval = None if op >= opcode.HAVE_ARGUMENT: oparg = codestr[i] + codestr[i + 1] * 256 + extended_arg i += 2 extended_arg = 0 if op == opcode.EXTENDED_ARG: extended_arg = oparg * 65536 continue if op in opcode.hasconst: argval = codeobj.co_consts[oparg] elif op in opcode.hasname: argval = codeobj.co_names[oparg] elif op in opcode.hasjrel: argval = i + oparg elif op in opcode.haslocal: argval = codeobj.co_varnames[oparg] elif op in opcode.hascompare: argval = opcode.cmp_op[oparg] elif op in opcode.hasfree: if free is None: free = codeobj.co_cellvars + codeobj.co_freevars argval = free[oparg] yield (opname, argval)
Example #3
Source File: teleportation.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def decode_codeobj(codeobj): # adapted from dis.dis extended_arg = 0 if is_py3k: codestr = codeobj.co_code else: codestr = [ord(ch) for ch in codeobj.co_code] free = None i = 0 while i < len(codestr): op = codestr[i] opname = opcode.opname[op] i += 1 argval = None if op >= opcode.HAVE_ARGUMENT: oparg = codestr[i] + codestr[i + 1] * 256 + extended_arg i += 2 extended_arg = 0 if op == opcode.EXTENDED_ARG: extended_arg = oparg * 65536 continue if op in opcode.hasconst: argval = codeobj.co_consts[oparg] elif op in opcode.hasname: argval = codeobj.co_names[oparg] elif op in opcode.hasjrel: argval = i + oparg elif op in opcode.haslocal: argval = codeobj.co_varnames[oparg] elif op in opcode.hascompare: argval = opcode.cmp_op[oparg] elif op in opcode.hasfree: if free is None: free = codeobj.co_cellvars + codeobj.co_freevars argval = free[oparg] yield (opname, argval)
Example #4
Source File: tb.py From owasp-pysec with Apache License 2.0 | 5 votes |
def disassemble(co): code = co.co_code labels = dis.findlabels(code) linestarts = dict(dis.findlinestarts(co)) n = len(code) i = 0 extended_arg = 0 free = None lineno = None while i < n: c = code[i] op = ord(c) lineno = linestarts.get(i, lineno) is_label = i in labels ist = i i += 1 if op >= opcode.HAVE_ARGUMENT: oparg = ord(code[i]) + ord(code[i + 1]) * 256 + extended_arg extended_arg = 0 i += 2 if op == opcode.EXTENDED_ARG: extended_arg = oparg * 65536L if op in opcode.hasconst: arg = co.co_consts[oparg] elif op in opcode.hasname: arg = co.co_names[oparg] elif op in opcode.hasjrel: arg = i + oparg elif op in opcode.haslocal: arg = co.co_varnames[oparg] elif op in opcode.hascompare: arg = opcode.cmp_op[oparg] elif op in opcode.hasfree: if free is None: free = co.co_cellvars + co.co_freevars arg = free[oparg] else: arg = NOVAL else: arg = NOVAL yield ist, lineno, is_label, opcode.opname[op], arg
Example #5
Source File: teleportation.py From backdoorme with MIT License | 5 votes |
def decode_codeobj(codeobj): # adapted from dis.dis extended_arg = 0 if is_py3k: codestr = codeobj.co_code else: codestr = [ord(ch) for ch in codeobj.co_code] free = None i = 0 while i < len(codestr): op = codestr[i] opname = opcode.opname[op] i += 1 argval = None if op >= opcode.HAVE_ARGUMENT: oparg = codestr[i] + codestr[i + 1] * 256 + extended_arg i += 2 extended_arg = 0 if op == opcode.EXTENDED_ARG: extended_arg = oparg * 65536 continue if op in opcode.hasconst: argval = codeobj.co_consts[oparg] elif op in opcode.hasname: argval = codeobj.co_names[oparg] elif op in opcode.hasjrel: argval = i + oparg elif op in opcode.haslocal: argval = codeobj.co_varnames[oparg] elif op in opcode.hascompare: argval = opcode.cmp_op[oparg] elif op in opcode.hasfree: if free is None: free = codeobj.co_cellvars + codeobj.co_freevars argval = free[oparg] yield (opname, argval)