diff options
Diffstat (limited to 'src/cuchaz/enigma/Deobfuscator.java')
| -rw-r--r-- | src/cuchaz/enigma/Deobfuscator.java | 60 |
1 files changed, 15 insertions, 45 deletions
diff --git a/src/cuchaz/enigma/Deobfuscator.java b/src/cuchaz/enigma/Deobfuscator.java index 7be5706..619eebf 100644 --- a/src/cuchaz/enigma/Deobfuscator.java +++ b/src/cuchaz/enigma/Deobfuscator.java | |||
| @@ -15,9 +15,6 @@ import java.io.FileInputStream; | |||
| 15 | import java.io.IOException; | 15 | import java.io.IOException; |
| 16 | import java.io.InputStream; | 16 | import java.io.InputStream; |
| 17 | import java.io.StringWriter; | 17 | import java.io.StringWriter; |
| 18 | import java.util.ArrayList; | ||
| 19 | import java.util.Collections; | ||
| 20 | import java.util.Comparator; | ||
| 21 | import java.util.Enumeration; | 18 | import java.util.Enumeration; |
| 22 | import java.util.List; | 19 | import java.util.List; |
| 23 | import java.util.jar.JarEntry; | 20 | import java.util.jar.JarEntry; |
| @@ -30,10 +27,12 @@ import com.strobel.decompiler.PlainTextOutput; | |||
| 30 | import cuchaz.enigma.mapping.Ancestries; | 27 | import cuchaz.enigma.mapping.Ancestries; |
| 31 | import cuchaz.enigma.mapping.ArgumentEntry; | 28 | import cuchaz.enigma.mapping.ArgumentEntry; |
| 32 | import cuchaz.enigma.mapping.ClassEntry; | 29 | import cuchaz.enigma.mapping.ClassEntry; |
| 30 | import cuchaz.enigma.mapping.ClassMapping; | ||
| 33 | import cuchaz.enigma.mapping.Entry; | 31 | import cuchaz.enigma.mapping.Entry; |
| 34 | import cuchaz.enigma.mapping.FieldEntry; | 32 | import cuchaz.enigma.mapping.FieldEntry; |
| 35 | import cuchaz.enigma.mapping.Mappings; | 33 | import cuchaz.enigma.mapping.Mappings; |
| 36 | import cuchaz.enigma.mapping.MethodEntry; | 34 | import cuchaz.enigma.mapping.MethodEntry; |
| 35 | import cuchaz.enigma.mapping.NameValidator; | ||
| 37 | import cuchaz.enigma.mapping.Renamer; | 36 | import cuchaz.enigma.mapping.Renamer; |
| 38 | import cuchaz.enigma.mapping.TranslationDirection; | 37 | import cuchaz.enigma.mapping.TranslationDirection; |
| 39 | import cuchaz.enigma.mapping.Translator; | 38 | import cuchaz.enigma.mapping.Translator; |
| @@ -47,25 +46,6 @@ public class Deobfuscator | |||
| 47 | private Mappings m_mappings; | 46 | private Mappings m_mappings; |
| 48 | private Renamer m_renamer; | 47 | private Renamer m_renamer; |
| 49 | 48 | ||
| 50 | private static Comparator<ClassFile> m_obfuscatedClassSorter; | ||
| 51 | |||
| 52 | static | ||
| 53 | { | ||
| 54 | m_obfuscatedClassSorter = new Comparator<ClassFile>( ) | ||
| 55 | { | ||
| 56 | @Override | ||
| 57 | public int compare( ClassFile a, ClassFile b ) | ||
| 58 | { | ||
| 59 | if( a.getName().length() != b.getName().length() ) | ||
| 60 | { | ||
| 61 | return a.getName().length() - b.getName().length(); | ||
| 62 | } | ||
| 63 | |||
| 64 | return a.getName().compareTo( b.getName() ); | ||
| 65 | } | ||
| 66 | }; | ||
| 67 | } | ||
| 68 | |||
| 69 | public Deobfuscator( File file ) | 49 | public Deobfuscator( File file ) |
| 70 | throws IOException | 50 | throws IOException |
| 71 | { | 51 | { |
| @@ -120,48 +100,38 @@ public class Deobfuscator | |||
| 120 | ) ); | 100 | ) ); |
| 121 | } | 101 | } |
| 122 | 102 | ||
| 123 | public List<ClassFile> getObfuscatedClasses( ) | 103 | public void getSortedClasses( List<ClassFile> obfClasses, List<ClassFile> deobfClasses ) |
| 124 | { | 104 | { |
| 125 | List<ClassFile> classes = new ArrayList<ClassFile>(); | ||
| 126 | Enumeration<JarEntry> entries = m_jar.entries(); | 105 | Enumeration<JarEntry> entries = m_jar.entries(); |
| 127 | while( entries.hasMoreElements() ) | 106 | while( entries.hasMoreElements() ) |
| 128 | { | 107 | { |
| 129 | JarEntry entry = entries.nextElement(); | 108 | JarEntry entry = entries.nextElement(); |
| 130 | 109 | ||
| 131 | // get the class name | 110 | // get the class name |
| 132 | String className = toClassName( entry.getName() ); | 111 | String obfName = NameValidator.fileNameToClassName( entry.getName() ); |
| 133 | if( className == null ) | 112 | if( obfName == null ) |
| 134 | { | 113 | { |
| 135 | continue; | 114 | continue; |
| 136 | } | 115 | } |
| 137 | 116 | ||
| 138 | ClassFile classFile = new ClassFile( className ); | 117 | ClassFile classFile = new ClassFile( obfName ); |
| 139 | if( classFile.isObfuscated() ) | 118 | ClassMapping classMapping = m_mappings.getClassByObf( classFile.getName() ); |
| 119 | if( classMapping != null ) | ||
| 140 | { | 120 | { |
| 141 | classes.add( classFile ); | 121 | classFile.setDeobfName( classMapping.getDeobfName() ); |
| 122 | deobfClasses.add( classFile ); | ||
| 123 | } | ||
| 124 | else | ||
| 125 | { | ||
| 126 | obfClasses.add( classFile ); | ||
| 142 | } | 127 | } |
| 143 | } | 128 | } |
| 144 | Collections.sort( classes, m_obfuscatedClassSorter ); | ||
| 145 | return classes; | ||
| 146 | } | ||
| 147 | |||
| 148 | // TODO: could go somewhere more generic | ||
| 149 | private static String toClassName( String fileName ) | ||
| 150 | { | ||
| 151 | final String suffix = ".class"; | ||
| 152 | |||
| 153 | if( !fileName.endsWith( suffix ) ) | ||
| 154 | { | ||
| 155 | return null; | ||
| 156 | } | ||
| 157 | |||
| 158 | return fileName.substring( 0, fileName.length() - suffix.length() ).replace( "/", "." ); | ||
| 159 | } | 129 | } |
| 160 | 130 | ||
| 161 | public String getSource( final ClassFile classFile ) | 131 | public String getSource( final ClassFile classFile ) |
| 162 | { | 132 | { |
| 163 | StringWriter buf = new StringWriter(); | 133 | StringWriter buf = new StringWriter(); |
| 164 | Decompiler.decompile( classFile.getName(), new PlainTextOutput( buf ), m_settings ); | 134 | Decompiler.decompile( classFile.getObfName(), new PlainTextOutput( buf ), m_settings ); |
| 165 | return buf.toString(); | 135 | return buf.toString(); |
| 166 | } | 136 | } |
| 167 | 137 | ||