You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 08:49:51 +08:00
Python 3 bytecode handles opcodes with varargs (better). Decompiling
assert works. Add more of the simple tests and their compiled bytecode.
This commit is contained in:
BIN
test/bytecode_3.2/divide_floor.pyc
Normal file
BIN
test/bytecode_3.2/divide_floor.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.2/divide_true.pyc
Normal file
BIN
test/bytecode_3.2/divide_true.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.2/modulo.pyc
Normal file
BIN
test/bytecode_3.2/modulo.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.2/multiply.pyc
Normal file
BIN
test/bytecode_3.2/multiply.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.2/or.pyc
Normal file
BIN
test/bytecode_3.2/or.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.2/power.pyc
Normal file
BIN
test/bytecode_3.2/power.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.2/shift_left.pyc
Normal file
BIN
test/bytecode_3.2/shift_left.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.2/shift_right.pyc
Normal file
BIN
test/bytecode_3.2/shift_right.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.2/subscription.pyc
Normal file
BIN
test/bytecode_3.2/subscription.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.2/subtract.pyc
Normal file
BIN
test/bytecode_3.2/subtract.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.2/xor.pyc
Normal file
BIN
test/bytecode_3.2/xor.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
test/bytecode_3.4/assert.pyc
Normal file
BIN
test/bytecode_3.4/assert.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/assign_none.pyc
Normal file
BIN
test/bytecode_3.4/assign_none.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/assign_none_str.pyc
Normal file
BIN
test/bytecode_3.4/assign_none_str.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/complex1.pyc
Normal file
BIN
test/bytecode_3.4/complex1.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/complex2.pyc
Normal file
BIN
test/bytecode_3.4/complex2.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/complex3.pyc
Normal file
BIN
test/bytecode_3.4/complex3.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/complex4.pyc
Normal file
BIN
test/bytecode_3.4/complex4.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/complex5.pyc
Normal file
BIN
test/bytecode_3.4/complex5.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/complex6.pyc
Normal file
BIN
test/bytecode_3.4/complex6.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/complex7.pyc
Normal file
BIN
test/bytecode_3.4/complex7.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/complex8.pyc
Normal file
BIN
test/bytecode_3.4/complex8.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/complex9.pyc
Normal file
BIN
test/bytecode_3.4/complex9.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/complex_script1.pyc
Normal file
BIN
test/bytecode_3.4/complex_script1.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/complex_script2.pyc
Normal file
BIN
test/bytecode_3.4/complex_script2.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/divide_floor.pyc
Normal file
BIN
test/bytecode_3.4/divide_floor.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/divide_true.pyc
Normal file
BIN
test/bytecode_3.4/divide_true.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/equal.pyc
Normal file
BIN
test/bytecode_3.4/equal.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/for.pyc
Normal file
BIN
test/bytecode_3.4/for.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/forelse.pyc
Normal file
BIN
test/bytecode_3.4/forelse.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/globals.pyc
Normal file
BIN
test/bytecode_3.4/globals.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/globals_locals.pyc
Normal file
BIN
test/bytecode_3.4/globals_locals.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/greater.pyc
Normal file
BIN
test/bytecode_3.4/greater.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/greater_equal.pyc
Normal file
BIN
test/bytecode_3.4/greater_equal.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/invert.pyc
Normal file
BIN
test/bytecode_3.4/invert.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/iter.pyc
Normal file
BIN
test/bytecode_3.4/iter.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/left.pyc
Normal file
BIN
test/bytecode_3.4/left.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/less.pyc
Normal file
BIN
test/bytecode_3.4/less.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/less_equal.pyc
Normal file
BIN
test/bytecode_3.4/less_equal.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/modulo.pyc
Normal file
BIN
test/bytecode_3.4/modulo.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/multiply.pyc
Normal file
BIN
test/bytecode_3.4/multiply.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/negative.pyc
Normal file
BIN
test/bytecode_3.4/negative.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/not.pyc
Normal file
BIN
test/bytecode_3.4/not.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/notequal.pyc
Normal file
BIN
test/bytecode_3.4/notequal.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/or.pyc
Normal file
BIN
test/bytecode_3.4/or.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/positive.pyc
Normal file
BIN
test/bytecode_3.4/positive.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/power.pyc
Normal file
BIN
test/bytecode_3.4/power.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/right.pyc
Normal file
BIN
test/bytecode_3.4/right.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/shift_left.pyc
Normal file
BIN
test/bytecode_3.4/shift_left.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/shift_right.pyc
Normal file
BIN
test/bytecode_3.4/shift_right.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/structure.pyc
Normal file
BIN
test/bytecode_3.4/structure.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/subscription.pyc
Normal file
BIN
test/bytecode_3.4/subscription.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/subtract.pyc
Normal file
BIN
test/bytecode_3.4/subtract.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/while.pyc
Normal file
BIN
test/bytecode_3.4/while.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/xor.pyc
Normal file
BIN
test/bytecode_3.4/xor.pyc
Normal file
Binary file not shown.
1
test/simple-source/operation_binary/multiply.py
Normal file
1
test/simple-source/operation_binary/multiply.py
Normal file
@@ -0,0 +1 @@
|
||||
a = b * c
|
1
test/simple-source/operation_binary/or.py
Normal file
1
test/simple-source/operation_binary/or.py
Normal file
@@ -0,0 +1 @@
|
||||
a = b | c
|
1
test/simple-source/operation_binary/power.py
Normal file
1
test/simple-source/operation_binary/power.py
Normal file
@@ -0,0 +1 @@
|
||||
a = b ** c
|
1
test/simple-source/operation_binary/shift_left.py
Normal file
1
test/simple-source/operation_binary/shift_left.py
Normal file
@@ -0,0 +1 @@
|
||||
a = b << c
|
1
test/simple-source/operation_binary/shift_right.py
Normal file
1
test/simple-source/operation_binary/shift_right.py
Normal file
@@ -0,0 +1 @@
|
||||
a = b >> c
|
1
test/simple-source/operation_binary/subscription.py
Normal file
1
test/simple-source/operation_binary/subscription.py
Normal file
@@ -0,0 +1 @@
|
||||
a = b[c]
|
1
test/simple-source/operation_binary/subtract.py
Normal file
1
test/simple-source/operation_binary/subtract.py
Normal file
@@ -0,0 +1 @@
|
||||
a = b - c
|
1
test/simple-source/operation_binary/xor.py
Normal file
1
test/simple-source/operation_binary/xor.py
Normal file
@@ -0,0 +1 @@
|
||||
a = b ^ c
|
1
test/simple-source/operation_comparison/equal.py
Normal file
1
test/simple-source/operation_comparison/equal.py
Normal file
@@ -0,0 +1 @@
|
||||
a == b
|
1
test/simple-source/operation_comparison/greater.py
Normal file
1
test/simple-source/operation_comparison/greater.py
Normal file
@@ -0,0 +1 @@
|
||||
a > b
|
1
test/simple-source/operation_comparison/greater_equal.py
Normal file
1
test/simple-source/operation_comparison/greater_equal.py
Normal file
@@ -0,0 +1 @@
|
||||
a >= b
|
1
test/simple-source/operation_comparison/less.py
Normal file
1
test/simple-source/operation_comparison/less.py
Normal file
@@ -0,0 +1 @@
|
||||
a < b
|
1
test/simple-source/operation_comparison/less_equal.py
Normal file
1
test/simple-source/operation_comparison/less_equal.py
Normal file
@@ -0,0 +1 @@
|
||||
a <= b
|
1
test/simple-source/operation_comparison/notequal.py
Normal file
1
test/simple-source/operation_comparison/notequal.py
Normal file
@@ -0,0 +1 @@
|
||||
a != b
|
1
test/simple-source/operation_inplace/add.py
Normal file
1
test/simple-source/operation_inplace/add.py
Normal file
@@ -0,0 +1 @@
|
||||
a += b
|
1
test/simple-source/operation_inplace/and.py
Normal file
1
test/simple-source/operation_inplace/and.py
Normal file
@@ -0,0 +1 @@
|
||||
a &= b
|
1
test/simple-source/operation_inplace/divide_floor.py
Normal file
1
test/simple-source/operation_inplace/divide_floor.py
Normal file
@@ -0,0 +1 @@
|
||||
a //= b
|
1
test/simple-source/operation_inplace/divide_true.py
Normal file
1
test/simple-source/operation_inplace/divide_true.py
Normal file
@@ -0,0 +1 @@
|
||||
a /= b
|
1
test/simple-source/operation_inplace/modulo.py
Normal file
1
test/simple-source/operation_inplace/modulo.py
Normal file
@@ -0,0 +1 @@
|
||||
a %= b
|
1
test/simple-source/operation_inplace/multiply.py
Normal file
1
test/simple-source/operation_inplace/multiply.py
Normal file
@@ -0,0 +1 @@
|
||||
a *= b
|
1
test/simple-source/operation_inplace/or.py
Normal file
1
test/simple-source/operation_inplace/or.py
Normal file
@@ -0,0 +1 @@
|
||||
a |= b
|
1
test/simple-source/operation_inplace/power.py
Normal file
1
test/simple-source/operation_inplace/power.py
Normal file
@@ -0,0 +1 @@
|
||||
a **= b
|
1
test/simple-source/operation_inplace/shift_left.py
Normal file
1
test/simple-source/operation_inplace/shift_left.py
Normal file
@@ -0,0 +1 @@
|
||||
a <<= b
|
1
test/simple-source/operation_inplace/shift_right.py
Normal file
1
test/simple-source/operation_inplace/shift_right.py
Normal file
@@ -0,0 +1 @@
|
||||
a >>= b
|
1
test/simple-source/operation_inplace/subtract.py
Normal file
1
test/simple-source/operation_inplace/subtract.py
Normal file
@@ -0,0 +1 @@
|
||||
a -= b
|
1
test/simple-source/operation_inplace/xor.py
Normal file
1
test/simple-source/operation_inplace/xor.py
Normal file
@@ -0,0 +1 @@
|
||||
a ^= b
|
1
test/simple-source/operation_logic/and.py
Normal file
1
test/simple-source/operation_logic/and.py
Normal file
@@ -0,0 +1 @@
|
||||
a = b and c
|
1
test/simple-source/operation_logic/complex1.py
Normal file
1
test/simple-source/operation_logic/complex1.py
Normal file
@@ -0,0 +1 @@
|
||||
a = b and c or d
|
1
test/simple-source/operation_logic/complex2.py
Normal file
1
test/simple-source/operation_logic/complex2.py
Normal file
@@ -0,0 +1 @@
|
||||
a = (b or c) and d
|
1
test/simple-source/operation_logic/complex3.py
Normal file
1
test/simple-source/operation_logic/complex3.py
Normal file
@@ -0,0 +1 @@
|
||||
a = b or c or d
|
2
test/simple-source/precedence/left.py
Normal file
2
test/simple-source/precedence/left.py
Normal file
@@ -0,0 +1,2 @@
|
||||
a = (b + c) * d
|
||||
a = b + c * d
|
2
test/simple-source/precedence/right.py
Normal file
2
test/simple-source/precedence/right.py
Normal file
@@ -0,0 +1,2 @@
|
||||
a = b * (c + d)
|
||||
a = b * c + d
|
2
test/simple-source/precedence/structure.py
Normal file
2
test/simple-source/precedence/structure.py
Normal file
@@ -0,0 +1,2 @@
|
||||
a = b + c + d + e
|
||||
a = b + c + (d + e)
|
@@ -665,9 +665,8 @@ class Python3Parser(PythonParser):
|
||||
"""
|
||||
new_rules = set()
|
||||
for token in tokens:
|
||||
if token.type not in ('CALL_FUNCTION', 'CALL_FUNCTION_VAR',
|
||||
if token.type in ('CALL_FUNCTION', 'CALL_FUNCTION_VAR',
|
||||
'CALL_FUNCTION_VAR_KW', 'CALL_FUNCTION_KW'):
|
||||
continue
|
||||
# Low byte indicates number of positional paramters,
|
||||
# high byte number of positional parameters
|
||||
args_pos = token.attr & 0xff
|
||||
|
@@ -17,6 +17,7 @@ from __future__ import print_function
|
||||
|
||||
import dis
|
||||
from collections import namedtuple
|
||||
from array import array
|
||||
|
||||
from uncompyle6 import PYTHON_VERSION
|
||||
from uncompyle6.scanner import Token, L65536
|
||||
@@ -36,21 +37,59 @@ class Scanner34(scan.Scanner):
|
||||
def __init__(self):
|
||||
scan.Scanner.__init__(self, 3.4) # check
|
||||
|
||||
def get_argument(self, bytecode, pos):
|
||||
arg = bytecode[pos+1] + bytecode[pos+2] * 256
|
||||
return arg
|
||||
|
||||
def disassemble(self, co):
|
||||
fn = self.disassemble_built_in if PYTHON_VERSION == 3.4 \
|
||||
else self.disassemble_cross_version
|
||||
return fn(co)
|
||||
|
||||
def disassemble_built_in(self, co):
|
||||
def disassemble_built_in(self, co, classname=None):
|
||||
# Container for tokens
|
||||
tokens = []
|
||||
self.code = co.co_code
|
||||
customize = {}
|
||||
self.code = array('B', co.co_code)
|
||||
self.build_lines_data(co)
|
||||
self.build_prev_op()
|
||||
|
||||
# Get jump targets
|
||||
# Format: {target offset: [jump offsets]}
|
||||
jump_targets = self.find_jump_targets()
|
||||
bytecode = dis.Bytecode(co)
|
||||
|
||||
# self.lines contains (block,addrLastInstr)
|
||||
# if classname:
|
||||
# classname = '_' + classname.lstrip('_') + '__'
|
||||
|
||||
# def unmangle(name):
|
||||
# if name.startswith(classname) and name[-2:] != '__':
|
||||
# return name[len(classname) - 2:]
|
||||
# return name
|
||||
|
||||
# free = [ unmangle(name) for name in (co.co_cellvars + co.co_freevars) ]
|
||||
# names = [ unmangle(name) for name in co.co_names ]
|
||||
# varnames = [ unmangle(name) for name in co.co_varnames ]
|
||||
# else:
|
||||
# free = co.co_cellvars + co.co_freevars
|
||||
# names = co.co_names
|
||||
# varnames = co.co_varnames
|
||||
|
||||
# Scan for assertions. Later we will
|
||||
# turn 'LOAD_GLOBAL' to 'LOAD_ASSERT' for those
|
||||
# assertions
|
||||
self.load_asserts = set()
|
||||
bs = list(bytecode)
|
||||
n = len(bs)
|
||||
for i in range(n):
|
||||
inst = bs[i]
|
||||
if inst.opname == 'POP_JUMP_IF_TRUE' and i+1 < n:
|
||||
next_inst = bs[i+1]
|
||||
if (next_inst.opname == 'LOAD_GLOBAL' and
|
||||
next_inst.argval == 'AssertionError'):
|
||||
self.load_asserts.add(next_inst.offset)
|
||||
|
||||
for inst in bytecode:
|
||||
if inst.offset in jump_targets:
|
||||
jump_idx = 0
|
||||
@@ -60,14 +99,38 @@ class Scanner34(scan.Scanner):
|
||||
jump_idx += 1
|
||||
pass
|
||||
pass
|
||||
|
||||
pattr = inst.argrepr
|
||||
opname = inst.opname
|
||||
|
||||
# For constants, the pattr is the same as attr. Using pattr adds
|
||||
# an extra level of quotes which messes other things up, like getting
|
||||
# keyword attribute names in a call. I suspect there will be things
|
||||
# other than LOAD_CONST, but we'll start out with just this for now.
|
||||
pattr = inst.argval if inst.opname in ['LOAD_CONST'] else inst.argrepr
|
||||
if opname in ['LOAD_CONST']:
|
||||
pattr = inst.argval
|
||||
elif opname in ('BUILD_LIST', 'BUILD_TUPLE', 'BUILD_SET', 'BUILD_SLICE',
|
||||
'UNPACK_SEQUENCE',
|
||||
'MAKE_FUNCTION', 'MAKE_CLOSURE',
|
||||
'DUP_TOPX', 'RAISE_VARARGS'
|
||||
):
|
||||
# if opname == 'BUILD_TUPLE' and \
|
||||
# self.code[self.prev[offset]] == LOAD_CLOSURE:
|
||||
# continue
|
||||
# else:
|
||||
# op_name = '%s_%d' % (op_name, oparg)
|
||||
# if opname != BUILD_SLICE:
|
||||
# customize[op_name] = oparg
|
||||
opname = '%s_%d' % (opname, inst.argval)
|
||||
if inst.opname != 'BUILD_SLICE':
|
||||
customize[opname] = inst.argval
|
||||
|
||||
elif inst.offset in self.load_asserts:
|
||||
opname = 'LOAD_ASSERT'
|
||||
|
||||
tokens.append(
|
||||
Token(
|
||||
type_ = inst.opname,
|
||||
type_ = opname,
|
||||
attr = inst.argval,
|
||||
pattr = pattr,
|
||||
offset = inst.offset,
|
||||
@@ -85,7 +148,7 @@ class Scanner34(scan.Scanner):
|
||||
"""
|
||||
# Container for tokens
|
||||
tokens = []
|
||||
self.code = code = co.co_code
|
||||
self.code = code = array('B', co.co_code)
|
||||
codelen = len(code)
|
||||
self.build_lines_data(co)
|
||||
self.build_prev_op()
|
||||
|
Reference in New Issue
Block a user