scanner35.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copyright (c) 2017, 2021-2022, 2024 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. """
  16. Python 3.5 bytecode decompiler scanner
  17. Does some additional massaging of xdis-disassembled instructions to
  18. make things easier for decompilation.
  19. This sets up opcodes Python's 3.5 and calls a generalized
  20. scanner routine for Python 3.
  21. """
  22. # bytecode verification, verify(), uses JUMP_OPs from here
  23. from xdis.opcodes import opcode_35 as opc
  24. from uncompyle6.scanners.scanner3 import Scanner3
  25. JUMP_OPS = opc.JUMP_OPS
  26. class Scanner35(Scanner3):
  27. def __init__(self, show_asm=None, is_pypy=False):
  28. Scanner3.__init__(self, (3, 5), show_asm, is_pypy)
  29. return
  30. pass
  31. if __name__ == "__main__":
  32. from xdis.version_info import PYTHON_VERSION_TRIPLE, version_tuple_to_str
  33. if PYTHON_VERSION_TRIPLE[:2] == (3, 5):
  34. import inspect
  35. co = inspect.currentframe().f_code # type: ignore
  36. tokens, customize = Scanner35().ingest(co)
  37. for t in tokens:
  38. print(t.format())
  39. pass
  40. else:
  41. print("Need to be Python 3.5 to demo; I am version %s" % version_tuple_to_str())