diff options
Diffstat (limited to 'src/cuchaz/enigma/Deobfuscator.java')
| -rw-r--r-- | src/cuchaz/enigma/Deobfuscator.java | 67 |
1 files changed, 61 insertions, 6 deletions
diff --git a/src/cuchaz/enigma/Deobfuscator.java b/src/cuchaz/enigma/Deobfuscator.java index ff83d21..9235cf7 100644 --- a/src/cuchaz/enigma/Deobfuscator.java +++ b/src/cuchaz/enigma/Deobfuscator.java | |||
| @@ -12,14 +12,18 @@ | |||
| 12 | package cuchaz.enigma; | 12 | package cuchaz.enigma; |
| 13 | 13 | ||
| 14 | import java.io.File; | 14 | import java.io.File; |
| 15 | import java.io.FileOutputStream; | ||
| 15 | import java.io.FileWriter; | 16 | import java.io.FileWriter; |
| 16 | import java.io.IOException; | 17 | import java.io.IOException; |
| 17 | import java.io.StringWriter; | 18 | import java.io.StringWriter; |
| 18 | import java.util.List; | 19 | import java.util.List; |
| 19 | import java.util.Map; | 20 | import java.util.Map; |
| 20 | import java.util.Set; | 21 | import java.util.Set; |
| 22 | import java.util.jar.JarEntry; | ||
| 21 | import java.util.jar.JarFile; | 23 | import java.util.jar.JarFile; |
| 24 | import java.util.jar.JarOutputStream; | ||
| 22 | 25 | ||
| 26 | import javassist.CtClass; | ||
| 23 | import javassist.bytecode.Descriptor; | 27 | import javassist.bytecode.Descriptor; |
| 24 | 28 | ||
| 25 | import com.google.common.collect.Lists; | 29 | import com.google.common.collect.Lists; |
| @@ -36,11 +40,11 @@ import com.strobel.decompiler.languages.java.ast.CompilationUnit; | |||
| 36 | import com.strobel.decompiler.languages.java.ast.InsertParenthesesVisitor; | 40 | import com.strobel.decompiler.languages.java.ast.InsertParenthesesVisitor; |
| 37 | 41 | ||
| 38 | import cuchaz.enigma.analysis.EntryReference; | 42 | import cuchaz.enigma.analysis.EntryReference; |
| 43 | import cuchaz.enigma.analysis.JarClassIterator; | ||
| 39 | import cuchaz.enigma.analysis.JarIndex; | 44 | import cuchaz.enigma.analysis.JarIndex; |
| 40 | import cuchaz.enigma.analysis.SourceIndex; | 45 | import cuchaz.enigma.analysis.SourceIndex; |
| 41 | import cuchaz.enigma.analysis.SourceIndexVisitor; | 46 | import cuchaz.enigma.analysis.SourceIndexVisitor; |
| 42 | import cuchaz.enigma.analysis.Token; | 47 | import cuchaz.enigma.analysis.Token; |
| 43 | import cuchaz.enigma.analysis.TreeDumpVisitor; | ||
| 44 | import cuchaz.enigma.mapping.ArgumentEntry; | 48 | import cuchaz.enigma.mapping.ArgumentEntry; |
| 45 | import cuchaz.enigma.mapping.BehaviorEntry; | 49 | import cuchaz.enigma.mapping.BehaviorEntry; |
| 46 | import cuchaz.enigma.mapping.BehaviorEntryFactory; | 50 | import cuchaz.enigma.mapping.BehaviorEntryFactory; |
| @@ -61,7 +65,7 @@ public class Deobfuscator | |||
| 61 | { | 65 | { |
| 62 | public interface ProgressListener | 66 | public interface ProgressListener |
| 63 | { | 67 | { |
| 64 | void init( int totalWork ); | 68 | void init( int totalWork, String title ); |
| 65 | void onProgress( int numDone, String message ); | 69 | void onProgress( int numDone, String message ); |
| 66 | } | 70 | } |
| 67 | 71 | ||
| @@ -393,7 +397,7 @@ public class Deobfuscator | |||
| 393 | 397 | ||
| 394 | if( progress != null ) | 398 | if( progress != null ) |
| 395 | { | 399 | { |
| 396 | progress.init( classEntries.size() ); | 400 | progress.init( classEntries.size(), "Decompiling classes..." ); |
| 397 | } | 401 | } |
| 398 | 402 | ||
| 399 | // DEOBFUSCATE ALL THE THINGS!! @_@ | 403 | // DEOBFUSCATE ALL THE THINGS!! @_@ |
| @@ -424,9 +428,60 @@ public class Deobfuscator | |||
| 424 | throw new Error( "Unable to deobfuscate class " + deobfClassEntry.toString() + " (" + obfClassEntry.toString() + ")", t ); | 428 | throw new Error( "Unable to deobfuscate class " + deobfClassEntry.toString() + " (" + obfClassEntry.toString() + ")", t ); |
| 425 | } | 429 | } |
| 426 | } | 430 | } |
| 427 | 431 | if( progress != null ) | |
| 428 | // done! | 432 | { |
| 429 | progress.onProgress( classEntries.size(), "Done!" ); | 433 | progress.onProgress( i, "Done!" ); |
| 434 | } | ||
| 435 | } | ||
| 436 | |||
| 437 | public void writeJar( File out, ProgressListener progress ) | ||
| 438 | { | ||
| 439 | try( JarOutputStream outJar = new JarOutputStream( new FileOutputStream( out ) ) ) | ||
| 440 | { | ||
| 441 | if( progress != null ) | ||
| 442 | { | ||
| 443 | progress.init( JarClassIterator.getClassEntries( m_jar ).size(), "Translating classes..." ); | ||
| 444 | } | ||
| 445 | |||
| 446 | // prep the loader | ||
| 447 | TranslatingTypeLoader loader = new TranslatingTypeLoader( | ||
| 448 | m_jar, | ||
| 449 | m_jarIndex, | ||
| 450 | getTranslator( TranslationDirection.Obfuscating ), | ||
| 451 | getTranslator( TranslationDirection.Deobfuscating ) | ||
| 452 | ); | ||
| 453 | |||
| 454 | int i = 0; | ||
| 455 | for( CtClass c : JarClassIterator.classes( m_jar ) ) | ||
| 456 | { | ||
| 457 | if( progress != null ) | ||
| 458 | { | ||
| 459 | progress.onProgress( i++, c.getName() ); | ||
| 460 | } | ||
| 461 | |||
| 462 | try | ||
| 463 | { | ||
| 464 | c = loader.transformClass( c ); | ||
| 465 | outJar.putNextEntry( new JarEntry( c.getName().replace( '.', '/' ) + ".class" ) ); | ||
| 466 | outJar.write( c.toBytecode() ); | ||
| 467 | outJar.closeEntry(); | ||
| 468 | } | ||
| 469 | catch( Throwable t ) | ||
| 470 | { | ||
| 471 | throw new Error( "Unable to deobfuscate class " + c.getName(), t ); | ||
| 472 | } | ||
| 473 | } | ||
| 474 | if( progress != null ) | ||
| 475 | { | ||
| 476 | progress.onProgress( i, "Done!" ); | ||
| 477 | } | ||
| 478 | |||
| 479 | outJar.close(); | ||
| 480 | } | ||
| 481 | catch( IOException ex ) | ||
| 482 | { | ||
| 483 | throw new Error( "Unable to write to Jar file!" ); | ||
| 484 | } | ||
| 430 | } | 485 | } |
| 431 | 486 | ||
| 432 | public <T extends Entry> T obfuscateEntry( T deobfEntry ) | 487 | public <T extends Entry> T obfuscateEntry( T deobfEntry ) |