This repository has been archived by the owner on Sep 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdecompiler.py
133 lines (119 loc) · 5.1 KB
/
decompiler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
from pathlib import Path
from shutil import copyfile,rmtree
import JDKcheck,subprocess,random,sys,os
checkJDK=True
removeBad=["summary.txt"]
import time
def copydir(source, dest):
"""Copy a directory structure overwriting existing files"""
for root, dirs, files in os.walk(source):
if not os.path.isdir(root):
os.makedirs(root)
for each_file in files:
rel_path = root.replace(source, '').lstrip(os.sep)
dest_path = os.path.join(dest, rel_path)
if not os.path.isdir(dest_path):
os.makedirs(dest_path)
dest_path=os.path.join(dest_path, each_file)
copyfile(os.path.join(root, each_file), dest_path)
def findjar():
path=Path("./1.13.1.jar")
if not path.exists():
path=Path("~/AppData/Roaming/.minecraft/versions/1.13.1/1.13.1.jar").expanduser()
if not path.exists():
path=None
print("No Jar found")
if path:
path=path.resolve()
return path
def decompileJar():
path=findjar()
if path:
cfr=Path("./lib/cfr_0_132.jar")
if cfr.exists():
cfr=cfr.resolve()
#ok that part isnt necessary but i want cfr to work
if checkJDK:
path_to_jdk=Path(JDKcheck.main())
if not path_to_jdk.exists():
path_to_jdk=None
print("Path to JDK is wrong af, put checkJDK=False in the import and relaunch if you are sure.")
else:
path_to_jdk=path_to_jdk.resolve()
subprocess.run(["java","-jar",cfr.__str__(),path.__str__(),"--outputdir","./temp","--caseinsensitivefs","true"],shell=True)
return True
else:
print("Missing a library: CFR")
else:
print("Missing a jar: 1.13.1.jar")
return False
def applyFileMappings():
obf=Path("./filesMappings/classes-obf.txt")
deobf=Path("./filesMappings/classes-deobf.txt")
mapping={}
if obf.exists() and deobf.exists():
#create the mapping dictionary for later application
with open(deobf) as d,open(obf) as o:
for e,el in zip(d,o):
if "$" not in el:
mapping[el.strip("\n")]=e.strip("\n")
#create the root node of the Tree
src="src/"
try:
Path(src).mkdir()
except FileExistsError:
print("I saw you already have a src, you might not want to change things in it, shall we create a new src directory? y/n ")
resp=input()
if resp.lower() in ["y","yes","ofc","yeah","yea","ye","yep","alright"]:
src="src"+str(random.getrandbits(128))+"/"
Path(src).mkdir()
else:
print("Shall i overwrite everything? y/n")
resp = input()
if resp.lower() not in ["y", "yes", "ofc", "yeah", "yea", "ye", "yep", "alright"]:
sys.exit()
#Apply the mappings and create the file Tree
path_to_temp = Path("./temp")
#remove some file generated by cfr
for el in removeBad:
if path_to_temp.joinpath(el).exists():
path_to_temp.joinpath(el).unlink()
for file in path_to_temp.iterdir():
if file.is_file():
nameObf=file.__str__().split("\\")[1].split(".")[0] if file.__str__().split("\\")[1].split(".")[1]=="java" else None
nameDeObf=mapping[nameObf] if nameObf in mapping else None
if nameDeObf:
route="/".join(nameDeObf.split("/")[:-1])
try:
Path(src).joinpath(route).mkdir(parents=True)
except FileExistsError:
pass
destination=Path(src).joinpath(nameDeObf+".java")
else:
print("I found one bad file: {}, it will be added at src/wtf/".format(file.__str__()))
try:
Path(src).joinpath("wtf").mkdir()
except FileExistsError:
pass
destination=Path(src).joinpath("wtf").joinpath(file.__str__().split("\\")[1])
source = Path(file)
if destination.exists():
mode='wb'
else:
mode="xb"
with destination.open(mode=mode) as fid:
fid.write(source.read_bytes())
else:
copydir(file.__str__(),src.strip("/")+"\\net")
rmtree("temp/")
else:
print("Missing files mappings: obf and deobf")
if __name__=="__main__":
t=time.time()
print("Starting, might take a few seconds to minutes, depends of your potato")
decompileJar()
print("Decompilation completed, starting the file renaming")
applyFileMappings()
print("File Renaming, starting the class name renaming (wip for now)")
print("Done in {}".format(time.time()-t))
print("Your files will be in /src")