diff --git a/utils/asm.py b/utils/asm.py new file mode 100644 index 0000000..1823cf7 --- /dev/null +++ b/utils/asm.py @@ -0,0 +1,8 @@ +import subprocess +from glob import glob +from sys import argv + +path = argv[1] +paths = glob(f"{path}/*/*.main.asasm") +for path in paths: + subprocess.run(["rabcasm", path]) \ No newline at end of file diff --git a/utils/dasm.py b/utils/dasm.py new file mode 100644 index 0000000..d5ad74b --- /dev/null +++ b/utils/dasm.py @@ -0,0 +1,8 @@ +import subprocess +from glob import glob +from sys import argv + +path = argv[1] +paths = glob(f"{path}/*.abc") +for path in paths: + subprocess.run(["rabcdasm", path]) \ No newline at end of file diff --git a/utils/deob.py b/utils/deob.py new file mode 100644 index 0000000..0e148f1 --- /dev/null +++ b/utils/deob.py @@ -0,0 +1,94 @@ +from json import load +from sys import argv +from glob import glob +import re +from multiprocessing import Pool + +mappingPath = argv[1] +detailMappingPath = argv[2] +abcPath = argv[3] + +mapping = {} +with open(mappingPath, "r") as file: + mapping = load(file) + +detailMapping = {} +with open(detailMappingPath, "r") as file: + detailMapping = load(file) + +paths = glob(f"{abcPath}/**/**/*.asasm") + +def deobfuscateFile(path): + print(path) + with open(path, "r+") as reader: + className = path.split("/")[-1] + className = className.split(".")[0] + packageName = path.split("/")[-2] + + content_lines = reader.readlines() + + new_lines = [] + + for index, line in enumerate(content_lines): + if ( + not line.strip().startswith("#include") + and not line.strip().startswith("pushstring") + and index != 0 + ): + for entry in mapping: + fakePackageName = entry.split(":")[0] + fakeClassName = entry.split(":")[1] + if fakePackageName in line: + realName = mapping[f"{fakePackageName}:{fakeClassName}"].split(":")[0] + line = re.sub( + rf"(^|[\"\/:]){fakePackageName}([\"\/:]|$)", rf"\1{realName}\2", line + ) + if fakeClassName in line: + realName = mapping[f"{fakePackageName}:{fakeClassName}"].split(":")[1] + line = re.sub( + rf"(^|[\"\/:]){fakeClassName}([\"\/:]|$)", rf"\1{realName}\2", line + ) + #classs = detailMapping[packageName][className] + for package in detailMapping: + for classs in detailMapping[package]: + classs = detailMapping[package][classs] + for member in classs: + realMember = classs[member] + if realMember == None: continue + + memberChain = member.split("/") + memberName = memberChain[-1] + if memberName == "setter" or memberName == "getter": + memberName = memberChain[-2] + elif memberName == "init" or memberName == "final" or memberName.rstrip() == "each" or memberName == "package": + continue + if ":" in memberName: + memberName = memberName.split(":")[-1] + + realMemberChain = realMember.split("/") + realMemberName = realMemberChain[-1] + if realMemberName == "set" or realMemberName == "get": + realMemberName = realMemberChain[-2] + if ":" in realMemberName: + realMemberName = realMemberName.split(":")[-1] + if realMemberName == memberName: + continue + + if memberName in line: + line = re.sub( + rf"(^|[\"\/:]){memberName}([\"\/:]|$)", rf"\1{realMemberName}\2", line + ) + + new_lines.append(line) + + # Reset the file to the beginning and truncate the content + reader.seek(0) + reader.truncate() + + # Then write the new contents to the file + reader.writelines(new_lines) + +# for path in paths: +# deobfuscateFile(path) +pool = Pool(12) +pool.map(deobfuscateFile, paths) \ No newline at end of file diff --git a/utils/generatemapping.py b/utils/generatemapping.py new file mode 100644 index 0000000..fa0f848 --- /dev/null +++ b/utils/generatemapping.py @@ -0,0 +1,36 @@ +from sys import argv +from glob import glob + +from json import dump + +path = argv[1] +paths = glob(f"{path}/**/**/*.class.asasm") +paths += glob(f"{path}/**/*.class.asasm") + +names = {} +for path in paths: + name = None + with open(path, "r") as file: + className = path.split("/")[-1] + className = className.split(".class.asasm")[0] + packageName = path.split("/")[-2] + + if not packageName in names: + names[packageName] = {} + if not className in names[packageName]: + names[packageName][className] = {} + + for line in file: + line = line.strip() + if line.startswith("name"): + line = line.split("name \"") + line = line[1][:-1] + name = line + elif line.startswith("refid"): + line = line.split("refid \"") + line = line[1][:-1] + + names[packageName][className][line] = name + +with open("mapping.json", "w") as file: + dump(names, file) \ No newline at end of file diff --git a/utils/generatepmapping.py b/utils/generatepmapping.py new file mode 100644 index 0000000..d94fa19 --- /dev/null +++ b/utils/generatepmapping.py @@ -0,0 +1,22 @@ +from json import load, dump +from sys import argv + +mappingPath = argv[1] +mapping = {} +with open(mappingPath, "r") as file: + mapping = load(file) + +classMap = {} +for packageName in mapping: + package = mapping[packageName] + for className in package: + clas = package[className] + func = list(clas.values()) + if len(func) != 0: + func = func[1] + realName = func.split("/")[0] + fakeName = f"{packageName}:{className}" + classMap[fakeName] = realName + +with open("packagemap.json", "w") as file: + dump(classMap, file) \ No newline at end of file diff --git a/utils/replace.py b/utils/replace.py new file mode 100644 index 0000000..1d178b6 --- /dev/null +++ b/utils/replace.py @@ -0,0 +1,16 @@ +from sys import argv +from os import listdir +from os.path import isdir +import subprocess + +abcPath = argv[1] +swfPath = argv[2] + +for path in listdir(abcPath): + folder = path.split("/")[-1] + path = f"{abcPath}/{path}" + if not isdir(path): continue + abcIndex = folder.split("-")[-1] + abcFile = f"{path}/{folder}.main.abc" + print(f"{path} {abcIndex} {abcFile}") + subprocess.run(["abcreplace", swfPath, abcIndex, abcFile]) \ No newline at end of file