Update scanner demo code

This commit is contained in:
rocky 2022-04-17 11:41:19 -04:00
parent f8ae674890
commit c806ef59c6
14 changed files with 117 additions and 77 deletions

View File

@ -1,4 +1,4 @@
# Copyright (c) 2016-2017, 2021 by Rocky Bernstein
# Copyright (c) 2016-2017, 2021-2022 by Rocky Bernstein
"""
Python 2.4 bytecode massaging.
@ -27,3 +27,18 @@ class Scanner24(scan.Scanner25):
self.version = (2, 4)
self.genexpr_name = "<generator expression>"
return
if __name__ == "__main__":
from xdis.version_info import PYTHON_VERSION_TRIPLE, version_tuple_to_str
if PYTHON_VERSION_TRIPLE[:2] == (2, 4):
import inspect
co = inspect.currentframe().f_code # type: ignore
tokens, customize = Scanner24().ingest(co)
for t in tokens:
print(t.format())
pass
else:
print("Need to be Python 2.4 to demo; I am version %s" % version_tuple_to_str())

View File

@ -1,4 +1,4 @@
# Copyright (c) 2015-2018, 2021 by Rocky Bernstein
# Copyright (c) 2015-2018, 2021-2022 by Rocky Bernstein
"""
Python 2.5 bytecode massaging.
@ -26,3 +26,18 @@ class Scanner25(scan.Scanner26):
scan.Scanner26.__init__(self, show_asm)
self.version = (2, 5)
return
if __name__ == "__main__":
from xdis.version_info import PYTHON_VERSION_TRIPLE, version_tuple_to_str
if PYTHON_VERSION_TRIPLE[:2] == (2, 5):
import inspect
co = inspect.currentframe().f_code # type: ignore
tokens, customize = Scanner25().ingest(co)
for t in tokens:
print(t.format())
pass
else:
print("Need to be Python 2.5 to demo; I am version %s" % version_tuple_to_str())

View File

@ -1,4 +1,4 @@
# Copyright (c) 2015-2017, 2021 by Rocky Bernstein
# Copyright (c) 2015-2017, 2021-2022 by Rocky Bernstein
# Copyright (c) 2005 by Dan Pascu <dan@windowmaker.org>
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
#
@ -280,3 +280,18 @@ class Scanner26(scan.Scanner2):
print(t.format(line_prefix=""))
print()
return tokens, customize
if __name__ == "__main__":
from xdis.version_info import PYTHON_VERSION_TRIPLE, version_tuple_to_str
if PYTHON_VERSION_TRIPLE[:2] == (2, 6):
import inspect
co = inspect.currentframe().f_code # type: ignore
tokens, customize = Scanner26().ingest(co)
for t in tokens:
print(t.format())
pass
else:
print("Need to be Python 2.6 to demo; I am version %s" % version_tuple_to_str())

View File

@ -1,4 +1,4 @@
# Copyright (c) 2015-2018, 2021 by Rocky Bernstein
# Copyright (c) 2015-2018, 2021-2022 by Rocky Bernstein
"""
Python 2.7 bytecode ingester.
@ -113,10 +113,10 @@ if __name__ == "__main__":
if PYTHON_VERSION_TRIPLE[:2] == (2, 7):
import inspect
co = inspect.currentframe().f_code
co = inspect.currentframe().f_code # type: ignore
tokens, customize = Scanner27().ingest(co)
for t in tokens:
print(t)
print(t.format())
pass
else:
print("Need to be Python 2.7 to demo; I am %s." % version_tuple_to_str())
print("Need to be Python 2.7 to demo; I am version %s" % version_tuple_to_str())

View File

@ -471,15 +471,16 @@ class Scanner30(Scanner3):
if __name__ == "__main__":
from uncompyle6 import PYTHON_VERSION
from xdis.version_info import PYTHON_VERSION_TRIPLE, version_tuple_to_str
if PYTHON_VERSION == (3, 0):
if PYTHON_VERSION_TRIPLE[:2] == (3, 0):
import inspect
co = inspect.currentframe().f_code
co = inspect.currentframe().f_code # type: ignore
tokens, customize = Scanner30().ingest(co)
for t in tokens:
print(t)
print(t.format())
pass
else:
print("Need to be Python 3.0 to demo; I am %s." % PYTHON_VERSION)
print("Need to be Python 3.0 to demo; I am version %s" % version_tuple_to_str())
[w

View File

@ -1,4 +1,4 @@
# Copyright (c) 2016-2017, 2021 by Rocky Bernstein
# Copyright (c) 2016-2017, 2021-2022 by Rocky Bernstein
"""
Python 3.1 bytecode scanner/deparser
@ -21,14 +21,15 @@ class Scanner31(Scanner3):
pass
if __name__ == "__main__":
from uncompyle6 import PYTHON_VERSION
if PYTHON_VERSION == (3, 1):
from xdis.version_info import PYTHON_VERSION_TRIPLE, version_tuple_to_str
if PYTHON_VERSION_TRIPLE[:2] == (3, 1):
import inspect
co = inspect.currentframe().f_code
co = inspect.currentframe().f_code # type: ignore
tokens, customize = Scanner31().ingest(co)
for t in tokens:
print(t)
print(t.format())
pass
else:
print("Need to be Python 3.1 to demo; I am %s." %
PYTHON_VERSION)
print("Need to be Python 3.1 to demo; I am version %s" % version_tuple_to_str())

