diff options
Diffstat (limited to 'src/cuchaz/enigma/ConvertMain.java')
| -rw-r--r-- | src/cuchaz/enigma/ConvertMain.java | 136 |
1 files changed, 108 insertions, 28 deletions
diff --git a/src/cuchaz/enigma/ConvertMain.java b/src/cuchaz/enigma/ConvertMain.java index 2afd9ca..624eb40 100644 --- a/src/cuchaz/enigma/ConvertMain.java +++ b/src/cuchaz/enigma/ConvertMain.java | |||
| @@ -6,14 +6,16 @@ import java.io.FileWriter; | |||
| 6 | import java.io.IOException; | 6 | import java.io.IOException; |
| 7 | import java.util.jar.JarFile; | 7 | import java.util.jar.JarFile; |
| 8 | 8 | ||
| 9 | import cuchaz.enigma.convert.ClassMatches; | ||
| 10 | import cuchaz.enigma.convert.FieldMatches; | ||
| 9 | import cuchaz.enigma.convert.MappingsConverter; | 11 | import cuchaz.enigma.convert.MappingsConverter; |
| 10 | import cuchaz.enigma.convert.Matches; | ||
| 11 | import cuchaz.enigma.convert.MatchesReader; | 12 | import cuchaz.enigma.convert.MatchesReader; |
| 12 | import cuchaz.enigma.convert.MatchesWriter; | 13 | import cuchaz.enigma.convert.MatchesWriter; |
| 13 | import cuchaz.enigma.gui.ClassMatchingGui; | 14 | import cuchaz.enigma.gui.ClassMatchingGui; |
| 14 | import cuchaz.enigma.gui.ClassMatchingGui.SaveListener; | 15 | import cuchaz.enigma.gui.FieldMatchingGui; |
| 15 | import cuchaz.enigma.mapping.MappingParseException; | 16 | import cuchaz.enigma.mapping.MappingParseException; |
| 16 | import cuchaz.enigma.mapping.Mappings; | 17 | import cuchaz.enigma.mapping.Mappings; |
| 18 | import cuchaz.enigma.mapping.MappingsChecker; | ||
| 17 | import cuchaz.enigma.mapping.MappingsReader; | 19 | import cuchaz.enigma.mapping.MappingsReader; |
| 18 | import cuchaz.enigma.mapping.MappingsWriter; | 20 | import cuchaz.enigma.mapping.MappingsWriter; |
| 19 | 21 | ||
| @@ -30,11 +32,13 @@ public class ConvertMain { | |||
| 30 | File inMappingsFile = new File("../Enigma Mappings/1.8.mappings"); | 32 | File inMappingsFile = new File("../Enigma Mappings/1.8.mappings"); |
| 31 | File outMappingsFile = new File("../Enigma Mappings/1.8.3.mappings"); | 33 | File outMappingsFile = new File("../Enigma Mappings/1.8.3.mappings"); |
| 32 | Mappings mappings = new MappingsReader().read(new FileReader(inMappingsFile)); | 34 | Mappings mappings = new MappingsReader().read(new FileReader(inMappingsFile)); |
| 33 | File matchingFile = new File(inMappingsFile.getName() + ".matching"); | 35 | File classMatchingFile = new File(inMappingsFile.getName() + ".class.matching"); |
| 36 | File fieldMatchingFile = new File(inMappingsFile.getName() + ".field.matching"); | ||
| 34 | 37 | ||
| 35 | //computeMatches(matchingFile, sourceJar, destJar, mappings); | 38 | //computeMatches(classMatchingFile, sourceJar, destJar, mappings); |
| 36 | editMatches(matchingFile, sourceJar, destJar, mappings); | 39 | //editClasssMatches(classMatchingFile, sourceJar, destJar, mappings); |
| 37 | //convertMappings(outMappingsFile, sourceJar, destJar, mappings, matchingFile); | 40 | //convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchingFile); |
| 41 | editFieldMatches(sourceJar, destJar, outMappingsFile, mappings, classMatchingFile, fieldMatchingFile); | ||
| 38 | 42 | ||
| 39 | /* TODO | 43 | /* TODO |
| 40 | // write out the converted mappings | 44 | // write out the converted mappings |
| @@ -45,28 +49,25 @@ public class ConvertMain { | |||
| 45 | */ | 49 | */ |
| 46 | } | 50 | } |
| 47 | 51 | ||
| 48 | private static void computeMatches(File matchingFile, JarFile sourceJar, JarFile destJar, Mappings mappings) | 52 | private static void computeMatches(File classMatchingFile, JarFile sourceJar, JarFile destJar, Mappings mappings) |
| 49 | throws IOException { | 53 | throws IOException { |
| 50 | Matches matches = MappingsConverter.computeMatches(sourceJar, destJar, mappings); | 54 | ClassMatches classMatches = MappingsConverter.computeMatches(sourceJar, destJar, mappings); |
| 51 | MatchesWriter.write(matches, matchingFile); | 55 | MatchesWriter.writeClasses(classMatches, classMatchingFile); |
| 52 | System.out.println("Wrote:\n\t" + matchingFile.getAbsolutePath()); | 56 | System.out.println("Wrote:\n\t" + classMatchingFile.getAbsolutePath()); |
| 53 | } | 57 | } |
| 54 | 58 | ||
| 55 | private static void editMatches(final File matchingFile, JarFile sourceJar, JarFile destJar, Mappings mappings) | 59 | private static void editClasssMatches(final File classMatchingFile, JarFile sourceJar, JarFile destJar, Mappings mappings) |
| 56 | throws IOException { | 60 | throws IOException { |
| 57 | System.out.println("Reading matches..."); | 61 | System.out.println("Reading matches..."); |
| 58 | Matches matches = MatchesReader.read(matchingFile); | 62 | ClassMatches classMatches = MatchesReader.readClasses(classMatchingFile); |
| 59 | System.out.println("Indexing source jar..."); | 63 | Deobfuscators deobfuscators = new Deobfuscators(sourceJar, destJar); |
| 60 | Deobfuscator sourceDeobfuscator = new Deobfuscator(sourceJar); | 64 | deobfuscators.source.setMappings(mappings); |
| 61 | sourceDeobfuscator.setMappings(mappings); | ||
| 62 | System.out.println("Indexing dest jar..."); | ||
| 63 | Deobfuscator destDeobfuscator = new Deobfuscator(destJar); | ||
| 64 | System.out.println("Starting GUI..."); | 65 | System.out.println("Starting GUI..."); |
| 65 | new ClassMatchingGui(matches, sourceDeobfuscator, destDeobfuscator).setSaveListener(new SaveListener() { | 66 | new ClassMatchingGui(classMatches, deobfuscators.source, deobfuscators.dest).setSaveListener(new ClassMatchingGui.SaveListener() { |
| 66 | @Override | 67 | @Override |
| 67 | public void save(Matches matches) { | 68 | public void save(ClassMatches matches) { |
| 68 | try { | 69 | try { |
| 69 | MatchesWriter.write(matches, matchingFile); | 70 | MatchesWriter.writeClasses(matches, classMatchingFile); |
| 70 | } catch (IOException ex) { | 71 | } catch (IOException ex) { |
| 71 | throw new Error(ex); | 72 | throw new Error(ex); |
| 72 | } | 73 | } |
| @@ -74,21 +75,100 @@ public class ConvertMain { | |||
| 74 | }); | 75 | }); |
| 75 | } | 76 | } |
| 76 | 77 | ||
| 77 | private static void convertMappings(File outMappingsFile, JarFile sourceJar, JarFile destJar, Mappings mappings, File matchingFile) | 78 | private static void convertMappings(File outMappingsFile, JarFile sourceJar, JarFile destJar, Mappings mappings, File classMatchingFile) |
| 78 | throws IOException { | 79 | throws IOException { |
| 79 | System.out.println("Reading matches..."); | 80 | System.out.println("Reading matches..."); |
| 80 | Matches matches = MatchesReader.read(matchingFile); | 81 | ClassMatches classMatches = MatchesReader.readClasses(classMatchingFile); |
| 81 | System.out.println("Indexing source jar..."); | 82 | Deobfuscators deobfuscators = new Deobfuscators(sourceJar, destJar); |
| 82 | Deobfuscator sourceDeobfuscator = new Deobfuscator(sourceJar); | 83 | deobfuscators.source.setMappings(mappings); |
| 83 | sourceDeobfuscator.setMappings(mappings); | ||
| 84 | System.out.println("Indexing dest jar..."); | ||
| 85 | Deobfuscator destDeobfuscator = new Deobfuscator(destJar); | ||
| 86 | 84 | ||
| 87 | Mappings newMappings = MappingsConverter.newMappings(matches, mappings, sourceDeobfuscator, destDeobfuscator); | 85 | Mappings newMappings = MappingsConverter.newMappings(classMatches, mappings, deobfuscators.source, deobfuscators.source); |
| 88 | 86 | ||
| 89 | try (FileWriter out = new FileWriter(outMappingsFile)) { | 87 | try (FileWriter out = new FileWriter(outMappingsFile)) { |
| 90 | new MappingsWriter().write(out, newMappings); | 88 | new MappingsWriter().write(out, newMappings); |
| 91 | } | 89 | } |
| 92 | System.out.println("Write converted mappings to: " + outMappingsFile.getAbsolutePath()); | 90 | System.out.println("Write converted mappings to: " + outMappingsFile.getAbsolutePath()); |
| 93 | } | 91 | } |
| 92 | |||
| 93 | private static void editFieldMatches(JarFile sourceJar, JarFile destJar, File destMappingsFile, Mappings sourceMappings, File classMatchingFile, final File fieldMatchingFile) | ||
| 94 | throws IOException, MappingParseException { | ||
| 95 | |||
| 96 | System.out.println("Reading matches..."); | ||
| 97 | ClassMatches classMatches = MatchesReader.readClasses(classMatchingFile); | ||
| 98 | FieldMatches fieldMatches; | ||
| 99 | if (fieldMatchingFile.exists() /* TEMP */ && false) { | ||
| 100 | // TODO | ||
| 101 | //fieldMatches = MatchesReader.readFields(fieldMatchingFile); | ||
| 102 | } else { | ||
| 103 | fieldMatches = new FieldMatches(); | ||
| 104 | } | ||
| 105 | |||
| 106 | // prep deobfuscators | ||
| 107 | Deobfuscators deobfuscators = new Deobfuscators(sourceJar, destJar); | ||
| 108 | deobfuscators.source.setMappings(sourceMappings); | ||
| 109 | Mappings destMappings = new MappingsReader().read(new FileReader(destMappingsFile)); | ||
| 110 | MappingsChecker checker = new MappingsChecker(deobfuscators.dest.getJarIndex()); | ||
| 111 | checker.dropBrokenMappings(destMappings); | ||
| 112 | deobfuscators.dest.setMappings(destMappings); | ||
| 113 | |||
| 114 | new FieldMatchingGui(classMatches, fieldMatches, checker.getDroppedFieldMappings(), deobfuscators.source, deobfuscators.dest).setSaveListener(new FieldMatchingGui.SaveListener() { | ||
| 115 | @Override | ||
| 116 | public void save(FieldMatches matches) { | ||
| 117 | /* TODO | ||
| 118 | try { | ||
| 119 | MatchesWriter.writeFields(matches, fieldMatchingFile); | ||
| 120 | } catch (IOException ex) { | ||
| 121 | throw new Error(ex); | ||
| 122 | } | ||
| 123 | */ | ||
| 124 | } | ||
| 125 | }); | ||
| 126 | } | ||
| 127 | |||
| 128 | private static class Deobfuscators { | ||
| 129 | |||
| 130 | public Deobfuscator source; | ||
| 131 | public Deobfuscator dest; | ||
| 132 | |||
| 133 | public Deobfuscators(JarFile sourceJar, JarFile destJar) { | ||
| 134 | System.out.println("Indexing source jar..."); | ||
| 135 | IndexerThread sourceIndexer = new IndexerThread(sourceJar); | ||
| 136 | sourceIndexer.start(); | ||
| 137 | System.out.println("Indexing dest jar..."); | ||
| 138 | IndexerThread destIndexer = new IndexerThread(destJar); | ||
| 139 | destIndexer.start(); | ||
| 140 | sourceIndexer.joinOrBail(); | ||
| 141 | destIndexer.joinOrBail(); | ||
| 142 | source = sourceIndexer.deobfuscator; | ||
| 143 | dest = destIndexer.deobfuscator; | ||
| 144 | } | ||
| 145 | } | ||
| 146 | |||
| 147 | private static class IndexerThread extends Thread { | ||
| 148 | |||
| 149 | private JarFile m_jarFile; | ||
| 150 | public Deobfuscator deobfuscator; | ||
| 151 | |||
| 152 | public IndexerThread(JarFile jarFile) { | ||
| 153 | m_jarFile = jarFile; | ||
| 154 | deobfuscator = null; | ||
| 155 | } | ||
| 156 | |||
| 157 | public void joinOrBail() { | ||
| 158 | try { | ||
| 159 | join(); | ||
| 160 | } catch (InterruptedException ex) { | ||
| 161 | throw new Error(ex); | ||
| 162 | } | ||
| 163 | } | ||
| 164 | |||
| 165 | @Override | ||
| 166 | public void run() { | ||
| 167 | try { | ||
| 168 | deobfuscator = new Deobfuscator(m_jarFile); | ||
| 169 | } catch (IOException ex) { | ||
| 170 | throw new Error(ex); | ||
| 171 | } | ||
| 172 | } | ||
| 173 | } | ||
| 94 | } | 174 | } |