scanner39.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copyright (c) 2019, 2021-2022 by Rocky Bernstein
  2. #
  3. # This program is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. """Python 3.9 bytecode decompiler scanner.
  16. Does some token massaging of xdis-disassembled instructions to make
  17. things easier for decompilation.
  18. This sets up opcodes Python's 3.9 and calls a generalized
  19. scanner routine for Python 3.7 and up.
  20. """
  21. # bytecode verification, verify(), uses JUMP_OPs from here
  22. from xdis.opcodes import opcode_38 as opc
  23. from decompyle3.scanners.scanner38 import Scanner38
  24. # bytecode verification, verify(), uses JUMP_OPS from here
  25. JUMP_OPs = opc.JUMP_OPS
  26. class Scanner39(Scanner38):
  27. def __init__(self, show_asm=None):
  28. Scanner38.__init__(self, (3, 9), show_asm)
  29. return
  30. pass
  31. if __name__ == "__main__":
  32. from xdis.version_info import PYTHON_VERSION
  33. if PYTHON_VERSION == 3.9:
  34. import inspect
  35. co = inspect.currentframe().f_code # type: ignore
  36. tokens, customize = Scanner39().ingest(co)
  37. for t in tokens:
  38. print(t.format())
  39. pass
  40. else:
  41. print(f"Need to be Python 3.9 to demo; I am {PYTHON_VERSION}.")