summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cuchaz/enigma/Deobfuscator.java13
-rw-r--r--src/cuchaz/enigma/TranslatingTypeLoader.java5
-rw-r--r--src/cuchaz/enigma/analysis/SourceIndexVisitor.java18
-rw-r--r--src/cuchaz/enigma/gui/GuiController.java9
4 files changed, 35 insertions, 10 deletions
diff --git a/src/cuchaz/enigma/Deobfuscator.java b/src/cuchaz/enigma/Deobfuscator.java
index 323aa2e..293e1c2 100644
--- a/src/cuchaz/enigma/Deobfuscator.java
+++ b/src/cuchaz/enigma/Deobfuscator.java
@@ -29,6 +29,7 @@ import com.strobel.decompiler.languages.java.ast.InsertParenthesesVisitor;
29import cuchaz.enigma.analysis.JarIndex; 29import cuchaz.enigma.analysis.JarIndex;
30import cuchaz.enigma.analysis.SourceIndex; 30import cuchaz.enigma.analysis.SourceIndex;
31import cuchaz.enigma.analysis.SourceIndexVisitor; 31import cuchaz.enigma.analysis.SourceIndexVisitor;
32import cuchaz.enigma.analysis.TreeDumpVisitor;
32import cuchaz.enigma.mapping.ArgumentEntry; 33import cuchaz.enigma.mapping.ArgumentEntry;
33import cuchaz.enigma.mapping.ClassEntry; 34import cuchaz.enigma.mapping.ClassEntry;
34import cuchaz.enigma.mapping.ClassMapping; 35import cuchaz.enigma.mapping.ClassMapping;
@@ -49,6 +50,7 @@ public class Deobfuscator
49 private JarIndex m_jarIndex; 50 private JarIndex m_jarIndex;
50 private Mappings m_mappings; 51 private Mappings m_mappings;
51 private Renamer m_renamer; 52 private Renamer m_renamer;
53 private TranslatingTypeLoader m_typeLoader;
52 54
53 public Deobfuscator( File file ) 55 public Deobfuscator( File file )
54 throws IOException 56 throws IOException
@@ -93,12 +95,13 @@ public class Deobfuscator
93 m_renamer = new Renamer( m_jarIndex, m_mappings ); 95 m_renamer = new Renamer( m_jarIndex, m_mappings );
94 96
95 // update decompiler options 97 // update decompiler options
96 m_settings.setTypeLoader( new TranslatingTypeLoader( 98 m_typeLoader = new TranslatingTypeLoader(
97 m_jar, 99 m_jar,
98 m_jarIndex, 100 m_jarIndex,
99 getTranslator( TranslationDirection.Obfuscating ), 101 getTranslator( TranslationDirection.Obfuscating ),
100 getTranslator( TranslationDirection.Deobfuscating ) 102 getTranslator( TranslationDirection.Deobfuscating )
101 ) ); 103 );
104 m_settings.setTypeLoader( m_typeLoader );
102 } 105 }
103 106
104 public Translator getTranslator( TranslationDirection direction ) 107 public Translator getTranslator( TranslationDirection direction )
@@ -158,7 +161,8 @@ public class Deobfuscator
158 // render the AST into source 161 // render the AST into source
159 StringWriter buf = new StringWriter(); 162 StringWriter buf = new StringWriter();
160 root.acceptVisitor( new InsertParenthesesVisitor(), null ); 163 root.acceptVisitor( new InsertParenthesesVisitor(), null );
161 //root.acceptVisitor( new TreeDumpVisitor( new File( "tree.txt" ) ), null ); 164 // DEBUG
165 root.acceptVisitor( new TreeDumpVisitor( new File( "tree.txt" ) ), null );
162 root.acceptVisitor( new JavaOutputVisitor( new PlainTextOutput( buf ), m_settings ), null ); 166 root.acceptVisitor( new JavaOutputVisitor( new PlainTextOutput( buf ), m_settings ), null );
163 167
164 // build the source index 168 // build the source index
@@ -196,6 +200,9 @@ public class Deobfuscator
196 { 200 {
197 throw new Error( "Unknown entry type: " + obfEntry.getClass().getName() ); 201 throw new Error( "Unknown entry type: " + obfEntry.getClass().getName() );
198 } 202 }
203
204 // clear the type loader cache
205 m_typeLoader.clearCache();
199 } 206 }
200 207
201 public Entry obfuscateEntry( Entry deobfEntry ) 208 public Entry obfuscateEntry( Entry deobfEntry )
diff --git a/src/cuchaz/enigma/TranslatingTypeLoader.java b/src/cuchaz/enigma/TranslatingTypeLoader.java
index ae27f37..cc86364 100644
--- a/src/cuchaz/enigma/TranslatingTypeLoader.java
+++ b/src/cuchaz/enigma/TranslatingTypeLoader.java
@@ -53,6 +53,11 @@ public class TranslatingTypeLoader implements ITypeLoader
53 m_cache = Maps.newHashMap(); 53 m_cache = Maps.newHashMap();
54 } 54 }
55 55
56 public void clearCache( )
57 {
58 m_cache.clear();
59 }
60
56 @Override 61 @Override
57 public boolean tryLoadType( String deobfClassName, Buffer out ) 62 public boolean tryLoadType( String deobfClassName, Buffer out )
58 { 63 {
diff --git a/src/cuchaz/enigma/analysis/SourceIndexVisitor.java b/src/cuchaz/enigma/analysis/SourceIndexVisitor.java
index 6c14ee9..f31eb1a 100644
--- a/src/cuchaz/enigma/analysis/SourceIndexVisitor.java
+++ b/src/cuchaz/enigma/analysis/SourceIndexVisitor.java
@@ -201,6 +201,18 @@ public class SourceIndexVisitor implements IAstVisitor<SourceIndex, Void>
201 return recurse( node, index ); 201 return recurse( node, index );
202 } 202 }
203 203
204 @Override
205 public Void visitEnumValueDeclaration( EnumValueDeclaration node, SourceIndex index )
206 {
207 // treat enum declarations as field declarations
208 FieldDefinition def = node.getUserData( Keys.FIELD_DEFINITION );
209 ClassEntry classEntry = new ClassEntry( def.getDeclaringType().getInternalName() );
210 FieldEntry fieldEntry = new FieldEntry( classEntry, def.getName() );
211 index.addDeclaration( node.getNameToken(), fieldEntry );
212
213 return recurse( node, index );
214 }
215
204 private Void recurse( AstNode node, SourceIndex index ) 216 private Void recurse( AstNode node, SourceIndex index )
205 { 217 {
206 for( final AstNode child : node.getChildren() ) 218 for( final AstNode child : node.getChildren() )
@@ -561,12 +573,6 @@ public class SourceIndexVisitor implements IAstVisitor<SourceIndex, Void>
561 } 573 }
562 574
563 @Override 575 @Override
564 public Void visitEnumValueDeclaration( EnumValueDeclaration node, SourceIndex index )
565 {
566 return recurse( node, index );
567 }
568
569 @Override
570 public Void visitAssertStatement( AssertStatement node, SourceIndex index ) 576 public Void visitAssertStatement( AssertStatement node, SourceIndex index )
571 { 577 {
572 return recurse( node, index ); 578 return recurse( node, index );
diff --git a/src/cuchaz/enigma/gui/GuiController.java b/src/cuchaz/enigma/gui/GuiController.java
index ffeb99a..f305e34 100644
--- a/src/cuchaz/enigma/gui/GuiController.java
+++ b/src/cuchaz/enigma/gui/GuiController.java
@@ -272,7 +272,14 @@ public class GuiController
272 m_gui.setSource( m_index.getSource() ); 272 m_gui.setSource( m_index.getSource() );
273 if( obfEntryToShow != null ) 273 if( obfEntryToShow != null )
274 { 274 {
275 m_gui.showToken( m_index.getDeclarationToken( m_deobfuscator.deobfuscateEntry( obfEntryToShow ) ) ); 275 Entry deobfEntryToShow = m_deobfuscator.deobfuscateEntry( obfEntryToShow );
276 Token token = m_index.getDeclarationToken( deobfEntryToShow );
277 if( token == null )
278 {
279 // TEMP
280 System.out.println( "WARNING: can't find token for " + obfEntryToShow + " -> " + deobfEntryToShow );
281 }
282 m_gui.showToken( token );
276 } 283 }
277 284
278 // set the highlighted tokens 285 // set the highlighted tokens