View File

@ -1,4 +1,4 @@
# Copyright (c) 2015-2017, 2021 by Rocky Bernstein
# Copyright (c) 2015-2017, 2021-2022 by Rocky Bernstein
"""
Python 3.2 bytecode decompiler scanner.
@ -24,14 +24,15 @@ class Scanner32(Scanner3):
pass
if __name__ == "__main__":
from uncompyle6 import PYTHON_VERSION
if PYTHON_VERSION == 3.2:
from xdis.version_info import PYTHON_VERSION_TRIPLE, version_tuple_to_str
if PYTHON_VERSION_TRIPLE[:2] == (3, 2):
import inspect
co = inspect.currentframe().f_code
co = inspect.currentframe().f_code # type: ignore
tokens, customize = Scanner32().ingest(co)
for t in tokens:
print(t)
print(t.format())
pass
else:
print("Need to be Python 3.2 to demo; I am %s." %
PYTHON_VERSION)
print("Need to be Python 3.2 to demo; I am version %s" % version_tuple_to_str())

View File

@ -1,4 +1,4 @@
# Copyright (c) 2015-2019, 2021 by Rocky Bernstein
# Copyright (c) 2015-2019, 2021-2022 by Rocky Bernstein
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -34,14 +34,15 @@ class Scanner33(Scanner3):
pass
if __name__ == "__main__":
from uncompyle6 import PYTHON_VERSION
if PYTHON_VERSION == 3.3:
from xdis.version_info import PYTHON_VERSION_TRIPLE, version_tuple_to_str
if PYTHON_VERSION_TRIPLE[:2] == (3, 3):
import inspect
co = inspect.currentframe().f_code
co = inspect.currentframe().f_code # type: ignore
tokens, customize = Scanner33().ingest(co)
for t in tokens:
print(t)
print(t.format())
pass
else:
print("Need to be Python 3.3 to demo; I am %s." %
PYTHON_VERSION)
print("Need to be Python 3.3 to demo; I am version %s" % version_tuple_to_str())

View File

@ -1,4 +1,4 @@
# Copyright (c) 2015-2018 by Rocky Bernstein
# Copyright (c) 2015-2018, 2022 by Rocky Bernstein
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -39,14 +39,15 @@ class Scanner34(Scanner3):
pass
if __name__ == "__main__":
from uncompyle6 import PYTHON_VERSION
if PYTHON_VERSION == 3.4:
from xdis.version_info import PYTHON_VERSION_TRIPLE, version_tuple_to_str
if PYTHON_VERSION_TRIPLE[:2] == (3, 4):
import inspect
co = inspect.currentframe().f_code
co = inspect.currentframe().f_code # type: ignore
tokens, customize = Scanner34().ingest(co)
for t in tokens:
print(t)
print(t.format())
pass
else:
print("Need to be Python 3.4 to demo; I am %s." %
PYTHON_VERSION)
print("Need to be Python 3.4 to demo; I am version %s" % version_tuple_to_str())

View File

@ -1,4 +1,4 @@
# Copyright (c) 2017, 2021 by Rocky Bernstein
# Copyright (c) 2017, 2021-2022 by Rocky Bernstein
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -38,14 +38,15 @@ class Scanner35(Scanner3):
pass
if __name__ == "__main__":
from uncompyle6 import PYTHON_VERSION
if PYTHON_VERSION == 3.5:
from xdis.version_info import PYTHON_VERSION_TRIPLE, version_tuple_to_str
if PYTHON_VERSION_TRIPLE[:2] == (3, 5):
import inspect
co = inspect.currentframe().f_code
co = inspect.currentframe().f_code # type: ignore
tokens, customize = Scanner35().ingest(co)
for t in tokens:
print(t)
print(t.format())
pass
else:
print("Need to be Python 3.5 to demo; I am %s." %
PYTHON_VERSION)
print("Need to be Python 3.5 to demo; I am version %s" % version_tuple_to_str())

View File

@ -50,14 +50,15 @@ class Scanner36(Scanner3):
return tokens, customize
if __name__ == "__main__":
from uncompyle6 import PYTHON_VERSION
if PYTHON_VERSION == 3.6:
from xdis.version_info import PYTHON_VERSION_TRIPLE, version_tuple_to_str
if PYTHON_VERSION_TRIPLE[:2] == (3, 6):
import inspect
co = inspect.currentframe().f_code
co = inspect.currentframe().f_code # type: ignore
tokens, customize = Scanner36().ingest(co)
for t in tokens:
print(t.format())
pass
else:
print("Need to be Python 3.6 to demo; I am %s." %
PYTHON_VERSION)
print("Need to be Python 3.6 to demo; I am version %s" % version_tuple_to_str())

View File

@ -1,4 +1,4 @@
# Copyright (c) 2016-2019, 2021 by Rocky Bernstein
# Copyright (c) 2016-2019, 2021-2022 by Rocky Bernstein
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -63,15 +63,15 @@ class Scanner37(Scanner37Base):
return tokens, customize
if __name__ == "__main__":
from uncompyle6 import PYTHON_VERSION
if PYTHON_VERSION == 3.7:
from xdis.version_info import PYTHON_VERSION_TRIPLE, version_tuple_to_str
if PYTHON_VERSION_TRIPLE[:2] == (3, 7):
import inspect
co = inspect.currentframe().f_code
co = inspect.currentframe().f_code # type: ignore
tokens, customize = Scanner37().ingest(co)
for t in tokens:
print(t.format())
pass
else:
print("Need to be Python 3.7 to demo; I am %s." %
PYTHON_VERSION)
print("Need to be Python 3.7 to demo; I am version %s" % version_tuple_to_str())

View File

@ -1,4 +1,4 @@
# Copyright (c) 2019-2021 by Rocky Bernstein
# Copyright (c) 2019-2022 by Rocky Bernstein
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -128,15 +128,15 @@ class Scanner38(Scanner37):
if __name__ == "__main__":
from uncompyle6 import PYTHON_VERSION
from xdis.version_info import PYTHON_VERSION_TRIPLE, version_tuple_to_str
if PYTHON_VERSION == 3.8:
if PYTHON_VERSION_TRIPLE[:2] == (3, 8):
import inspect
co = inspect.currentframe().f_code
co = inspect.currentframe().f_code # type: ignore
tokens, customize = Scanner38().ingest(co)
for t in tokens:
print(t.format())
pass
else:
print("Need to be Python 3.8 to demo; I am %s." % PYTHON_VERSION)
print("Need to be Python 3.8 to demo; I am version %s" % version_tuple_to_str())

View File

@ -1,4 +1,4 @@
# Copyright (c) 2019, 2021 by Rocky Bernstein
# Copyright (c) 2019, 2021-2022 by Rocky Bernstein
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -40,16 +40,4 @@ class Scanner39(Scanner38):
if __name__ == "__main__":
from uncompyle6 import PYTHON_VERSION
if PYTHON_VERSION == 3.9:
import inspect
co = inspect.currentframe().f_code
tokens, customize = Scanner39().ingest(co)
for t in tokens:
print(t.format())
pass
else:
print("Need to be Python 3.9 to demo; I am %s." %
PYTHON_VERSION)
print("Note: Python 3.9 decompilation not supported")