Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support high version python to decompile low version pyc #453

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions uncompyle6/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@

from uncompyle6.semantics.pysource import code_deparse, deparse_code2str


PYC_version = 3.6

__all__ = [
"__version__",
"code_deparse",
Expand Down
5 changes: 3 additions & 2 deletions uncompyle6/bin/uncompile.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

program = 'uncompyle6'

from uncompyle6 import verify
from uncompyle6 import verify, PYC_version
from uncompyle6.main import main, status_msg
from uncompyle6.version import __version__

Expand All @@ -72,7 +72,8 @@ def usage():


def main_bin():
if not (sys.version_info[0:2] in ((2, 6), (2, 7), (3, 0),
ver = (int(PYC_version), int((PYC_version - int(PYC_version)) * 10))
if not (ver in ((2, 6), (2, 7), (3, 0),
(3, 1), (3, 2), (3, 3),
(3, 4), (3, 5), (3, 6),
(3, 7), (3, 8), (3, 9), (3, 10)
Expand Down
4 changes: 4 additions & 0 deletions uncompyle6/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

from xdis.load import load_module

from uncompyle6 import PYC_version

def _get_outstream(outfile: str) -> Any:
dir = os.path.dirname(outfile)
failed_file = outfile + "_failed"
Expand Down Expand Up @@ -192,6 +194,8 @@ def decompile_file(
filename, code_objects
)

PYC_version = version

if isinstance(co, list):
deparsed = []
for bytecode in co:
Expand Down
37 changes: 21 additions & 16 deletions uncompyle6/scanners/tok.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,27 @@ def __init__(
self.pattr = None

if opc is None:
try:
from xdis.std import _std_api
except KeyError as e:
print(f"I don't know about Python version {e} yet.")
try:
version_tuple = tuple(int(i) for i in str(e)[1:-1].split("."))
except Exception:
pass
else:
if version_tuple > (3, 9):
print("Python versions 3.9 and greater are not supported.")
else:
print(f"xdis might need to be informed about version {e}")
return

self.opc = _std_api.opc
from uncompyle6 import PYC_version
from xdis.std import make_std_api

self.opc = make_std_api(PYC_version).opc

# try:
# from xdis.std import _std_api
# except KeyError as e:
# print(f"I don't know about Python version {e} yet.")
# try:
# version_tuple = tuple(int(i) for i in str(e)[1:-1].split("."))
# except Exception:
# pass
# else:
# if version_tuple > (3, 9):
# print("Python versions 3.9 and greater are not supported.")
# else:
# print(f"xdis might need to be informed about version {e}")
# return

# self.opc = _std_api.opc
else:
self.opc = opc
if op is None:
Expand Down