summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/Deobfuscator.java
diff options
context:
space:
mode:
authorGravatar hg2014-08-17 10:56:17 -0400
committerGravatar hg2014-08-17 10:56:17 -0400
commit6c4440ac1133bfaa7871d1049d174528a289ef30 (patch)
treefe1142b285c5e43dbd3afe8dd3eb0189f027c6a6 /src/cuchaz/enigma/Deobfuscator.java
parenttrying to get inner/anonymous classes working... I have a working heuristic i... (diff)
downloadenigma-fork-6c4440ac1133bfaa7871d1049d174528a289ef30.tar.gz
enigma-fork-6c4440ac1133bfaa7871d1049d174528a289ef30.tar.xz
enigma-fork-6c4440ac1133bfaa7871d1049d174528a289ef30.zip
added support for automatic reconstruction of inner and anonymous classes
also added class to restore bridge method flags taken out by the obfuscator
Diffstat (limited to 'src/cuchaz/enigma/Deobfuscator.java')
-rw-r--r--src/cuchaz/enigma/Deobfuscator.java51
1 files changed, 27 insertions, 24 deletions
diff --git a/src/cuchaz/enigma/Deobfuscator.java b/src/cuchaz/enigma/Deobfuscator.java
index 127a0d9..9a0ec13 100644
--- a/src/cuchaz/enigma/Deobfuscator.java
+++ b/src/cuchaz/enigma/Deobfuscator.java
@@ -62,7 +62,6 @@ public class Deobfuscator
62 62
63 // config the decompiler 63 // config the decompiler
64 m_settings = DecompilerSettings.javaDefaults(); 64 m_settings = DecompilerSettings.javaDefaults();
65 m_settings.setShowSyntheticMembers( true );
66 65
67 // init mappings 66 // init mappings
68 setMappings( new Mappings() ); 67 setMappings( new Mappings() );
@@ -109,9 +108,15 @@ public class Deobfuscator
109 { 108 {
110 for( String obfClassName : m_jarIndex.getObfClassNames() ) 109 for( String obfClassName : m_jarIndex.getObfClassNames() )
111 { 110 {
111 // skip inner classes
112 if( m_jarIndex.getOuterClass( obfClassName ) != null )
113 {
114 continue;
115 }
116
112 // separate the classes 117 // separate the classes
113 ClassMapping classMapping = m_mappings.getClassByObf( obfClassName ); 118 ClassMapping classMapping = m_mappings.getClassByObf( obfClassName );
114 if( classMapping != null ) 119 if( classMapping != null && !classMapping.getObfName().equals( classMapping.getDeobfName() ) )
115 { 120 {
116 deobfClasses.add( classMapping.getDeobfName() ); 121 deobfClasses.add( classMapping.getDeobfName() );
117 } 122 }
@@ -151,6 +156,7 @@ public class Deobfuscator
151 // render the AST into source 156 // render the AST into source
152 StringWriter buf = new StringWriter(); 157 StringWriter buf = new StringWriter();
153 root.acceptVisitor( new InsertParenthesesVisitor(), null ); 158 root.acceptVisitor( new InsertParenthesesVisitor(), null );
159 //root.acceptVisitor( new TreeDumpVisitor( new File( "tree.txt" ) ), null );
154 root.acceptVisitor( new JavaOutputVisitor( new PlainTextOutput( buf ), m_settings ), null ); 160 root.acceptVisitor( new JavaOutputVisitor( new PlainTextOutput( buf ), m_settings ), null );
155 161
156 // build the source index 162 // build the source index
@@ -281,33 +287,30 @@ public class Deobfuscator
281 } 287 }
282 } 288 }
283 289
284 public boolean entryIsObfuscatedIdenfitier( Entry obfEntry ) 290 public boolean isObfuscatedIdentifier( Entry obfEntry )
285 { 291 {
286 if( obfEntry instanceof ClassEntry ) 292 if( obfEntry instanceof ClassEntry )
287 { 293 {
288 // obf classes must be in the list 294 if( obfEntry.getName().indexOf( '$' ) >= 0 )
289 return m_jarIndex.getObfClassNames().contains( obfEntry.getName() ); 295 {
290 } 296 String[] parts = obfEntry.getName().split( "\\$" );
291 else if( obfEntry instanceof FieldEntry ) 297 assert( parts.length == 2 ); // not supporting recursively-nested classes
292 { 298 String outerClassName = parts[0];
293 return m_jarIndex.getObfClassNames().contains( obfEntry.getClassName() ); 299 String innerClassName = parts[1];
294 } 300
295 else if( obfEntry instanceof MethodEntry ) 301 // both classes must be in the list
296 { 302 return m_jarIndex.getObfClassNames().contains( outerClassName )
297 return m_jarIndex.getObfClassNames().contains( obfEntry.getClassName() ); 303 && m_jarIndex.getObfClassNames().contains( innerClassName );
298 } 304 }
299 else if( obfEntry instanceof ConstructorEntry ) 305 else
300 { 306 {
301 return m_jarIndex.getObfClassNames().contains( obfEntry.getClassName() ); 307 // class must be in the list
308 return m_jarIndex.getObfClassNames().contains( obfEntry.getName() );
309 }
302 } 310 }
303 else if( obfEntry instanceof ArgumentEntry ) 311 else
304 { 312 {
305 // arguments only appear in method declarations 313 return isObfuscatedIdentifier( obfEntry.getClassEntry() );
306 // since we only show declarations for obf classes, these are always obfuscated
307 return true;
308 } 314 }
309
310 // assume everything else is not obfuscated
311 return false;
312 } 315 }
313} 316}