scanner34.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copyright (c) 2015-2018, 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. """
  16. Python 3.4 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.4 and calls a generalized
  20. scanner routine for Python 3.
  21. """
  22. from __future__ import print_function
  23. from xdis.opcodes import opcode_34 as opc
  24. # bytecode verification, verify(), uses JUMP_OPs from here
  25. JUMP_OPS = opc.JUMP_OPS
  26. from uncompyle6.scanners.scanner3 import Scanner3
  27. class Scanner34(Scanner3):
  28. def __init__(self, show_asm=None):
  29. Scanner3.__init__(self, (3, 4), show_asm)
  30. return
  31. pass
  32. if __name__ == "__main__":
  33. from xdis.version_info import PYTHON_VERSION_TRIPLE, version_tuple_to_str
  34. if PYTHON_VERSION_TRIPLE[:2] == (3, 4):
  35. import inspect
  36. co = inspect.currentframe().f_code # type: ignore
  37. tokens, customize = Scanner34().ingest(co)
  38. for t in tokens:
  39. print(t.format())
  40. pass
  41. else:
  42. print("Need to be Python 3.4 to demo; I am version %s" % version_tuple_to_str())