You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
Another 2.7 'continue' detection bug
This commit is contained in:
Binary file not shown.
@@ -9,3 +9,10 @@
|
||||
for a in [__name__]:
|
||||
try:len(a)
|
||||
except:continue
|
||||
|
||||
# The above has JUMP_ABSOLUTE in it.
|
||||
# This has JUMP_FORWARD instead.
|
||||
for a in [__name__]:
|
||||
try:len(a)
|
||||
except:continue
|
||||
y = 2
|
||||
|
@@ -161,20 +161,14 @@ class Scanner2(scan.Scanner):
|
||||
elif op in self.opc.hasname:
|
||||
pattr = names[oparg]
|
||||
elif op in self.opc.hasjrel:
|
||||
# use instead: hasattr(self, 'patch_continue'): ?
|
||||
if self.version == 2.7:
|
||||
self.patch_continue(tokens, offset, op)
|
||||
pattr = repr(offset + 3 + oparg)
|
||||
elif op in self.opc.hasjabs:
|
||||
if self.version == 2.7 and op == self.opc.JUMP_ABSOLUTE:
|
||||
target = self.get_target(offset)
|
||||
# FIXME: this is a hack to catch stuff like:
|
||||
# for ...
|
||||
# try: ...
|
||||
# except: continue
|
||||
# the "continue" is not on a new line.
|
||||
n = len(tokens)
|
||||
if (n > 2 and
|
||||
tokens[-1].type == 'JUMP_BACK' and
|
||||
self.code[offset+3] == self.opc.END_FINALLY):
|
||||
tokens[-1].type = intern('CONTINUE')
|
||||
# use instead: hasattr(self, 'patch_continue'): ?
|
||||
if self.version == 2.7:
|
||||
self.patch_continue(tokens, offset, op)
|
||||
pattr = repr(oparg)
|
||||
elif op in self.opc.haslocal:
|
||||
pattr = varnames[oparg]
|
||||
|
@@ -12,6 +12,11 @@ from __future__ import print_function
|
||||
|
||||
from uncompyle6.scanners.scanner2 import Scanner2
|
||||
|
||||
from uncompyle6 import PYTHON3
|
||||
if PYTHON3:
|
||||
import sys
|
||||
intern = sys.intern
|
||||
|
||||
# bytecode verification, verify(), uses JUMP_OPs from here
|
||||
from xdis.opcodes import opcode_27
|
||||
JUMP_OPs = opcode_27.JUMP_OPs
|
||||
@@ -76,6 +81,20 @@ class Scanner27(Scanner2):
|
||||
self.opc.JUMP_IF_TRUE_OR_POP])
|
||||
|
||||
return
|
||||
|
||||
def patch_continue(self, tokens, offset, op):
|
||||
if op in (self.opc.JUMP_FORWARD, self.opc.JUMP_ABSOLUTE):
|
||||
# FIXME: this is a hack to catch stuff like:
|
||||
# for ...
|
||||
# try: ...
|
||||
# except: continue
|
||||
# the "continue" is not on a new line.
|
||||
n = len(tokens)
|
||||
if (n > 2 and
|
||||
tokens[-1].type == 'JUMP_BACK' and
|
||||
self.code[offset+3] == self.opc.END_FINALLY):
|
||||
tokens[-1].type = intern('CONTINUE')
|
||||
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Reference in New Issue
Block a user