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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
|
/*******************************************************************************
* Copyright (c) 2015 Jeff Martin.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser General Public
* License v3.0 which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Contributors:
* Jeff Martin - initial API and implementation
******************************************************************************/
package cuchaz.enigma;
import com.google.common.base.Stopwatch;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.strobel.assembler.metadata.MetadataSystem;
import com.strobel.assembler.metadata.TypeDefinition;
import com.strobel.assembler.metadata.TypeReference;
import com.strobel.decompiler.DecompilerContext;
import com.strobel.decompiler.DecompilerSettings;
import com.strobel.decompiler.PlainTextOutput;
import com.strobel.decompiler.languages.java.JavaOutputVisitor;
import com.strobel.decompiler.languages.java.ast.AstBuilder;
import com.strobel.decompiler.languages.java.ast.CompilationUnit;
import com.strobel.decompiler.languages.java.ast.InsertParenthesesVisitor;
import cuchaz.enigma.analysis.*;
import cuchaz.enigma.bytecode.ClassProtectifier;
import cuchaz.enigma.bytecode.ClassPublifier;
import cuchaz.enigma.mapping.*;
import cuchaz.enigma.mapping.entry.*;
import cuchaz.enigma.throwables.IllegalNameException;
import cuchaz.enigma.utils.Utils;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode;
import java.io.*;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;
public class Deobfuscator {
private final ReferencedEntryPool entryPool = new ReferencedEntryPool();
private final ParsedJar parsedJar;
private final DecompilerSettings settings;
private final JarIndex jarIndex;
private final MappingsRenamer renamer;
private final Map<TranslationDirection, Translator> translatorCache;
private Mappings mappings;
public Deobfuscator(ParsedJar jar) {
this.parsedJar = jar;
// build the jar index
this.jarIndex = new JarIndex(entryPool);
this.jarIndex.indexJar(this.parsedJar, true);
// config the decompiler
this.settings = DecompilerSettings.javaDefaults();
this.settings.setMergeVariables(Utils.getSystemPropertyAsBoolean("enigma.mergeVariables", true));
this.settings.setForceExplicitImports(Utils.getSystemPropertyAsBoolean("enigma.forceExplicitImports", true));
this.settings.setForceExplicitTypeArguments(
Utils.getSystemPropertyAsBoolean("enigma.forceExplicitTypeArguments", true));
// DEBUG
this.settings.setShowDebugLineNumbers(Utils.getSystemPropertyAsBoolean("enigma.showDebugLineNumbers", false));
this.settings.setShowSyntheticMembers(Utils.getSystemPropertyAsBoolean("enigma.showSyntheticMembers", false));
// init defaults
this.translatorCache = Maps.newTreeMap();
this.renamer = new MappingsRenamer(this.jarIndex, null, this.entryPool);
// init mappings
setMappings(new Mappings());
}
public Deobfuscator(JarFile jar) throws IOException {
this(new ParsedJar(jar));
}
public ParsedJar getJar() {
return this.parsedJar;
}
public JarIndex getJarIndex() {
return this.jarIndex;
}
public Mappings getMappings() {
return this.mappings;
}
public void setMappings(Mappings val) {
setMappings(val, true);
}
public void setMappings(Mappings val, boolean warnAboutDrops) {
if (val == null) {
val = new Mappings();
}
// drop mappings that don't match the jar
MappingsChecker checker = new MappingsChecker(this.jarIndex);
checker.dropBrokenMappings(val);
if (warnAboutDrops) {
for (Map.Entry<ClassEntry, ClassMapping> mapping : checker.getDroppedClassMappings().entrySet()) {
System.out.println("WARNING: Couldn't find class entry " + mapping.getKey() + " (" + mapping.getValue().getDeobfName() + ") in jar. Mapping was dropped.");
}
for (Map.Entry<ClassEntry, ClassMapping> mapping : checker.getDroppedInnerClassMappings().entrySet()) {
System.out.println("WARNING: Couldn't find inner class entry " + mapping.getKey() + " (" + mapping.getValue().getDeobfName() + ") in jar. Mapping was dropped.");
}
for (Map.Entry<FieldEntry, FieldMapping> mapping : checker.getDroppedFieldMappings().entrySet()) {
System.out.println("WARNING: Couldn't find field entry " + mapping.getKey() + " (" + mapping.getValue().getDeobfName() + ") in jar. Mapping was dropped.");
}
for (Map.Entry<MethodEntry, MethodMapping> mapping : checker.getDroppedMethodMappings().entrySet()) {
System.out.println("WARNING: Couldn't find behavior entry " + mapping.getKey() + " (" + mapping.getValue().getDeobfName() + ") in jar. Mapping was dropped.");
}
}
this.mappings = val;
this.renamer.setMappings(mappings);
this.translatorCache.clear();
}
public Translator getTranslator(TranslationDirection direction) {
return this.translatorCache.computeIfAbsent(direction,
k -> this.mappings.getTranslator(direction, this.jarIndex.getTranslationIndex()));
}
public void getSeparatedClasses(List<ClassEntry> obfClasses, List<ClassEntry> deobfClasses) {
for (ClassEntry obfClassEntry : this.jarIndex.getObfClassEntries()) {
// skip inner classes
if (obfClassEntry.isInnerClass()) {
continue;
}
// separate the classes
ClassEntry deobfClassEntry = deobfuscateEntry(obfClassEntry);
if (!deobfClassEntry.equals(obfClassEntry)) {
// if the class has a mapping, clearly it's deobfuscated
deobfClasses.add(deobfClassEntry);
} else if (obfClassEntry.getPackageName() != null) {
// also call it deobufscated if it's not in the none package
deobfClasses.add(obfClassEntry);
} else {
// otherwise, assume it's still obfuscated
obfClasses.add(obfClassEntry);
}
}
}
public TranslatingTypeLoader createTypeLoader() {
return new TranslatingTypeLoader(
this.parsedJar,
this.jarIndex,
this.entryPool,
getTranslator(TranslationDirection.OBFUSCATING),
getTranslator(TranslationDirection.DEOBFUSCATING)
);
}
public CompilationUnit getSourceTree(String className) {
// we don't know if this class name is obfuscated or deobfuscated
// we need to tell the decompiler the deobfuscated name so it doesn't get freaked out
// the decompiler only sees classes after deobfuscation, so we need to load it by the deobfuscated name if there is one
// first, assume class name is deobf
String deobfClassName = className;
// if it wasn't actually deobf, then we can find a mapping for it and get the deobf name
ClassMapping classMapping = this.mappings.getClassByObf(className);
if (classMapping != null && classMapping.getDeobfName() != null) {
deobfClassName = classMapping.getDeobfName();
}
// set the desc loader
TranslatingTypeLoader loader = createTypeLoader();
this.settings.setTypeLoader(loader);
// see if procyon can find the desc
TypeReference type = new MetadataSystem(loader).lookupType(deobfClassName);
if (type == null) {
throw new Error(String.format("Unable to find desc: %s (deobf: %s)\nTried class names: %s",
className, deobfClassName, loader.getClassNamesToTry(deobfClassName)
));
}
TypeDefinition resolvedType = type.resolve();
// decompile it!
DecompilerContext context = new DecompilerContext();
context.setCurrentType(resolvedType);
context.setSettings(this.settings);
AstBuilder builder = new AstBuilder(context);
builder.addType(resolvedType);
builder.runTransformations(null);
return builder.getCompilationUnit();
}
public SourceIndex getSourceIndex(CompilationUnit sourceTree, String source) {
return getSourceIndex(sourceTree, source, null);
}
public SourceIndex getSourceIndex(CompilationUnit sourceTree, String source, Boolean ignoreBadTokens) {
// build the source index
SourceIndex index;
if (ignoreBadTokens != null) {
index = new SourceIndex(source, ignoreBadTokens);
} else {
index = new SourceIndex(source);
}
sourceTree.acceptVisitor(new SourceIndexVisitor(entryPool), index);
// DEBUG
// sourceTree.acceptVisitor( new TreeDumpVisitor( new File( "tree.txt" ) ), null );
// resolve all the classes in the source references
for (Token token : index.referenceTokens()) {
EntryReference<Entry, Entry> deobfReference = index.getDeobfReference(token);
// get the obfuscated entry
Entry obfEntry = obfuscateEntry(deobfReference.entry);
// try to resolve the class
ClassEntry resolvedObfClassEntry = this.jarIndex.getTranslationIndex().resolveEntryOwner(obfEntry);
if (resolvedObfClassEntry != null && !resolvedObfClassEntry.equals(obfEntry.getOwnerClassEntry())) {
// change the class of the entry
obfEntry = obfEntry.updateOwnership(resolvedObfClassEntry);
// save the new deobfuscated reference
deobfReference.entry = deobfuscateEntry(obfEntry);
index.replaceDeobfReference(token, deobfReference);
}
// DEBUG
// System.out.println( token + " -> " + reference + " -> " + index.getReferenceToken( reference ) );
}
return index;
}
public String getSource(CompilationUnit sourceTree) {
// render the AST into source
StringWriter buf = new StringWriter();
sourceTree.acceptVisitor(new InsertParenthesesVisitor(), null);
sourceTree.acceptVisitor(new JavaOutputVisitor(new PlainTextOutput(buf), this.settings), null);
return buf.toString();
}
public void writeSources(File dirOut, ProgressListener progress) {
// get the classes to decompile
Set<ClassEntry> classEntries = Sets.newHashSet();
for (ClassEntry obfClassEntry : this.jarIndex.getObfClassEntries()) {
// skip inner classes
if (obfClassEntry.isInnerClass()) {
continue;
}
classEntries.add(obfClassEntry);
}
if (progress != null) {
progress.init(classEntries.size(), "Decompiling classes...");
}
// DEOBFUSCATE ALL THE THINGS!! @_@
Stopwatch stopwatch = Stopwatch.createStarted();
AtomicInteger count = new AtomicInteger();
classEntries.parallelStream().forEach(obfClassEntry -> {
ClassEntry deobfClassEntry = deobfuscateEntry(new ClassEntry(obfClassEntry));
if (progress != null) {
progress.onProgress(count.getAndIncrement(), deobfClassEntry.toString());
}
try {
// get the source
CompilationUnit sourceTree = getSourceTree(obfClassEntry.getName());
// write the file
File file = new File(dirOut, deobfClassEntry.getName().replace('.', '/') + ".java");
file.getParentFile().mkdirs();
try (Writer writer = new BufferedWriter(new FileWriter(file))) {
sourceTree.acceptVisitor(new InsertParenthesesVisitor(), null);
sourceTree.acceptVisitor(new JavaOutputVisitor(new PlainTextOutput(writer), settings), null);
}
} catch (Throwable t) {
// don't crash the whole world here, just log the error and keep going
// TODO: set up logback via log4j
System.err.println("Unable to deobfuscate class " + deobfClassEntry + " (" + obfClassEntry + ")");
t.printStackTrace(System.err);
}
});
stopwatch.stop();
System.out.println("Done in : " + stopwatch.toString());
if (progress != null) {
progress.onProgress(count.get(), "Done:");
}
}
private void addAllPotentialAncestors(Set<ClassEntry> classEntries, ClassEntry classObfEntry) {
for (ClassEntry interfaceEntry : jarIndex.getTranslationIndex().getInterfaces(classObfEntry)) {
if (classEntries.add(interfaceEntry)) {
addAllPotentialAncestors(classEntries, interfaceEntry);
}
}
ClassEntry superClassEntry = jarIndex.getTranslationIndex().getSuperclass(classObfEntry);
if (superClassEntry != null && classEntries.add(superClassEntry)) {
addAllPotentialAncestors(classEntries, superClassEntry);
}
}
private boolean isMethodProvider(ClassEntry classObfEntry, MethodEntry methodEntry) {
Set<ClassEntry> classEntries = new HashSet<>();
addAllPotentialAncestors(classEntries, classObfEntry);
for (ClassEntry parentEntry : classEntries) {
MethodEntry ancestorMethodEntry = entryPool.getMethod(parentEntry, methodEntry.getName(), methodEntry.getDesc());
if (jarIndex.containsObfMethod(ancestorMethodEntry)) {
return false;
}
}
return true;
}
public void rebuildMethodNames(ProgressListener progress) {
int i = 0;
Map<ClassMapping, Map<Entry, String>> renameClassMap = new HashMap<>();
progress.init(getMappings().classes().size() * 3, "Rebuilding method names");
for (ClassMapping classMapping : Lists.newArrayList(getMappings().classes())) {
progress.onProgress(i++, classMapping.getDeobfName());
rebuildMethodNames(classMapping, renameClassMap);
}
for (Map.Entry<ClassMapping, Map<Entry, String>> renameClassMapEntry : renameClassMap.entrySet()) {
progress.onProgress(i++, renameClassMapEntry.getKey().getDeobfName());
for (Map.Entry<Entry, String> entry : renameClassMapEntry.getValue().entrySet()) {
Entry obfEntry = entry.getKey();
removeMapping(obfEntry);
}
}
for (Map.Entry<ClassMapping, Map<Entry, String>> renameClassMapEntry : renameClassMap.entrySet()) {
progress.onProgress(i++, renameClassMapEntry.getKey().getDeobfName());
for (Map.Entry<Entry, String> entry : renameClassMapEntry.getValue().entrySet()) {
Entry obfEntry = entry.getKey();
String name = entry.getValue();
try {
rename(obfEntry, name);
} catch (IllegalNameException exception) {
System.out.println("WARNING: " + exception.getMessage());
}
}
}
}
private void rebuildMethodNames(ClassMapping classMapping, Map<ClassMapping, Map<Entry, String>> renameClassMap) {
Map<Entry, String> renameEntries = new HashMap<>();
for (MethodMapping methodMapping : Lists.newArrayList(classMapping.methods())) {
ClassEntry classObfEntry = classMapping.getObfEntry();
MethodEntry obfEntry = methodMapping.getObfEntry(classObfEntry);
if (isMethodProvider(classObfEntry, obfEntry)) {
if (hasDeobfuscatedName(obfEntry)
&& !(methodMapping.getDeobfName().equals(methodMapping.getObfName()))) {
renameEntries.put(obfEntry, methodMapping.getDeobfName());
}
ArrayList<LocalVariableMapping> arguments = Lists.newArrayList(methodMapping.arguments());
for (LocalVariableMapping localVariableMapping : arguments) {
Entry argObfEntry = localVariableMapping.getObfEntry(obfEntry);
if (hasDeobfuscatedName(argObfEntry)) {
renameEntries.put(argObfEntry, deobfuscateEntry(argObfEntry).getName());
}
}
}
}
classMapping.markDirty();
renameClassMap.put(classMapping, renameEntries);
for (ClassMapping innerClass : classMapping.innerClasses()) {
rebuildMethodNames(innerClass, renameClassMap);
}
}
public void writeJar(File out, ProgressListener progress) {
transformJar(out, progress, createTypeLoader()::transformInto);
}
public void protectifyJar(File out, ProgressListener progress) {
transformJar(out, progress, (node, writer) -> {
node.accept(new ClassProtectifier(Opcodes.ASM5, writer));
return node.name;
});
}
public void publifyJar(File out, ProgressListener progress) {
transformJar(out, progress, (node, writer) -> {
node.accept(new ClassPublifier(Opcodes.ASM5, writer));
return node.name;
});
}
public void transformJar(File out, ProgressListener progress, ClassTransformer transformer) {
try (JarOutputStream outJar = new JarOutputStream(new FileOutputStream(out))) {
if (progress != null) {
progress.init(parsedJar.getClassCount(), "Transforming classes...");
}
AtomicInteger i = new AtomicInteger();
parsedJar.visit(node -> {
if (progress != null) {
progress.onProgress(i.getAndIncrement(), node.name);
}
try {
ClassWriter writer = new ClassWriter(0);
String transformedName = transformer.transform(node, writer);
outJar.putNextEntry(new JarEntry(transformedName.replace('.', '/') + ".class"));
outJar.write(writer.toByteArray());
outJar.closeEntry();
} catch (Throwable t) {
throw new Error("Unable to transform class " + node.name, t);
}
});
if (progress != null) {
progress.onProgress(i.get(), "Done!");
}
} catch (IOException ex) {
throw new Error("Unable to write to Jar file!");
}
}
public <T extends Entry> T obfuscateEntry(T deobfEntry) {
if (deobfEntry == null) {
return null;
}
T translatedEntry = getTranslator(TranslationDirection.OBFUSCATING).getTranslatedEntry(deobfEntry);
if (translatedEntry == null) {
return deobfEntry;
}
return translatedEntry;
}
public <T extends Entry> T deobfuscateEntry(T obfEntry) {
if (obfEntry == null) {
return null;
}
T translatedEntry = getTranslator(TranslationDirection.DEOBFUSCATING).getTranslatedEntry(obfEntry);
if (translatedEntry == null) {
return obfEntry;
}
return translatedEntry;
}
public <E extends Entry, C extends Entry> EntryReference<E, C> obfuscateReference(EntryReference<E, C> deobfReference) {
if (deobfReference == null) {
return null;
}
return new EntryReference<>(obfuscateEntry(deobfReference.entry), obfuscateEntry(deobfReference.context), deobfReference);
}
public <E extends Entry, C extends Entry> EntryReference<E, C> deobfuscateReference(EntryReference<E, C> obfReference) {
if (obfReference == null) {
return null;
}
return new EntryReference<>(deobfuscateEntry(obfReference.entry), deobfuscateEntry(obfReference.context), obfReference);
}
public boolean isObfuscatedIdentifier(Entry obfEntry) {
return isObfuscatedIdentifier(obfEntry, false);
}
public boolean isObfuscatedIdentifier(Entry obfEntry, boolean hack) {
if (obfEntry instanceof MethodEntry) {
// HACKHACK: Object methods are not obfuscated identifiers
MethodEntry obfMethodEntry = (MethodEntry) obfEntry;
String name = obfMethodEntry.getName();
String sig = obfMethodEntry.getDesc().toString();
if (name.equals("clone") && sig.equals("()Ljava/lang/Object;")) {
return false;
} else if (name.equals("equals") && sig.equals("(Ljava/lang/Object;)Z")) {
return false;
} else if (name.equals("finalize") && sig.equals("()V")) {
return false;
} else if (name.equals("getClass") && sig.equals("()Ljava/lang/Class;")) {
return false;
} else if (name.equals("hashCode") && sig.equals("()I")) {
return false;
} else if (name.equals("notify") && sig.equals("()V")) {
return false;
} else if (name.equals("notifyAll") && sig.equals("()V")) {
return false;
} else if (name.equals("toString") && sig.equals("()Ljava/lang/String;")) {
return false;
} else if (name.equals("wait") && sig.equals("()V")) {
return false;
} else if (name.equals("wait") && sig.equals("(J)V")) {
return false;
} else if (name.equals("wait") && sig.equals("(JI)V")) {
return false;
}
// FIXME: HACK EVEN MORE HACK!
if (hack && this.jarIndex.containsObfEntry(obfEntry.getOwnerClassEntry()))
return true;
}
return this.jarIndex.containsObfEntry(obfEntry);
}
public boolean isRenameable(EntryReference<Entry, Entry> obfReference, boolean activeHack) {
return obfReference.isNamed() && isObfuscatedIdentifier(obfReference.getNameableEntry(), activeHack);
}
public boolean isRenameable(EntryReference<Entry, Entry> obfReference) {
return isRenameable(obfReference, false);
}
public boolean hasDeobfuscatedName(Entry obfEntry) {
Translator translator = getTranslator(TranslationDirection.DEOBFUSCATING);
if (obfEntry instanceof ClassEntry) {
ClassEntry obfClass = (ClassEntry) obfEntry;
List<ClassMapping> mappingChain = this.mappings.getClassMappingChain(obfClass);
ClassMapping classMapping = mappingChain.get(mappingChain.size() - 1);
return classMapping != null && classMapping.getDeobfName() != null;
} else if (obfEntry instanceof FieldEntry) {
return translator.hasFieldMapping((FieldEntry) obfEntry);
} else if (obfEntry instanceof MethodEntry) {
MethodEntry methodEntry = (MethodEntry) obfEntry;
if (methodEntry.isConstructor()) {
return false;
}
return translator.hasMethodMapping(methodEntry);
} else if (obfEntry instanceof LocalVariableEntry) {
return translator.hasLocalVariableMapping((LocalVariableEntry) obfEntry);
} else {
throw new Error("Unknown entry desc: " + obfEntry.getClass().getName());
}
}
public void rename(Entry obfEntry, String newName) {
rename(obfEntry, newName, true);
}
// NOTE: these methods are a bit messy... oh well
public void rename(Entry obfEntry, String newName, boolean clearCache) {
if (obfEntry instanceof ClassEntry) {
this.renamer.setClassName((ClassEntry) obfEntry, newName);
} else if (obfEntry instanceof FieldEntry) {
this.renamer.setFieldName((FieldEntry) obfEntry, newName);
} else if (obfEntry instanceof MethodEntry) {
if (((MethodEntry) obfEntry).isConstructor()) {
throw new IllegalArgumentException("Cannot rename constructors");
}
this.renamer.setMethodTreeName((MethodEntry) obfEntry, newName);
} else if (obfEntry instanceof LocalVariableEntry) {
this.renamer.setLocalVariableTreeName((LocalVariableEntry) obfEntry, newName);
} else {
throw new Error("Unknown entry desc: " + obfEntry.getClass().getName());
}
// clear caches
if (clearCache)
this.translatorCache.clear();
}
public void removeMapping(Entry obfEntry) {
if (obfEntry instanceof ClassEntry) {
this.renamer.removeClassMapping((ClassEntry) obfEntry);
} else if (obfEntry instanceof FieldEntry) {
this.renamer.removeFieldMapping((FieldEntry) obfEntry);
} else if (obfEntry instanceof MethodEntry) {
if (((MethodEntry) obfEntry).isConstructor()) {
throw new IllegalArgumentException("Cannot rename constructors");
}
this.renamer.removeMethodTreeMapping((MethodEntry) obfEntry);
} else if (obfEntry instanceof LocalVariableEntry) {
this.renamer.removeLocalVariableMapping((LocalVariableEntry) obfEntry);
} else {
throw new Error("Unknown entry desc: " + obfEntry);
}
// clear caches
this.translatorCache.clear();
}
public void markAsDeobfuscated(Entry obfEntry) {
if (obfEntry instanceof ClassEntry) {
this.renamer.markClassAsDeobfuscated((ClassEntry) obfEntry);
} else if (obfEntry instanceof FieldEntry) {
this.renamer.markFieldAsDeobfuscated((FieldEntry) obfEntry);
} else if (obfEntry instanceof MethodEntry) {
MethodEntry methodEntry = (MethodEntry) obfEntry;
if (methodEntry.isConstructor()) {
throw new IllegalArgumentException("Cannot rename constructors");
}
this.renamer.markMethodTreeAsDeobfuscated(methodEntry);
} else if (obfEntry instanceof LocalVariableEntry) {
this.renamer.markArgumentAsDeobfuscated((LocalVariableEntry) obfEntry);
} else {
throw new Error("Unknown entry desc: " + obfEntry);
}
// clear caches
this.translatorCache.clear();
}
public void changeModifier(Entry entry, Mappings.EntryModifier modifierEntry) {
Entry obfEntry = obfuscateEntry(entry);
if (obfEntry instanceof ClassEntry)
this.renamer.setClassModifier((ClassEntry) obfEntry, modifierEntry);
else if (obfEntry instanceof FieldEntry)
this.renamer.setFieldModifier((FieldEntry) obfEntry, modifierEntry);
else if (obfEntry instanceof MethodEntry)
this.renamer.setMethodModifier((MethodEntry) obfEntry, modifierEntry);
else
throw new Error("Unknown entry desc: " + obfEntry);
}
public Mappings.EntryModifier getModifier(Entry obfEntry) {
Entry entry = obfuscateEntry(obfEntry);
if (entry != null)
obfEntry = entry;
if (obfEntry instanceof ClassEntry)
return this.renamer.getClassModifier((ClassEntry) obfEntry);
else if (obfEntry instanceof FieldEntry)
return this.renamer.getFieldModifier((FieldEntry) obfEntry);
else if (obfEntry instanceof MethodEntry)
return this.renamer.getMethodModfifier((MethodEntry) obfEntry);
else
throw new Error("Unknown entry desc: " + obfEntry);
}
public interface ProgressListener {
void init(int totalWork, String title);
void onProgress(int numDone, String message);
}
public interface ClassTransformer {
String transform(ClassNode node, ClassWriter writer);
}
}
|