From 6c4440ac1133bfaa7871d1049d174528a289ef30 Mon Sep 17 00:00:00 2001 From: hg Date: Sun, 17 Aug 2014 10:56:17 -0400 Subject: added support for automatic reconstruction of inner and anonymous classes also added class to restore bridge method flags taken out by the obfuscator --- src/cuchaz/enigma/Deobfuscator.java | 51 ++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 24 deletions(-) (limited to 'src/cuchaz/enigma/Deobfuscator.java') 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 // config the decompiler m_settings = DecompilerSettings.javaDefaults(); - m_settings.setShowSyntheticMembers( true ); // init mappings setMappings( new Mappings() ); @@ -109,9 +108,15 @@ public class Deobfuscator { for( String obfClassName : m_jarIndex.getObfClassNames() ) { + // skip inner classes + if( m_jarIndex.getOuterClass( obfClassName ) != null ) + { + continue; + } + // separate the classes ClassMapping classMapping = m_mappings.getClassByObf( obfClassName ); - if( classMapping != null ) + if( classMapping != null && !classMapping.getObfName().equals( classMapping.getDeobfName() ) ) { deobfClasses.add( classMapping.getDeobfName() ); } @@ -151,6 +156,7 @@ public class Deobfuscator // render the AST into source StringWriter buf = new StringWriter(); root.acceptVisitor( new InsertParenthesesVisitor(), null ); + //root.acceptVisitor( new TreeDumpVisitor( new File( "tree.txt" ) ), null ); root.acceptVisitor( new JavaOutputVisitor( new PlainTextOutput( buf ), m_settings ), null ); // build the source index @@ -281,33 +287,30 @@ public class Deobfuscator } } - public boolean entryIsObfuscatedIdenfitier( Entry obfEntry ) + public boolean isObfuscatedIdentifier( Entry obfEntry ) { if( obfEntry instanceof ClassEntry ) { - // obf classes must be in the list - return m_jarIndex.getObfClassNames().contains( obfEntry.getName() ); - } - else if( obfEntry instanceof FieldEntry ) - { - return m_jarIndex.getObfClassNames().contains( obfEntry.getClassName() ); - } - else if( obfEntry instanceof MethodEntry ) - { - return m_jarIndex.getObfClassNames().contains( obfEntry.getClassName() ); - } - else if( obfEntry instanceof ConstructorEntry ) - { - return m_jarIndex.getObfClassNames().contains( obfEntry.getClassName() ); + if( obfEntry.getName().indexOf( '$' ) >= 0 ) + { + String[] parts = obfEntry.getName().split( "\\$" ); + assert( parts.length == 2 ); // not supporting recursively-nested classes + String outerClassName = parts[0]; + String innerClassName = parts[1]; + + // both classes must be in the list + return m_jarIndex.getObfClassNames().contains( outerClassName ) + && m_jarIndex.getObfClassNames().contains( innerClassName ); + } + else + { + // class must be in the list + return m_jarIndex.getObfClassNames().contains( obfEntry.getName() ); + } } - else if( obfEntry instanceof ArgumentEntry ) + else { - // arguments only appear in method declarations - // since we only show declarations for obf classes, these are always obfuscated - return true; + return isObfuscatedIdentifier( obfEntry.getClassEntry() ); } - - // assume everything else is not obfuscated - return false; } } -- cgit v1.2.3