diff options
| author | 2018-10-25 00:01:49 +0200 | |
|---|---|---|
| committer | 2018-10-25 00:01:49 +0200 | |
| commit | 9274c5c862e6a38b37ff2d11f468a6a98cc47daf (patch) | |
| tree | 0d4cb774e77848112368a12bba42c7be0ed1f8fb /src/main/java/cuchaz/enigma/Deobfuscator.java | |
| parent | Merge pull request #62 from OpenModLoader/asm (diff) | |
| parent | recursively check ClassMapping dirty state (diff) | |
| download | enigma-fork-9274c5c862e6a38b37ff2d11f468a6a98cc47daf.tar.gz enigma-fork-9274c5c862e6a38b37ff2d11f468a6a98cc47daf.tar.xz enigma-fork-9274c5c862e6a38b37ff2d11f468a6a98cc47daf.zip | |
make rebuild method names discard child-only names. imperfect, but eh
Diffstat (limited to 'src/main/java/cuchaz/enigma/Deobfuscator.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/Deobfuscator.java | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/src/main/java/cuchaz/enigma/Deobfuscator.java b/src/main/java/cuchaz/enigma/Deobfuscator.java index 6ea1c40..5980f1f 100644 --- a/src/main/java/cuchaz/enigma/Deobfuscator.java +++ b/src/main/java/cuchaz/enigma/Deobfuscator.java | |||
| @@ -34,6 +34,7 @@ import cuchaz.enigma.mapping.entry.*; | |||
| 34 | import cuchaz.enigma.throwables.IllegalNameException; | 34 | import cuchaz.enigma.throwables.IllegalNameException; |
| 35 | import cuchaz.enigma.utils.Utils; | 35 | import cuchaz.enigma.utils.Utils; |
| 36 | import oml.ast.transformers.ObfuscatedEnumSwitchRewriterTransform; | 36 | import oml.ast.transformers.ObfuscatedEnumSwitchRewriterTransform; |
| 37 | import oml.ast.transformers.RemoveObjectCasts; | ||
| 37 | import org.objectweb.asm.ClassWriter; | 38 | import org.objectweb.asm.ClassWriter; |
| 38 | import org.objectweb.asm.Opcodes; | 39 | import org.objectweb.asm.Opcodes; |
| 39 | import org.objectweb.asm.tree.ClassNode; | 40 | import org.objectweb.asm.tree.ClassNode; |
| @@ -324,6 +325,21 @@ public class Deobfuscator { | |||
| 324 | } | 325 | } |
| 325 | } | 326 | } |
| 326 | 327 | ||
| 328 | public boolean isMethodProvider(MethodEntry methodEntry) { | ||
| 329 | Set<ClassEntry> classEntries = new HashSet<>(); | ||
| 330 | addAllPotentialAncestors(classEntries, methodEntry.getOwnerClassEntry()); | ||
| 331 | |||
| 332 | for (ClassEntry parentEntry : classEntries) { | ||
| 333 | MethodEntry ancestorMethodEntry = entryPool.getMethod(parentEntry, methodEntry.getName(), methodEntry.getDesc()); | ||
| 334 | if (jarIndex.containsObfMethod(ancestorMethodEntry)) { | ||
| 335 | return false; | ||
| 336 | } | ||
| 337 | } | ||
| 338 | |||
| 339 | return true; | ||
| 340 | } | ||
| 341 | |||
| 342 | @Deprecated | ||
| 327 | public boolean isMethodProvider(ClassEntry classObfEntry, MethodEntry methodEntry) { | 343 | public boolean isMethodProvider(ClassEntry classObfEntry, MethodEntry methodEntry) { |
| 328 | Set<ClassEntry> classEntries = new HashSet<>(); | 344 | Set<ClassEntry> classEntries = new HashSet<>(); |
| 329 | addAllPotentialAncestors(classEntries, classObfEntry); | 345 | addAllPotentialAncestors(classEntries, classObfEntry); |
| @@ -366,10 +382,12 @@ public class Deobfuscator { | |||
| 366 | Entry obfEntry = entry.getKey(); | 382 | Entry obfEntry = entry.getKey(); |
| 367 | String name = entry.getValue(); | 383 | String name = entry.getValue(); |
| 368 | 384 | ||
| 369 | try { | 385 | if (name != null) { |
| 370 | rename(obfEntry, name); | 386 | try { |
| 371 | } catch (IllegalNameException exception) { | 387 | rename(obfEntry, name); |
| 372 | System.out.println("WARNING: " + exception.getMessage()); | 388 | } catch (IllegalNameException exception) { |
| 389 | System.out.println("WARNING: " + exception.getMessage()); | ||
| 390 | } | ||
| 373 | } | 391 | } |
| 374 | } | 392 | } |
| 375 | } | 393 | } |
| @@ -381,15 +399,15 @@ public class Deobfuscator { | |||
| 381 | for (MethodMapping methodMapping : Lists.newArrayList(classMapping.methods())) { | 399 | for (MethodMapping methodMapping : Lists.newArrayList(classMapping.methods())) { |
| 382 | ClassEntry classObfEntry = classMapping.getObfEntry(); | 400 | ClassEntry classObfEntry = classMapping.getObfEntry(); |
| 383 | MethodEntry obfEntry = methodMapping.getObfEntry(classObfEntry); | 401 | MethodEntry obfEntry = methodMapping.getObfEntry(classObfEntry); |
| 402 | boolean isProvider = isMethodProvider(obfEntry); | ||
| 384 | 403 | ||
| 385 | if (isMethodProvider(classObfEntry, obfEntry)) { | 404 | if (hasDeobfuscatedName(obfEntry) |
| 386 | if (hasDeobfuscatedName(obfEntry) | 405 | && !(methodMapping.getDeobfName().equals(methodMapping.getObfName()))) { |
| 387 | && !(methodMapping.getDeobfName().equals(methodMapping.getObfName()))) { | 406 | renameEntries.put(obfEntry, isProvider ? methodMapping.getDeobfName() : null); |
| 388 | renameEntries.put(obfEntry, methodMapping.getDeobfName()); | 407 | } |
| 389 | } | ||
| 390 | 408 | ||
| 391 | ArrayList<LocalVariableMapping> arguments = Lists.newArrayList(methodMapping.arguments()); | 409 | if (isProvider) { |
| 392 | for (LocalVariableMapping localVariableMapping : arguments) { | 410 | for (LocalVariableMapping localVariableMapping : methodMapping.arguments()) { |
| 393 | Entry argObfEntry = localVariableMapping.getObfEntry(obfEntry); | 411 | Entry argObfEntry = localVariableMapping.getObfEntry(obfEntry); |
| 394 | if (hasDeobfuscatedName(argObfEntry)) { | 412 | if (hasDeobfuscatedName(argObfEntry)) { |
| 395 | renameEntries.put(argObfEntry, deobfuscateEntry(argObfEntry).getName()); | 413 | renameEntries.put(argObfEntry, deobfuscateEntry(argObfEntry).getName()); |
| @@ -661,7 +679,8 @@ public class Deobfuscator { | |||
| 661 | 679 | ||
| 662 | public static void runCustomTransforms(AstBuilder builder, DecompilerContext context){ | 680 | public static void runCustomTransforms(AstBuilder builder, DecompilerContext context){ |
| 663 | List<IAstTransform> transformers = Arrays.asList( | 681 | List<IAstTransform> transformers = Arrays.asList( |
| 664 | new ObfuscatedEnumSwitchRewriterTransform(context) | 682 | new ObfuscatedEnumSwitchRewriterTransform(context), |
| 683 | new RemoveObjectCasts(context) | ||
| 665 | ); | 684 | ); |
| 666 | for (IAstTransform transform : transformers){ | 685 | for (IAstTransform transform : transformers){ |
| 667 | transform.run(builder.getCompilationUnit()); | 686 | transform.run(builder.getCompilationUnit()); |