Created
October 19, 2019 01:42
-
-
Save Andoryuuta/5f4dff70a21d55f4b0960dad7613f5fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from xdis.load import load_module | |
from xdis.code import Code2Compat | |
import uncompyle6 | |
import xdis.main | |
import sys | |
if __name__ == "__main__": | |
if len(sys.argv) <= 1: | |
print("Usage: anti_decomp.py <some_py2_file.pyc>") | |
sys.exit(1) | |
filename = sys.argv[1] | |
filename_base = filename.split('.')[0] | |
(version, timestamp, magic_int, co, pypy, source_size) = load_module(filename) | |
opc = xdis.main.get_opcode(version, pypy) | |
co_code = bytearray(len(co.co_code)) | |
co_code[:] = co.co_code[:] | |
co_code.append(0x9) # Add a NOP | |
new_co = Code2Compat( | |
co.co_argcount, | |
co.co_nlocals, | |
co.co_stacksize, | |
co.co_flags, | |
co_code, | |
co.co_consts, | |
co.co_names, | |
co.co_varnames, | |
co.co_filename, | |
co.co_name, | |
co.co_firstlineno, | |
co.co_lnotab, | |
co.co_freevars, | |
co.co_cellvars, | |
) | |
# Crashes with: Parse error at or near `None' instruction at offset -1 | |
uncompyle6.main.decompile(version, new_co, sys.stdout) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment