diff options
Diffstat (limited to 'src/cuchaz/enigma/ConvertMain.java')
| -rw-r--r-- | src/cuchaz/enigma/ConvertMain.java | 82 |
1 files changed, 69 insertions, 13 deletions
diff --git a/src/cuchaz/enigma/ConvertMain.java b/src/cuchaz/enigma/ConvertMain.java index e012f19..c3a2ad5 100644 --- a/src/cuchaz/enigma/ConvertMain.java +++ b/src/cuchaz/enigma/ConvertMain.java | |||
| @@ -7,12 +7,14 @@ import java.io.IOException; | |||
| 7 | import java.util.jar.JarFile; | 7 | import java.util.jar.JarFile; |
| 8 | 8 | ||
| 9 | import cuchaz.enigma.convert.ClassMatches; | 9 | import cuchaz.enigma.convert.ClassMatches; |
| 10 | import cuchaz.enigma.convert.FieldMatches; | ||
| 11 | import cuchaz.enigma.convert.MappingsConverter; | 10 | import cuchaz.enigma.convert.MappingsConverter; |
| 12 | import cuchaz.enigma.convert.MatchesReader; | 11 | import cuchaz.enigma.convert.MatchesReader; |
| 13 | import cuchaz.enigma.convert.MatchesWriter; | 12 | import cuchaz.enigma.convert.MatchesWriter; |
| 13 | import cuchaz.enigma.convert.MemberMatches; | ||
| 14 | import cuchaz.enigma.gui.ClassMatchingGui; | 14 | import cuchaz.enigma.gui.ClassMatchingGui; |
| 15 | import cuchaz.enigma.gui.FieldMatchingGui; | 15 | import cuchaz.enigma.gui.MemberMatchingGui; |
| 16 | import cuchaz.enigma.mapping.BehaviorEntry; | ||
| 17 | import cuchaz.enigma.mapping.FieldEntry; | ||
| 16 | import cuchaz.enigma.mapping.MappingParseException; | 18 | import cuchaz.enigma.mapping.MappingParseException; |
| 17 | import cuchaz.enigma.mapping.Mappings; | 19 | import cuchaz.enigma.mapping.Mappings; |
| 18 | import cuchaz.enigma.mapping.MappingsChecker; | 20 | import cuchaz.enigma.mapping.MappingsChecker; |
| @@ -34,13 +36,21 @@ public class ConvertMain { | |||
| 34 | Mappings mappings = new MappingsReader().read(new FileReader(inMappingsFile)); | 36 | Mappings mappings = new MappingsReader().read(new FileReader(inMappingsFile)); |
| 35 | File classMatchesFile = new File(inMappingsFile.getName() + ".class.matches"); | 37 | File classMatchesFile = new File(inMappingsFile.getName() + ".class.matches"); |
| 36 | File fieldMatchesFile = new File(inMappingsFile.getName() + ".field.matches"); | 38 | File fieldMatchesFile = new File(inMappingsFile.getName() + ".field.matches"); |
| 39 | File methodMatchesFile = new File(inMappingsFile.getName() + ".method.matches"); | ||
| 37 | 40 | ||
| 41 | // match classes | ||
| 38 | //computeClassMatches(classMatchesFile, sourceJar, destJar, mappings); | 42 | //computeClassMatches(classMatchesFile, sourceJar, destJar, mappings); |
| 39 | editClasssMatches(classMatchesFile, sourceJar, destJar, mappings); | 43 | //editClasssMatches(classMatchesFile, sourceJar, destJar, mappings); |
| 40 | //convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile); | 44 | //convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile); |
| 45 | |||
| 46 | // match fields | ||
| 41 | //computeFieldMatches(fieldMatchesFile, destJar, outMappingsFile, classMatchesFile); | 47 | //computeFieldMatches(fieldMatchesFile, destJar, outMappingsFile, classMatchesFile); |
| 42 | //editFieldMatches(sourceJar, destJar, outMappingsFile, mappings, classMatchesFile, fieldMatchesFile); | 48 | //editFieldMatches(sourceJar, destJar, outMappingsFile, mappings, classMatchesFile, fieldMatchesFile); |
| 43 | 49 | ||
| 50 | // match methods/constructors | ||
| 51 | //computeMethodMatches(methodMatchesFile, destJar, outMappingsFile, classMatchesFile); | ||
| 52 | editMethodMatches(sourceJar, destJar, outMappingsFile, mappings, classMatchesFile, methodMatchesFile); | ||
| 53 | |||
| 44 | /* TODO | 54 | /* TODO |
| 45 | // write out the converted mappings | 55 | // write out the converted mappings |
| 46 | FileWriter writer = new FileWriter(outMappingsFile); | 56 | FileWriter writer = new FileWriter(outMappingsFile); |
| @@ -91,7 +101,7 @@ public class ConvertMain { | |||
| 91 | System.out.println("Write converted mappings to: " + outMappingsFile.getAbsolutePath()); | 101 | System.out.println("Write converted mappings to: " + outMappingsFile.getAbsolutePath()); |
| 92 | } | 102 | } |
| 93 | 103 | ||
| 94 | private static void computeFieldMatches(File fieldMatchesFile, JarFile destJar, File destMappingsFile, File classMatchesFile) | 104 | private static void computeFieldMatches(File memberMatchesFile, JarFile destJar, File destMappingsFile, File classMatchesFile) |
| 95 | throws IOException, MappingParseException { | 105 | throws IOException, MappingParseException { |
| 96 | 106 | ||
| 97 | System.out.println("Reading class matches..."); | 107 | System.out.println("Reading class matches..."); |
| @@ -101,13 +111,13 @@ public class ConvertMain { | |||
| 101 | System.out.println("Indexing dest jar..."); | 111 | System.out.println("Indexing dest jar..."); |
| 102 | Deobfuscator destDeobfuscator = new Deobfuscator(destJar); | 112 | Deobfuscator destDeobfuscator = new Deobfuscator(destJar); |
| 103 | 113 | ||
| 104 | System.out.println("Writing field matches..."); | 114 | System.out.println("Writing matches..."); |
| 105 | 115 | ||
| 106 | // get the matched and unmatched field mappings | 116 | // get the matched and unmatched mappings |
| 107 | FieldMatches fieldMatches = MappingsConverter.computeFieldMatches(destDeobfuscator, destMappings, classMatches); | 117 | MemberMatches<FieldEntry> fieldMatches = MappingsConverter.computeFieldMatches(destDeobfuscator, destMappings, classMatches); |
| 108 | 118 | ||
| 109 | MatchesWriter.writeFields(fieldMatches, fieldMatchesFile); | 119 | MatchesWriter.writeMembers(fieldMatches, memberMatchesFile); |
| 110 | System.out.println("Wrote:\n\t" + fieldMatchesFile.getAbsolutePath()); | 120 | System.out.println("Wrote:\n\t" + memberMatchesFile.getAbsolutePath()); |
| 111 | } | 121 | } |
| 112 | 122 | ||
| 113 | private static void editFieldMatches(JarFile sourceJar, JarFile destJar, File destMappingsFile, Mappings sourceMappings, File classMatchesFile, final File fieldMatchesFile) | 123 | private static void editFieldMatches(JarFile sourceJar, JarFile destJar, File destMappingsFile, Mappings sourceMappings, File classMatchesFile, final File fieldMatchesFile) |
| @@ -115,7 +125,7 @@ public class ConvertMain { | |||
| 115 | 125 | ||
| 116 | System.out.println("Reading matches..."); | 126 | System.out.println("Reading matches..."); |
| 117 | ClassMatches classMatches = MatchesReader.readClasses(classMatchesFile); | 127 | ClassMatches classMatches = MatchesReader.readClasses(classMatchesFile); |
| 118 | FieldMatches fieldMatches = MatchesReader.readFields(fieldMatchesFile); | 128 | MemberMatches<FieldEntry> fieldMatches = MatchesReader.readMembers(fieldMatchesFile); |
| 119 | 129 | ||
| 120 | // prep deobfuscators | 130 | // prep deobfuscators |
| 121 | Deobfuscators deobfuscators = new Deobfuscators(sourceJar, destJar); | 131 | Deobfuscators deobfuscators = new Deobfuscators(sourceJar, destJar); |
| @@ -125,18 +135,64 @@ public class ConvertMain { | |||
| 125 | checker.dropBrokenMappings(destMappings); | 135 | checker.dropBrokenMappings(destMappings); |
| 126 | deobfuscators.dest.setMappings(destMappings); | 136 | deobfuscators.dest.setMappings(destMappings); |
| 127 | 137 | ||
| 128 | new FieldMatchingGui(classMatches, fieldMatches, deobfuscators.source, deobfuscators.dest).setSaveListener(new FieldMatchingGui.SaveListener() { | 138 | new MemberMatchingGui<FieldEntry>(classMatches, fieldMatches, deobfuscators.source, deobfuscators.dest).setSaveListener(new MemberMatchingGui.SaveListener<FieldEntry>() { |
| 129 | @Override | 139 | @Override |
| 130 | public void save(FieldMatches matches) { | 140 | public void save(MemberMatches<FieldEntry> matches) { |
| 131 | try { | 141 | try { |
| 132 | MatchesWriter.writeFields(matches, fieldMatchesFile); | 142 | MatchesWriter.writeMembers(matches, fieldMatchesFile); |
| 133 | } catch (IOException ex) { | 143 | } catch (IOException ex) { |
| 134 | throw new Error(ex); | 144 | throw new Error(ex); |
| 135 | } | 145 | } |
| 136 | } | 146 | } |
| 137 | }); | 147 | }); |
| 138 | } | 148 | } |
| 149 | |||
| 150 | private static void computeMethodMatches(File methodMatchesFile, JarFile destJar, File destMappingsFile, File classMatchesFile) | ||
| 151 | throws IOException, MappingParseException { | ||
| 152 | |||
| 153 | System.out.println("Reading class matches..."); | ||
| 154 | ClassMatches classMatches = MatchesReader.readClasses(classMatchesFile); | ||
| 155 | System.out.println("Reading mappings..."); | ||
| 156 | Mappings destMappings = new MappingsReader().read(new FileReader(destMappingsFile)); | ||
| 157 | System.out.println("Indexing dest jar..."); | ||
| 158 | Deobfuscator destDeobfuscator = new Deobfuscator(destJar); | ||
| 159 | |||
| 160 | System.out.println("Writing method matches..."); | ||
| 161 | |||
| 162 | // get the matched and unmatched mappings | ||
| 163 | MemberMatches<BehaviorEntry> methodMatches = MappingsConverter.computeBehaviorMatches(destDeobfuscator, destMappings, classMatches); | ||
| 164 | |||
| 165 | MatchesWriter.writeMembers(methodMatches, methodMatchesFile); | ||
| 166 | System.out.println("Wrote:\n\t" + methodMatchesFile.getAbsolutePath()); | ||
| 167 | } | ||
| 139 | 168 | ||
| 169 | private static void editMethodMatches(JarFile sourceJar, JarFile destJar, File destMappingsFile, Mappings sourceMappings, File classMatchesFile, final File methodMatchesFile) | ||
| 170 | throws IOException, MappingParseException { | ||
| 171 | |||
| 172 | System.out.println("Reading matches..."); | ||
| 173 | ClassMatches classMatches = MatchesReader.readClasses(classMatchesFile); | ||
| 174 | MemberMatches<BehaviorEntry> methodMatches = MatchesReader.readMembers(methodMatchesFile); | ||
| 175 | |||
| 176 | // prep deobfuscators | ||
| 177 | Deobfuscators deobfuscators = new Deobfuscators(sourceJar, destJar); | ||
| 178 | deobfuscators.source.setMappings(sourceMappings); | ||
| 179 | Mappings destMappings = new MappingsReader().read(new FileReader(destMappingsFile)); | ||
| 180 | MappingsChecker checker = new MappingsChecker(deobfuscators.dest.getJarIndex()); | ||
| 181 | checker.dropBrokenMappings(destMappings); | ||
| 182 | deobfuscators.dest.setMappings(destMappings); | ||
| 183 | |||
| 184 | new MemberMatchingGui<BehaviorEntry>(classMatches, methodMatches, deobfuscators.source, deobfuscators.dest).setSaveListener(new MemberMatchingGui.SaveListener<BehaviorEntry>() { | ||
| 185 | @Override | ||
| 186 | public void save(MemberMatches<BehaviorEntry> matches) { | ||
| 187 | try { | ||
| 188 | MatchesWriter.writeMembers(matches, methodMatchesFile); | ||
| 189 | } catch (IOException ex) { | ||
| 190 | throw new Error(ex); | ||
| 191 | } | ||
| 192 | } | ||
| 193 | }); | ||
| 194 | } | ||
| 195 | |||
| 140 | private static class Deobfuscators { | 196 | private static class Deobfuscators { |
| 141 | 197 | ||
| 142 | public Deobfuscator source; | 198 | public Deobfuscator source; |