-
Notifications
You must be signed in to change notification settings - Fork 4
/
mcp.py
218 lines (197 loc) · 8.19 KB
/
mcp.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 19 15:04:52 2012
@author: Fesh0r
@version: v1.0
"""
import time
from commands import CLIENT, SIDE_NAME
def decompile_side(commands, side, use_ff=False, use_srg=False, no_comments=False, no_reformat=False, no_renamer=False,
no_patch=False, strip_comments=True, exc_update=False, keep_lvt=False, keep_generics=False, force_rg=False, rg_update=False,
joined=False):
if not commands.checkjars(side):
commands.logger.warning('!! Missing %s jar file. Aborting !!', SIDE_NAME[side])
return False
if commands.checksourcedir(side):
commands.logger.warning('!! %s already decompiled. Run cleanup before decompiling again !!', SIDE_NAME[side])
return False
starttime = time.time()
decompiler = 'JAD'
if use_ff:
decompiler = 'fernflower'
commands.logger.info('== Decompiling %s using %s ==', SIDE_NAME[side], decompiler)
if joined:
commands.logger.info('> Using Joined variants')
commands.logger.info('> Creating SRGs')
commands.createsrgs(side, use_srg=use_srg, rg_update=rg_update)
if force_rg:
commands.logger.info('> Applying Retroguard')
commands.applyrg(side)
else:
commands.logger.info('> Applying SpecialSource')
commands.applyss(side, keep_lvt=keep_lvt, keep_generics=keep_generics,joined=joined)
commands.logger.info('> Applying MCInjector')
commands.applyexceptor(side, exc_update=exc_update)
commands.logger.info('> Creating renamed srg')
commands.createclssrg(side)
if use_ff:
commands.logger.info('> Filtering classes')
commands.filterffjar(side)
commands.logger.info('> Decompiling')
commands.applyff(side)
else:
commands.logger.info('> Unpacking jar')
commands.extractjar(side)
commands.logger.info('> Copying classes')
commands.copycls(side)
commands.logger.info('> Applying jadretro')
commands.applyjadretro(side)
commands.logger.info('> Decompiling')
commands.applyjad(side)
commands.logger.info('> Copying sources')
commands.copysrc(side)
if use_ff:
commands.logger.info('> Applying fernflower fixes')
commands.process_fffixes(side)
else:
commands.logger.info('> Applying JAD fixes')
commands.process_jadfixes(side)
if commands.osname == 'osx' and not no_patch:
commands.logger.info('> Applying OSX JAD fixes')
commands.applypatches(side, use_ff=False, use_osx=True)
if not no_patch:
if joined:
commands.logger.info('> Applying Joined patches')
else:
commands.logger.info('> Applying patches')
commands.applypatches(side, use_ff=use_ff, use_joined=joined)
if strip_comments:
commands.logger.info('> Cleaning comments')
commands.process_comments(side)
else:
commands.logger.warning('!! comment cleaning disabled !!')
else:
commands.logger.warning('!! patches disabled !!')
commands.logger.info('- Done in %.2f seconds', time.time() - starttime)
if not no_reformat:
reformat_side(commands, side)
else:
commands.logger.warning('!! reformating disabled !!')
if not no_renamer:
updatenames_side(commands, side, no_comments=no_comments)
else:
commands.logger.warning('!! renaming disabled !!')
return True
def reformat_side(commands, side):
if not commands.checksourcedir(side):
return False
starttime = time.time()
commands.logger.info('== Reformating %s ==', SIDE_NAME[side])
commands.logger.info('> Cleaning sources')
commands.process_cleanup(side)
if side == CLIENT:
commands.logger.info('> Replacing OpenGL constants')
commands.process_annotate(side)
if commands.has_astyle:
commands.logger.info('> Reformating sources')
commands.applyastyle(side)
else:
commands.logger.warning('!! reformating disabled due to no astyle or config !!')
commands.logger.info('- Done in %.2f seconds', time.time() - starttime)
return True
def updatenames_side(commands, side, no_comments=False):
if not commands.checksourcedir(side):
return False
starttime = time.time()
commands.logger.info('== Updating %s ==', SIDE_NAME[side])
if not no_comments:
if commands.has_doc_csv:
commands.logger.info('> Adding javadoc')
commands.process_javadoc(side)
else:
commands.logger.warning('!! javadoc disabled due to no csvs !!')
else:
commands.logger.warning('!! javadoc disabled !!')
if commands.has_name_csv:
commands.logger.info('> Renaming sources')
commands.process_rename(side)
else:
commands.logger.warning('!! renaming disabled due to no csvs !!')
commands.logger.info('- Done in %.2f seconds', time.time() - starttime)
return True
def recompile_side(commands, side):
if not commands.checksources(side):
commands.logger.warning('!! Can not find %s sources, try decompiling !!', SIDE_NAME[side])
return False
starttime = time.time()
commands.logger.info('== Recompiling %s ==', SIDE_NAME[side])
commands.logger.info('> Cleaning bin')
commands.cleanbindirs(side)
commands.logger.info('> Recompiling')
commands.recompile(side)
commands.logger.info('- Done in %.2f seconds', time.time() - starttime)
return True
def updatemd5_side(commands, side):
recomp = recompile_side(commands, side)
if recomp:
commands.logger.info('> Generating %s md5s', SIDE_NAME[side])
commands.gathermd5s(side)
return True
return False
def reobfuscate_side(commands, side, reobf_all=False, srg_names=False, force_rg=False, keep_lvt=True, keep_generics=False):
if not commands.checkmd5s(side):
commands.logger.warning('!! Can not find %s md5s !!', SIDE_NAME[side])
return False
if not commands.checkbins(side):
commands.logger.warning('!! Can not find %s bins, try recompiling !!', SIDE_NAME[side])
return False
starttime = time.time()
commands.logger.info('== Reobfuscating %s ==', SIDE_NAME[side])
commands.logger.info('> Cleaning reobf')
commands.cleanreobfdir(side)
commands.logger.info('> Generating md5s')
commands.gathermd5s(side, True)
commands.logger.info('> Packing jar')
commands.packbin(side)
commands.logger.info('> Generating class markers')
commands.applyexceptor(side, dryrun=True)
#commands.cmpclassmarkers(side)
# List gen by MCInjector should be done here
commands.logger.info('> Creating reobf mapping')
commands.creatergreobfsrg(side)
if srg_names:
commands.logger.info('> Creating srg maping')
commands.createreobfsrg()
commands.logger.info('> Reobfuscating jar')
if force_rg:
commands.applyrg(side, True)
else:
commands.applyss(side, True, srg_names=srg_names, keep_lvt=keep_lvt, keep_generics=keep_generics)
commands.logger.info('> Extracting modified classes')
commands.unpackreobfclasses(side, reobf_all, srg_names=srg_names)
commands.logger.info('- Done in %.2f seconds', time.time() - starttime)
return True
def getchangedsrc_side(commands, side):
if not commands.checkmd5s(side):
commands.logger.warning('!! Can not find %s md5s !!', SIDE_NAME[side])
return False
if not commands.checksources(side):
commands.logger.warning('!! Can not find %s sources !!', SIDE_NAME[side])
return False
commands.logger.info('> Getting changed %s source', SIDE_NAME[side])
commands.gathermd5s(side, True)
commands.unpackmodifiedclasses(side)
return True
def updateids_side(commands, side, no_comments=False):
if not commands.checksourcedir(side):
return False
starttime = time.time()
commands.logger.info('== Updating %s ==', SIDE_NAME[side])
if commands.has_renumber_csv:
commands.logger.info('> Renumbering sources')
commands.process_renumber(side)
else:
commands.logger.warning('!! renumbering disabled due to no csvs !!')
commands.logger.info('- Done in %.2f seconds', time.time() - starttime)
return True