uncompyle6.scanners package¶
Submodules¶
uncompyle6.scanners.pypy27 module¶
Python PyPy 2.7 bytecode scanner/deparser
This overlaps Python’s 2.7’s dis module, but it can be run from Python 3 and other versions of Python. Also, we save token information for later use in deparsing.
-
class
uncompyle6.scanners.pypy27.ScannerPyPy27(show_asm)¶
uncompyle6.scanners.pypy32 module¶
Python PyPy 3.2 bytecode scanner/deparser
This overlaps Python’s 3.2’s dis module, but it can be run from Python 3 and other versions of Python. Also, we save token information for later use in deparsing.
-
class
uncompyle6.scanners.pypy32.ScannerPyPy32(show_asm)¶
uncompyle6.scanners.scanner2 module¶
Python 2 Generic bytecode scanner/deparser
This overlaps various Python3’s dis module, but it can be run from Python versions other than the version running this code. Notably, run from Python version 2.
Also we modify the instruction sequence to assist deparsing code. For example:
we add “COME_FROM” instructions to help in figuring out conditional branching and looping.
LOAD_CONSTs are classified further into the type of thing they load:
lambda’s, genexpr’s, {dict,set,list} comprehension’s,
PARAMETER counts appended {CALL,MAKE}_FUNCTION, BUILD_{TUPLE,SET,SLICE}
Finally we save token information.
-
class
uncompyle6.scanners.scanner2.Scanner2(version, show_asm=None, is_pypy=False)¶ Bases:
uncompyle6.scanner.Scanner-
build_lines_data(co, n)¶ Initializes self.lines and self.linesstartoffsets
-
build_prev_op(n)¶
-
build_stmt_indices()¶
-
detect_structure(pos, op)¶ Detect type of block structures and their boundaries to fix optimized jumps in python2.3+
-
find_jump_targets()¶ Detect all offsets in a byte code which are jump targets where we might insert a COME_FROM instruction.
Return the list of offsets. An instruction can be jumped to in from multiple instructions.
-
ingest(co, classname=None, code_objects={}, show_asm=None)¶ Pick out tokens from an uncompyle6 code object, and transform them, returning a list of uncompyle6 ‘Token’s.
The transformations are made to assist the deparsing grammar. Specificially:
- various types of LOAD_CONST’s are categorized in terms of what they load
- COME_FROM instructions are added to assist parsing control structures
- MAKE_FUNCTION and FUNCTION_CALLS append the number of positional arguments
Also, when we encounter certain tokens, we add them to a set which will cause custom grammar rules. Specifically, variable arg tokens like MAKE_FUNCTION or BUILD_LIST cause specific rules for the specific number of arguments they take.
-
next_except_jump(start)¶ Return the next jump that was generated by an except SomeException: construct in a try...except...else clause or None if not found.
-
op_size(op)¶ Return size of operator with its arguments for given opcode <op>.
-
rem_or(start, end, instr, target=None, include_beyond_target=False)¶ Find all <instr> in the block from start to end. <instr> is any python bytecode instruction or a list of opcodes If <instr> is an opcode with a target (like a jump), a target destination can be specified which must match precisely.
Return a list with indexes to them or [] if none found.
-
setup_code(co)¶ Creates Python-independent bytecode structure (byte array) in self.code and records previous instruction in self.prev The size of self.code is returned
-
uncompyle6.scanners.scanner22 module¶
Python 2.2 bytecode ingester.
This massages tokenized 2.2 bytecode to make it more amenable for grammar parsing.
-
class
uncompyle6.scanners.scanner22.Scanner22(show_asm=False)¶ Bases:
uncompyle6.scanners.scanner23.Scanner23-
ingest22(co, classname=None, code_objects={}, show_asm=None)¶
-
uncompyle6.scanners.scanner23 module¶
Python 2.3 bytecode scanner/deparser
This overlaps Python’s 2.3’s dis module, but it can be run from Python 3 and other versions of Python. Also, we save token information for later use in deparsing.
-
class
uncompyle6.scanners.scanner23.Scanner23(show_asm)¶
uncompyle6.scanners.scanner24 module¶
Python 2.4 bytecode scanner/deparser
This overlaps Python’s 2.4’s dis module, but it can be run from Python 3 and other versions of Python. Also, we save token information for later use in deparsing.
-
class
uncompyle6.scanners.scanner24.Scanner24(show_asm)¶
uncompyle6.scanners.scanner25 module¶
Python 2.5 bytecode scanner/deparser
This overlaps Python’s 2.5’s dis module, but it can be run from Python 3 and other versions of Python. Also, we save token information for later use in deparsing.
-
class
uncompyle6.scanners.scanner25.Scanner25(show_asm)¶
uncompyle6.scanners.scanner26 module¶
Python 2.6 bytecode scanner
This overlaps Python’s 2.6’s dis module, but it can be run from Python 3 and other versions of Python. Also, we save token information for later use in deparsing.
-
class
uncompyle6.scanners.scanner26.Scanner26(show_asm=False)¶ Bases:
uncompyle6.scanners.scanner2.Scanner2-
ingest(co, classname=None, code_objects={}, show_asm=None)¶ Pick out tokens from an uncompyle6 code object, and transform them, returning a list of uncompyle6 ‘Token’s.
The transformations are made to assist the deparsing grammar. Specificially:
- various types of LOAD_CONST’s are categorized in terms of what they load
- COME_FROM instructions are added to assist parsing control structures
- MAKE_FUNCTION and FUNCTION_CALLS append the number of positional arguments
Also, when we encounter certain tokens, we add them to a set which will cause custom grammar rules. Specifically, variable arg tokens like MAKE_FUNCTION or BUILD_LIST cause specific rules for the specific number of arguments they take.
-
uncompyle6.scanners.scanner27 module¶
Python 2.7 bytecode ingester.
This massages tokenized 2.7 bytecode to make it more amenable for grammar parsing.
-
class
uncompyle6.scanners.scanner27.Scanner27(show_asm=False, is_pypy=False)¶ Bases:
uncompyle6.scanners.scanner2.Scanner2-
patch_continue(tokens, offset, op)¶
-
uncompyle6.scanners.scanner3 module¶
Python 3 Generic bytecode scanner/deparser
This overlaps various Python3’s dis module, but it can be run from Python versions other than the version running this code. Notably, run from Python version 2.
Also we modify the instruction sequence to assist deparsing code. For example:
we add “COME_FROM” instructions to help in figuring out conditional branching and looping.
LOAD_CONSTs are classified further into the type of thing they load:
lambda’s, genexpr’s, {dict,set,list} comprehension’s,
PARAMETER counts appended {CALL,MAKE}_FUNCTION, BUILD_{TUPLE,SET,SLICE}
Finally we save token information.
-
class
uncompyle6.scanners.scanner3.Scanner3(version, show_asm=None, is_pypy=False)¶ Bases:
uncompyle6.scanner.Scanner-
build_lines_data(code_obj)¶ Generate various line-related helper data.
-
build_prev_op()¶ Compose ‘list-map’ which allows to jump to previous op, given offset of current op as index.
-
build_statement_indices()¶
-
detect_structure(offset, targets)¶ Detect structures and their boundaries to fix optimized jumps in python2.3+
-
find_jump_targets()¶ Detect all offsets in a byte code which are jump targets.
Return the list of offsets.
This procedure is modelled after dis.findlabels(), but here for each target the number of jumps is counted.
-
get_target(offset)¶ Get target offset for op located at given <offset>.
-
ingest(co, classname=None, code_objects={}, show_asm=None)¶ Pick out tokens from an uncompyle6 code object, and transform them, returning a list of uncompyle6 ‘Token’s.
The transformations are made to assist the deparsing grammar. Specificially:
- various types of LOAD_CONST’s are categorized in terms of what they load
- COME_FROM instructions are added to assist parsing control structures
- MAKE_FUNCTION and FUNCTION_CALLS append the number of positional arguments
Also, when we encounter certain tokens, we add them to a set which will cause custom grammar rules. Specifically, variable arg tokens like MAKE_FUNCTION or BUILD_LIST cause specific rules for the specific number of arguments they take.
-
next_except_jump(start)¶ Return the next jump that was generated by an except SomeException: construct in a try...except...else clause or None if not found.
-
opName(offset)¶
-
op_size(op)¶ Return size of operator with its arguments for given opcode <op>.
-
rem_or(start, end, instr, target=None, include_beyond_target=False)¶ Find offsets of all requested <instr> between <start> and <end>, optionally <target>ing specified offset, and return list found <instr> offsets which are not within any POP_JUMP_IF_TRUE jumps.
-
uncompyle6.scanners.scanner31 module¶
Python 3.1 bytecode scanner/deparser
This sets up opcodes Python’s 3.1 and calls a generalized scanner routine for Python 3.
-
class
uncompyle6.scanners.scanner31.Scanner31(show_asm=None, is_pypy=False)¶
uncompyle6.scanners.scanner32 module¶
Python 3.2 bytecode scanner/deparser
This sets up opcodes Python’s 3.2 and calls a generalized scanner routine for Python 3.
-
class
uncompyle6.scanners.scanner32.Scanner32(show_asm=None, is_pypy=False)¶
uncompyle6.scanners.scanner33 module¶
Python 3.3 bytecode scanner/deparser
This sets up opcodes Python’s 3.3 and calls a generalized scanner routine for Python 3.
-
class
uncompyle6.scanners.scanner33.Scanner33(show_asm=False)¶
uncompyle6.scanners.scanner34 module¶
Python 3.4 bytecode scanner/deparser
This sets up opcodes Python’s 3.4 and calls a generalized scanner routine for Python 3.
-
class
uncompyle6.scanners.scanner34.Scanner34(show_asm=None)¶
uncompyle6.scanners.scanner35 module¶
Python 3.5 bytecode scanner/deparser
This sets up opcodes Python’s 3.5 and calls a generalized scanner routine for Python 3.
-
class
uncompyle6.scanners.scanner35.Scanner35(show_asm=None)¶
uncompyle6.scanners.scanner36 module¶
Python 3.5 bytecode scanner/deparser
This sets up opcodes Python’s 3.5 and calls a generalized scanner routine for Python 3.
-
class
uncompyle6.scanners.scanner36.Scanner36(show_asm=None)¶
uncompyle6.scanners.tok module¶
-
class
uncompyle6.scanners.tok.Token(type_, attr=None, pattr=None, offset=-1, linestart=None, op=None, has_arg=None, opc=None)¶ Class representing a byte-code instruction.
A byte-code token is equivalent to Python 3’s dis.instruction or the contents of one line as output by dis.dis().