Skip to content

Instantly share code, notes, and snippets.

@friedkeenan
Last active December 15, 2019 07:20
Show Gist options
  • Select an option

  • Save friedkeenan/538749ab928c05523041ae51bc7f8688 to your computer and use it in GitHub Desktop.

Select an option

Save friedkeenan/538749ab928c05523041ae51bc7f8688 to your computer and use it in GitHub Desktop.
Scripts to further deobfuscate deobfuscated Transformice code
#!/usr/bin/env python3
import sys
import re
def get_num_methods(string):
m = re.search(r'private function method_(\d+)\(... rest\) : Object(\s*\{\s*)return const_1\[(\d+)\];(\s*\}\s*\})', string)
return int(m.group(1))
def index_for_method(method_num, string):
search_string = r'private function method_' + str(method_num) + r'\(... rest\) : Object(\s*\{\s*)return const_1\[(\d+)\]'
m = re.search(search_string, string)
return int(m.group(2))
def main(args):
with open(args[0]) as f:
obf = f.read()
chars = re.search(r'private static const const_1:Object = "([^"]+)', obf).group(1)
num_methods = get_num_methods(obf)
for i in range(1, num_methods + 1):
c = chars[index_for_method(i, obf)]
obf = obf.replace(f"this.method_{i}()", f'"{c}"')
obf = obf.replace('" + "', "")
with open(args[1], "w") as f:
f.write(obf)
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
#!/usr/bin/env python3
import sys
import re
from pathlib import Path
def main(args):
in_file = Path(args[0])
scripts_dir = Path(args[1])
class_only_return = args[2]
out_file = Path(args[3])
with in_file.open() as f:
obf = f.read()
obf_class = ""
class_m = re.search(r"class class_(\d+)", obf)
if class_m is not None:
obf_class = class_m.group(1)
def var_repl(m):
with Path(scripts_dir, f"class_{m.group(1)}.as").open() as f:
cont = f.read()
new_m = re.search(r"var_" + m.group(2) + r":(\S+\s*=\s*)(.+);", cont)
if m.group(1) == obf_class or new_m is None:
return f"class_{m.group(1)}.var_{m.group(2)}{m.group(3)}"
return new_m.group(2) + m.group(3)
obf = re.sub(r"class_(\d+)\.var_(\d+)(.(?==|.))", var_repl, obf)
obf = re.sub(r"class_" + class_only_return + r"\.method_(\d+)\(([^)]+)\)", r"\2", obf)
obf = obf.replace('" + "', "")
with out_file.open("w") as f:
f.write(obf)
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment