diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/ConvertMain.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/ConvertMain.java | 669 |
1 files changed, 334 insertions, 335 deletions
diff --git a/src/main/java/cuchaz/enigma/ConvertMain.java b/src/main/java/cuchaz/enigma/ConvertMain.java index 48e7f27..3d58f57 100644 --- a/src/main/java/cuchaz/enigma/ConvertMain.java +++ b/src/main/java/cuchaz/enigma/ConvertMain.java | |||
| @@ -8,11 +8,8 @@ | |||
| 8 | * Contributors: | 8 | * Contributors: |
| 9 | * Jeff Martin - initial API and implementation | 9 | * Jeff Martin - initial API and implementation |
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | package cuchaz.enigma; | ||
| 12 | 11 | ||
| 13 | import java.io.File; | 12 | package cuchaz.enigma; |
| 14 | import java.io.IOException; | ||
| 15 | import java.util.jar.JarFile; | ||
| 16 | 13 | ||
| 17 | import cuchaz.enigma.convert.*; | 14 | import cuchaz.enigma.convert.*; |
| 18 | import cuchaz.enigma.gui.ClassMatchingGui; | 15 | import cuchaz.enigma.gui.ClassMatchingGui; |
| @@ -21,338 +18,340 @@ import cuchaz.enigma.mapping.*; | |||
| 21 | import cuchaz.enigma.throwables.MappingConflict; | 18 | import cuchaz.enigma.throwables.MappingConflict; |
| 22 | import cuchaz.enigma.throwables.MappingParseException; | 19 | import cuchaz.enigma.throwables.MappingParseException; |
| 23 | 20 | ||
| 21 | import java.io.File; | ||
| 22 | import java.io.IOException; | ||
| 23 | import java.util.jar.JarFile; | ||
| 24 | 24 | ||
| 25 | public class ConvertMain { | 25 | public class ConvertMain { |
| 26 | 26 | ||
| 27 | public static void main(String[] args) | 27 | public static void main(String[] args) |
| 28 | throws IOException, MappingParseException { | 28 | throws IOException, MappingParseException { |
| 29 | try { | 29 | try { |
| 30 | //Get all are args | 30 | //Get all are args |
| 31 | String JarOld = getArg(args, 1, "Path to Old Jar", true); | 31 | String JarOld = getArg(args, 1, "Path to Old Jar", true); |
| 32 | String JarNew = getArg(args, 2, "Path to New Jar", true); | 32 | String JarNew = getArg(args, 2, "Path to New Jar", true); |
| 33 | String OldMappings = getArg(args, 3, "Path to old .mappings file", true); | 33 | String OldMappings = getArg(args, 3, "Path to old .mappings file", true); |
| 34 | String NewMappings = getArg(args, 4, "Path to new .mappings file", true); | 34 | String NewMappings = getArg(args, 4, "Path to new .mappings file", true); |
| 35 | String ClassMatches = getArg(args, 5, "Path to Class .matches file", true); | 35 | String ClassMatches = getArg(args, 5, "Path to Class .matches file", true); |
| 36 | String FieldMatches = getArg(args, 6, "Path to Field .matches file", true); | 36 | String FieldMatches = getArg(args, 6, "Path to Field .matches file", true); |
| 37 | String MethodMatches = getArg(args, 7, "Path to Method .matches file", true); | 37 | String MethodMatches = getArg(args, 7, "Path to Method .matches file", true); |
| 38 | //OldJar | 38 | //OldJar |
| 39 | JarFile sourceJar = new JarFile(new File(JarOld)); | 39 | JarFile sourceJar = new JarFile(new File(JarOld)); |
| 40 | //NewJar | 40 | //NewJar |
| 41 | JarFile destJar = new JarFile(new File(JarNew)); | 41 | JarFile destJar = new JarFile(new File(JarNew)); |
| 42 | //Get the mapping files | 42 | //Get the mapping files |
| 43 | File inMappingsFile = new File(OldMappings); | 43 | File inMappingsFile = new File(OldMappings); |
| 44 | File outMappingsFile = new File(NewMappings); | 44 | File outMappingsFile = new File(NewMappings); |
| 45 | Mappings mappings = new MappingsEnigmaReader().read(inMappingsFile); | 45 | Mappings mappings = new MappingsEnigmaReader().read(inMappingsFile); |
| 46 | //Make the Match Files.. | 46 | //Make the Match Files.. |
| 47 | File classMatchesFile = new File(ClassMatches); | 47 | File classMatchesFile = new File(ClassMatches); |
| 48 | File fieldMatchesFile = new File(FieldMatches); | 48 | File fieldMatchesFile = new File(FieldMatches); |
| 49 | File methodMatchesFile = new File(MethodMatches); | 49 | File methodMatchesFile = new File(MethodMatches); |
| 50 | 50 | ||
| 51 | String command = getArg(args, 0, "command", true); | 51 | String command = getArg(args, 0, "command", true); |
| 52 | 52 | ||
| 53 | if (command.equalsIgnoreCase("computeClassMatches")) { | 53 | if (command.equalsIgnoreCase("computeClassMatches")) { |
| 54 | computeClassMatches(classMatchesFile, sourceJar, destJar, mappings); | 54 | computeClassMatches(classMatchesFile, sourceJar, destJar, mappings); |
| 55 | convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile); | 55 | convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile); |
| 56 | } else if (command.equalsIgnoreCase("editClassMatches")) { | 56 | } else if (command.equalsIgnoreCase("editClassMatches")) { |
| 57 | editClasssMatches(classMatchesFile, sourceJar, destJar, mappings); | 57 | editClasssMatches(classMatchesFile, sourceJar, destJar, mappings); |
| 58 | convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile); | 58 | convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile); |
| 59 | } else if (command.equalsIgnoreCase("computeFieldMatches")) { | 59 | } else if (command.equalsIgnoreCase("computeFieldMatches")) { |
| 60 | computeFieldMatches(fieldMatchesFile, destJar, outMappingsFile, classMatchesFile); | 60 | computeFieldMatches(fieldMatchesFile, destJar, outMappingsFile, classMatchesFile); |
| 61 | convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile); | 61 | convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile); |
| 62 | } else if (command.equalsIgnoreCase("editFieldMatches")) { | 62 | } else if (command.equalsIgnoreCase("editFieldMatches")) { |
| 63 | editFieldMatches(sourceJar, destJar, outMappingsFile, mappings, classMatchesFile, fieldMatchesFile); | 63 | editFieldMatches(sourceJar, destJar, outMappingsFile, mappings, classMatchesFile, fieldMatchesFile); |
| 64 | convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile); | 64 | convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile); |
| 65 | } else if (command.equalsIgnoreCase("computeMethodMatches")) { | 65 | } else if (command.equalsIgnoreCase("computeMethodMatches")) { |
| 66 | computeMethodMatches(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile, methodMatchesFile); | 66 | computeMethodMatches(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile, methodMatchesFile); |
| 67 | convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile, methodMatchesFile); | 67 | convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile, methodMatchesFile); |
| 68 | } else if (command.equalsIgnoreCase("editMethodMatches")) { | 68 | } else if (command.equalsIgnoreCase("editMethodMatches")) { |
| 69 | editMethodMatches(sourceJar, destJar, outMappingsFile, mappings, classMatchesFile, methodMatchesFile); | 69 | editMethodMatches(sourceJar, destJar, outMappingsFile, mappings, classMatchesFile, methodMatchesFile); |
| 70 | convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile, methodMatchesFile); | 70 | convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile, methodMatchesFile); |
| 71 | } else if (command.equalsIgnoreCase("convertMappings")) { | 71 | } else if (command.equalsIgnoreCase("convertMappings")) { |
| 72 | convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile, methodMatchesFile); | 72 | convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile, methodMatchesFile); |
| 73 | } | 73 | } |
| 74 | } catch (MappingConflict ex) { | 74 | } catch (MappingConflict ex) { |
| 75 | System.out.println(ex.getMessage()); | 75 | System.out.println(ex.getMessage()); |
| 76 | ex.printStackTrace(); | 76 | ex.printStackTrace(); |
| 77 | } catch (IllegalArgumentException ex) { | 77 | } catch (IllegalArgumentException ex) { |
| 78 | System.out.println(ex.getMessage()); | 78 | System.out.println(ex.getMessage()); |
| 79 | printHelp(); | 79 | printHelp(); |
| 80 | } | 80 | } |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | private static void printHelp() { | 83 | private static void printHelp() { |
| 84 | System.out.println(String.format("%s - %s", Constants.NAME, Constants.VERSION)); | 84 | System.out.println(String.format("%s - %s", Constants.NAME, Constants.VERSION)); |
| 85 | System.out.println("Usage:"); | 85 | System.out.println("Usage:"); |
| 86 | System.out.println("\tjava -cp enigma.jar cuchaz.enigma.ConvertMain <command> <old-jar> <new-jar> <old-mappings> <new-mappings> <class-matches> <field-matches> <method-matches>"); | 86 | System.out.println("\tjava -cp enigma.jar cuchaz.enigma.ConvertMain <command> <old-jar> <new-jar> <old-mappings> <new-mappings> <class-matches> <field-matches> <method-matches>"); |
| 87 | System.out.println("\tWhere <command> is one of:"); | 87 | System.out.println("\tWhere <command> is one of:"); |
| 88 | System.out.println("\t\tcomputeClassMatches"); | 88 | System.out.println("\t\tcomputeClassMatches"); |
| 89 | System.out.println("\t\teditClassMatches"); | 89 | System.out.println("\t\teditClassMatches"); |
| 90 | System.out.println("\t\tcomputeFieldMatches"); | 90 | System.out.println("\t\tcomputeFieldMatches"); |
| 91 | System.out.println("\t\teditFieldMatches"); | 91 | System.out.println("\t\teditFieldMatches"); |
| 92 | System.out.println("\t\teditMethodMatches"); | 92 | System.out.println("\t\teditMethodMatches"); |
| 93 | System.out.println("\t\tconvertMappings"); | 93 | System.out.println("\t\tconvertMappings"); |
| 94 | System.out.println("\tWhere <old-jar> is the already mapped jar."); | 94 | System.out.println("\tWhere <old-jar> is the already mapped jar."); |
| 95 | System.out.println("\tWhere <new-jar> is the unmapped jar."); | 95 | System.out.println("\tWhere <new-jar> is the unmapped jar."); |
| 96 | System.out.println("\tWhere <old-mappings> is the path to the mappings for the old jar."); | 96 | System.out.println("\tWhere <old-mappings> is the path to the mappings for the old jar."); |
| 97 | System.out.println("\tWhere <new-mappings> is the new mappings. (Where you want to save them and there name)"); | 97 | System.out.println("\tWhere <new-mappings> is the new mappings. (Where you want to save them and there name)"); |
| 98 | System.out.println("\tWhere <class-matches> is the class matches file."); | 98 | System.out.println("\tWhere <class-matches> is the class matches file."); |
| 99 | System.out.println("\tWhere <field-matches> is the field matches file."); | 99 | System.out.println("\tWhere <field-matches> is the field matches file."); |
| 100 | System.out.println("\tWhere <method-matches> is the method matches file."); | 100 | System.out.println("\tWhere <method-matches> is the method matches file."); |
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | //Copy of getArg from CommandMain.... Should make a utils class. | 103 | //Copy of getArg from CommandMain.... Should make a utils class. |
| 104 | private static String getArg(String[] args, int i, String name, boolean required) { | 104 | private static String getArg(String[] args, int i, String name, boolean required) { |
| 105 | if (i >= args.length) { | 105 | if (i >= args.length) { |
| 106 | if (required) { | 106 | if (required) { |
| 107 | throw new IllegalArgumentException(name + " is required"); | 107 | throw new IllegalArgumentException(name + " is required"); |
| 108 | } else { | 108 | } else { |
| 109 | return null; | 109 | return null; |
| 110 | } | 110 | } |
| 111 | } | 111 | } |
| 112 | return args[i]; | 112 | return args[i]; |
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | private static void computeClassMatches(File classMatchesFile, JarFile sourceJar, JarFile destJar, Mappings mappings) | 115 | private static void computeClassMatches(File classMatchesFile, JarFile sourceJar, JarFile destJar, Mappings mappings) |
| 116 | throws IOException { | 116 | throws IOException { |
| 117 | ClassMatches classMatches = MappingsConverter.computeClassMatches(sourceJar, destJar, mappings); | 117 | ClassMatches classMatches = MappingsConverter.computeClassMatches(sourceJar, destJar, mappings); |
| 118 | MatchesWriter.writeClasses(classMatches, classMatchesFile); | 118 | MatchesWriter.writeClasses(classMatches, classMatchesFile); |
| 119 | System.out.println("Wrote:\n\t" + classMatchesFile.getAbsolutePath()); | 119 | System.out.println("Wrote:\n\t" + classMatchesFile.getAbsolutePath()); |
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | private static void editClasssMatches(final File classMatchesFile, JarFile sourceJar, JarFile destJar, Mappings mappings) | 122 | private static void editClasssMatches(final File classMatchesFile, JarFile sourceJar, JarFile destJar, Mappings mappings) |
| 123 | throws IOException { | 123 | throws IOException { |
| 124 | System.out.println("Reading class matches..."); | 124 | System.out.println("Reading class matches..."); |
| 125 | ClassMatches classMatches = MatchesReader.readClasses(classMatchesFile); | 125 | ClassMatches classMatches = MatchesReader.readClasses(classMatchesFile); |
| 126 | Deobfuscators deobfuscators = new Deobfuscators(sourceJar, destJar); | 126 | Deobfuscators deobfuscators = new Deobfuscators(sourceJar, destJar); |
| 127 | deobfuscators.source.setMappings(mappings); | 127 | deobfuscators.source.setMappings(mappings); |
| 128 | System.out.println("Starting GUI..."); | 128 | System.out.println("Starting GUI..."); |
| 129 | new ClassMatchingGui(classMatches, deobfuscators.source, deobfuscators.dest).setSaveListener(matches -> | 129 | new ClassMatchingGui(classMatches, deobfuscators.source, deobfuscators.dest).setSaveListener(matches -> |
| 130 | { | 130 | { |
| 131 | try { | 131 | try { |
| 132 | MatchesWriter.writeClasses(matches, classMatchesFile); | 132 | MatchesWriter.writeClasses(matches, classMatchesFile); |
| 133 | } catch (IOException ex) { | 133 | } catch (IOException ex) { |
| 134 | throw new Error(ex); | 134 | throw new Error(ex); |
| 135 | } | 135 | } |
| 136 | }); | 136 | }); |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | @SuppressWarnings("unused") | 139 | @SuppressWarnings("unused") |
| 140 | private static void convertMappings(File outMappingsFile, JarFile sourceJar, JarFile destJar, Mappings mappings, File classMatchesFile) | 140 | private static void convertMappings(File outMappingsFile, JarFile sourceJar, JarFile destJar, Mappings mappings, File classMatchesFile) |
| 141 | throws IOException, MappingConflict { | 141 | throws IOException, MappingConflict { |
| 142 | System.out.println("Reading class matches..."); | 142 | System.out.println("Reading class matches..."); |
| 143 | ClassMatches classMatches = MatchesReader.readClasses(classMatchesFile); | 143 | ClassMatches classMatches = MatchesReader.readClasses(classMatchesFile); |
| 144 | Deobfuscators deobfuscators = new Deobfuscators(sourceJar, destJar); | 144 | Deobfuscators deobfuscators = new Deobfuscators(sourceJar, destJar); |
| 145 | deobfuscators.source.setMappings(mappings); | 145 | deobfuscators.source.setMappings(mappings); |
| 146 | 146 | ||
| 147 | Mappings newMappings = MappingsConverter.newMappings(classMatches, mappings, deobfuscators.source, deobfuscators.dest); | 147 | Mappings newMappings = MappingsConverter.newMappings(classMatches, mappings, deobfuscators.source, deobfuscators.dest); |
| 148 | new MappingsEnigmaWriter().write(outMappingsFile, newMappings, true); | 148 | new MappingsEnigmaWriter().write(outMappingsFile, newMappings, true); |
| 149 | System.out.println("Write converted mappings to: " + outMappingsFile.getAbsolutePath()); | 149 | System.out.println("Write converted mappings to: " + outMappingsFile.getAbsolutePath()); |
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | private static void computeFieldMatches(File memberMatchesFile, JarFile destJar, File destMappingsFile, File classMatchesFile) | 152 | private static void computeFieldMatches(File memberMatchesFile, JarFile destJar, File destMappingsFile, File classMatchesFile) |
| 153 | throws IOException, MappingParseException { | 153 | throws IOException, MappingParseException { |
| 154 | 154 | ||
| 155 | System.out.println("Reading class matches..."); | 155 | System.out.println("Reading class matches..."); |
| 156 | ClassMatches classMatches = MatchesReader.readClasses(classMatchesFile); | 156 | ClassMatches classMatches = MatchesReader.readClasses(classMatchesFile); |
| 157 | System.out.println("Reading mappings..."); | 157 | System.out.println("Reading mappings..."); |
| 158 | Mappings destMappings = new MappingsEnigmaReader().read(destMappingsFile); | 158 | Mappings destMappings = new MappingsEnigmaReader().read(destMappingsFile); |
| 159 | System.out.println("Indexing dest jar..."); | 159 | System.out.println("Indexing dest jar..."); |
| 160 | Deobfuscator destDeobfuscator = new Deobfuscator(destJar); | 160 | Deobfuscator destDeobfuscator = new Deobfuscator(destJar); |
| 161 | 161 | ||
| 162 | System.out.println("Writing matches..."); | 162 | System.out.println("Writing matches..."); |
| 163 | 163 | ||
| 164 | // get the matched and unmatched mappings | 164 | // get the matched and unmatched mappings |
| 165 | MemberMatches<FieldEntry> fieldMatches = MappingsConverter.computeMemberMatches( | 165 | MemberMatches<FieldEntry> fieldMatches = MappingsConverter.computeMemberMatches( |
| 166 | destDeobfuscator, | 166 | destDeobfuscator, |
| 167 | destMappings, | 167 | destMappings, |
| 168 | classMatches, | 168 | classMatches, |
| 169 | MappingsConverter.getFieldDoer() | 169 | MappingsConverter.getFieldDoer() |
| 170 | ); | 170 | ); |
| 171 | 171 | ||
| 172 | MatchesWriter.writeMembers(fieldMatches, memberMatchesFile); | 172 | MatchesWriter.writeMembers(fieldMatches, memberMatchesFile); |
| 173 | System.out.println("Wrote:\n\t" + memberMatchesFile.getAbsolutePath()); | 173 | System.out.println("Wrote:\n\t" + memberMatchesFile.getAbsolutePath()); |
| 174 | } | 174 | } |
| 175 | 175 | ||
| 176 | private static void editFieldMatches(JarFile sourceJar, JarFile destJar, File destMappingsFile, Mappings sourceMappings, File classMatchesFile, final File fieldMatchesFile) | 176 | private static void editFieldMatches(JarFile sourceJar, JarFile destJar, File destMappingsFile, Mappings sourceMappings, File classMatchesFile, final File fieldMatchesFile) |
| 177 | throws IOException, MappingParseException { | 177 | throws IOException, MappingParseException { |
| 178 | 178 | ||
| 179 | System.out.println("Reading matches..."); | 179 | System.out.println("Reading matches..."); |
| 180 | ClassMatches classMatches = MatchesReader.readClasses(classMatchesFile); | 180 | ClassMatches classMatches = MatchesReader.readClasses(classMatchesFile); |
| 181 | MemberMatches<FieldEntry> fieldMatches = MatchesReader.readMembers(fieldMatchesFile); | 181 | MemberMatches<FieldEntry> fieldMatches = MatchesReader.readMembers(fieldMatchesFile); |
| 182 | 182 | ||
| 183 | // prep deobfuscators | 183 | // prep deobfuscators |
| 184 | Deobfuscators deobfuscators = new Deobfuscators(sourceJar, destJar); | 184 | Deobfuscators deobfuscators = new Deobfuscators(sourceJar, destJar); |
| 185 | deobfuscators.source.setMappings(sourceMappings); | 185 | deobfuscators.source.setMappings(sourceMappings); |
| 186 | Mappings destMappings = new MappingsEnigmaReader().read(destMappingsFile); | 186 | Mappings destMappings = new MappingsEnigmaReader().read(destMappingsFile); |
| 187 | MappingsChecker checker = new MappingsChecker(deobfuscators.dest.getJarIndex()); | 187 | MappingsChecker checker = new MappingsChecker(deobfuscators.dest.getJarIndex()); |
| 188 | checker.dropBrokenMappings(destMappings); | 188 | checker.dropBrokenMappings(destMappings); |
| 189 | deobfuscators.dest.setMappings(destMappings); | 189 | deobfuscators.dest.setMappings(destMappings); |
| 190 | 190 | ||
| 191 | new MemberMatchingGui<>(classMatches, fieldMatches, deobfuscators.source, deobfuscators.dest).setSaveListener( | 191 | new MemberMatchingGui<>(classMatches, fieldMatches, deobfuscators.source, deobfuscators.dest).setSaveListener( |
| 192 | matches -> | 192 | matches -> |
| 193 | { | 193 | { |
| 194 | try { | 194 | try { |
| 195 | MatchesWriter.writeMembers(matches, fieldMatchesFile); | 195 | MatchesWriter.writeMembers(matches, fieldMatchesFile); |
| 196 | } catch (IOException ex) { | 196 | } catch (IOException ex) { |
| 197 | throw new Error(ex); | 197 | throw new Error(ex); |
| 198 | } | 198 | } |
| 199 | }); | 199 | }); |
| 200 | } | 200 | } |
| 201 | 201 | ||
| 202 | @SuppressWarnings("unused") | 202 | @SuppressWarnings("unused") |
| 203 | private static void convertMappings(File outMappingsFile, JarFile sourceJar, JarFile destJar, Mappings mappings, File classMatchesFile, File fieldMatchesFile) | 203 | private static void convertMappings(File outMappingsFile, JarFile sourceJar, JarFile destJar, Mappings mappings, File classMatchesFile, File fieldMatchesFile) |
| 204 | throws IOException, MappingConflict { | 204 | throws IOException, MappingConflict { |
| 205 | 205 | ||
| 206 | System.out.println("Reading matches..."); | 206 | System.out.println("Reading matches..."); |
| 207 | ClassMatches classMatches = MatchesReader.readClasses(classMatchesFile); | 207 | ClassMatches classMatches = MatchesReader.readClasses(classMatchesFile); |
| 208 | MemberMatches<FieldEntry> fieldMatches = MatchesReader.readMembers(fieldMatchesFile); | 208 | MemberMatches<FieldEntry> fieldMatches = MatchesReader.readMembers(fieldMatchesFile); |
| 209 | 209 | ||
| 210 | Deobfuscators deobfuscators = new Deobfuscators(sourceJar, destJar); | 210 | Deobfuscators deobfuscators = new Deobfuscators(sourceJar, destJar); |
| 211 | deobfuscators.source.setMappings(mappings); | 211 | deobfuscators.source.setMappings(mappings); |
| 212 | 212 | ||
| 213 | // apply matches | 213 | // apply matches |
| 214 | Mappings newMappings = MappingsConverter.newMappings(classMatches, mappings, deobfuscators.source, deobfuscators.dest); | 214 | Mappings newMappings = MappingsConverter.newMappings(classMatches, mappings, deobfuscators.source, deobfuscators.dest); |
| 215 | MappingsConverter.applyMemberMatches(newMappings, classMatches, fieldMatches, MappingsConverter.getFieldDoer()); | 215 | MappingsConverter.applyMemberMatches(newMappings, classMatches, fieldMatches, MappingsConverter.getFieldDoer()); |
| 216 | 216 | ||
| 217 | // write out the converted mappings | 217 | // write out the converted mappings |
| 218 | 218 | ||
| 219 | new MappingsEnigmaWriter().write(outMappingsFile, newMappings, true); | 219 | new MappingsEnigmaWriter().write(outMappingsFile, newMappings, true); |
| 220 | System.out.println("Wrote converted mappings to:\n\t" + outMappingsFile.getAbsolutePath()); | 220 | System.out.println("Wrote converted mappings to:\n\t" + outMappingsFile.getAbsolutePath()); |
| 221 | } | 221 | } |
| 222 | 222 | ||
| 223 | 223 | private static void computeMethodMatches(File outMappingsFile, JarFile sourceJar, JarFile destJar, Mappings sourceMappings, File classMatchesFile, File fieldMatchesFile, File methodMatchesFile) | |
| 224 | private static void computeMethodMatches(File outMappingsFile, JarFile sourceJar, JarFile destJar, Mappings sourceMappings, File classMatchesFile, File fieldMatchesFile, File methodMatchesFile) | 224 | throws IOException, MappingParseException { |
| 225 | throws IOException, MappingParseException { | 225 | |
| 226 | 226 | System.out.println("Reading class matches..."); | |
| 227 | System.out.println("Reading class matches..."); | 227 | ClassMatches classMatches = MatchesReader.readClasses(classMatchesFile); |
| 228 | ClassMatches classMatches = MatchesReader.readClasses(classMatchesFile); | 228 | System.out.println("Reading dest mappings..."); |
| 229 | System.out.println("Reading dest mappings..."); | 229 | Mappings destMappings = new MappingsEnigmaReader().read(outMappingsFile); |
| 230 | Mappings destMappings = new MappingsEnigmaReader().read(outMappingsFile); | 230 | System.out.println("Indexing dest jar..."); |
| 231 | System.out.println("Indexing dest jar..."); | 231 | Deobfuscator destDeobfuscator = new Deobfuscator(destJar); |
| 232 | Deobfuscator destDeobfuscator = new Deobfuscator(destJar); | 232 | System.out.println("Indexing source jar..."); |
| 233 | System.out.println("Indexing source jar..."); | 233 | Deobfuscator sourceDeobfuscator = new Deobfuscator(sourceJar); |
| 234 | Deobfuscator sourceDeobfuscator = new Deobfuscator(sourceJar); | 234 | |
| 235 | 235 | System.out.println("Writing method matches..."); | |
| 236 | System.out.println("Writing method matches..."); | 236 | |
| 237 | 237 | // get the matched and unmatched mappings | |
| 238 | // get the matched and unmatched mappings | 238 | MemberMatches<BehaviorEntry> methodMatches = MappingsConverter.computeMethodsMatches( |
| 239 | MemberMatches<BehaviorEntry> methodMatches = MappingsConverter.computeMethodsMatches( | 239 | destDeobfuscator, |
| 240 | destDeobfuscator, | 240 | destMappings, |
| 241 | destMappings, | 241 | sourceDeobfuscator, |
| 242 | sourceDeobfuscator, | 242 | sourceMappings, |
| 243 | sourceMappings, | 243 | classMatches, |
| 244 | classMatches, | 244 | MappingsConverter.getMethodDoer() |
| 245 | MappingsConverter.getMethodDoer() | 245 | ); |
| 246 | ); | 246 | |
| 247 | 247 | MatchesWriter.writeMembers(methodMatches, methodMatchesFile); | |
| 248 | MatchesWriter.writeMembers(methodMatches, methodMatchesFile); | 248 | System.out.println("Wrote:\n\t" + methodMatchesFile.getAbsolutePath()); |
| 249 | System.out.println("Wrote:\n\t" + methodMatchesFile.getAbsolutePath()); | 249 | } |
| 250 | } | 250 | |
| 251 | 251 | private static void editMethodMatches(JarFile sourceJar, JarFile destJar, File destMappingsFile, Mappings sourceMappings, File classMatchesFile, final File methodMatchesFile) | |
| 252 | private static void editMethodMatches(JarFile sourceJar, JarFile destJar, File destMappingsFile, Mappings sourceMappings, File classMatchesFile, final File methodMatchesFile) | 252 | throws IOException, MappingParseException { |
| 253 | throws IOException, MappingParseException { | 253 | |
| 254 | 254 | System.out.println("Reading matches..."); | |
| 255 | System.out.println("Reading matches..."); | 255 | ClassMatches classMatches = MatchesReader.readClasses(classMatchesFile); |
| 256 | ClassMatches classMatches = MatchesReader.readClasses(classMatchesFile); | 256 | MemberMatches<BehaviorEntry> methodMatches = MatchesReader.readMembers(methodMatchesFile); |
| 257 | MemberMatches<BehaviorEntry> methodMatches = MatchesReader.readMembers(methodMatchesFile); | 257 | |
| 258 | 258 | // prep deobfuscators | |
| 259 | // prep deobfuscators | 259 | Deobfuscators deobfuscators = new Deobfuscators(sourceJar, destJar); |
| 260 | Deobfuscators deobfuscators = new Deobfuscators(sourceJar, destJar); | 260 | deobfuscators.source.setMappings(sourceMappings); |
| 261 | deobfuscators.source.setMappings(sourceMappings); | 261 | Mappings destMappings = new MappingsEnigmaReader().read(destMappingsFile); |
| 262 | Mappings destMappings = new MappingsEnigmaReader().read(destMappingsFile); | 262 | MappingsChecker checker = new MappingsChecker(deobfuscators.dest.getJarIndex()); |
| 263 | MappingsChecker checker = new MappingsChecker(deobfuscators.dest.getJarIndex()); | 263 | checker.dropBrokenMappings(destMappings); |
| 264 | checker.dropBrokenMappings(destMappings); | 264 | deobfuscators.dest.setMappings(destMappings); |
| 265 | deobfuscators.dest.setMappings(destMappings); | 265 | |
| 266 | 266 | new MemberMatchingGui<>(classMatches, methodMatches, deobfuscators.source, deobfuscators.dest).setSaveListener( | |
| 267 | new MemberMatchingGui<>(classMatches, methodMatches, deobfuscators.source, deobfuscators.dest).setSaveListener( | 267 | matches -> |
| 268 | matches -> | 268 | { |
| 269 | { | 269 | try { |
| 270 | try { | 270 | MatchesWriter.writeMembers(matches, methodMatchesFile); |
| 271 | MatchesWriter.writeMembers(matches, methodMatchesFile); | 271 | } catch (IOException ex) { |
| 272 | } catch (IOException ex) { | 272 | throw new Error(ex); |
| 273 | throw new Error(ex); | 273 | } |
| 274 | } | 274 | }); |
| 275 | }); | 275 | } |
| 276 | } | 276 | |
| 277 | 277 | private static void convertMappings(File outMappingsFile, JarFile sourceJar, JarFile destJar, Mappings mappings, File classMatchesFile, File fieldMatchesFile, File methodMatchesFile) | |
| 278 | private static void convertMappings(File outMappingsFile, JarFile sourceJar, JarFile destJar, Mappings mappings, File classMatchesFile, File fieldMatchesFile, File methodMatchesFile) | 278 | throws IOException, MappingConflict { |
| 279 | throws IOException, MappingConflict { | 279 | |
| 280 | 280 | System.out.println("Reading matches..."); | |
| 281 | System.out.println("Reading matches..."); | 281 | ClassMatches classMatches = MatchesReader.readClasses(classMatchesFile); |
| 282 | ClassMatches classMatches = MatchesReader.readClasses(classMatchesFile); | 282 | MemberMatches<FieldEntry> fieldMatches = MatchesReader.readMembers(fieldMatchesFile); |
| 283 | MemberMatches<FieldEntry> fieldMatches = MatchesReader.readMembers(fieldMatchesFile); | 283 | MemberMatches<BehaviorEntry> methodMatches = MatchesReader.readMembers(methodMatchesFile); |
| 284 | MemberMatches<BehaviorEntry> methodMatches = MatchesReader.readMembers(methodMatchesFile); | 284 | |
| 285 | 285 | Deobfuscators deobfuscators = new Deobfuscators(sourceJar, destJar); | |
| 286 | Deobfuscators deobfuscators = new Deobfuscators(sourceJar, destJar); | 286 | deobfuscators.source.setMappings(mappings); |
| 287 | deobfuscators.source.setMappings(mappings); | 287 | |
| 288 | 288 | // apply matches | |
| 289 | // apply matches | 289 | Mappings newMappings = MappingsConverter.newMappings(classMatches, mappings, deobfuscators.source, deobfuscators.dest); |
| 290 | Mappings newMappings = MappingsConverter.newMappings(classMatches, mappings, deobfuscators.source, deobfuscators.dest); | 290 | MappingsConverter.applyMemberMatches(newMappings, classMatches, fieldMatches, MappingsConverter.getFieldDoer()); |
| 291 | MappingsConverter.applyMemberMatches(newMappings, classMatches, fieldMatches, MappingsConverter.getFieldDoer()); | 291 | MappingsConverter.applyMemberMatches(newMappings, classMatches, methodMatches, MappingsConverter.getMethodDoer()); |
| 292 | MappingsConverter.applyMemberMatches(newMappings, classMatches, methodMatches, MappingsConverter.getMethodDoer()); | 292 | |
| 293 | 293 | // check the final mappings | |
| 294 | // check the final mappings | 294 | MappingsChecker checker = new MappingsChecker(deobfuscators.dest.getJarIndex()); |
| 295 | MappingsChecker checker = new MappingsChecker(deobfuscators.dest.getJarIndex()); | 295 | checker.dropBrokenMappings(newMappings); |
| 296 | checker.dropBrokenMappings(newMappings); | 296 | |
| 297 | 297 | for (java.util.Map.Entry<ClassEntry, ClassMapping> mapping : checker.getDroppedClassMappings().entrySet()) { | |
| 298 | for (java.util.Map.Entry<ClassEntry, ClassMapping> mapping : checker.getDroppedClassMappings().entrySet()) { | 298 | System.out.println("WARNING: Broken class entry " + mapping.getKey() + " (" + mapping.getValue().getDeobfName() + ")"); |
| 299 | System.out.println("WARNING: Broken class entry " + mapping.getKey() + " (" + mapping.getValue().getDeobfName() + ")"); | 299 | } |
| 300 | } | 300 | for (java.util.Map.Entry<ClassEntry, ClassMapping> mapping : checker.getDroppedInnerClassMappings().entrySet()) { |
| 301 | for (java.util.Map.Entry<ClassEntry, ClassMapping> mapping : checker.getDroppedInnerClassMappings().entrySet()) { | 301 | System.out.println("WARNING: Broken inner class entry " + mapping.getKey() + " (" + mapping.getValue().getDeobfName() + ")"); |
| 302 | System.out.println("WARNING: Broken inner class entry " + mapping.getKey() + " (" + mapping.getValue().getDeobfName() + ")"); | 302 | } |
| 303 | } | 303 | for (java.util.Map.Entry<FieldEntry, FieldMapping> mapping : checker.getDroppedFieldMappings().entrySet()) { |
| 304 | for (java.util.Map.Entry<FieldEntry, FieldMapping> mapping : checker.getDroppedFieldMappings().entrySet()) { | 304 | System.out.println("WARNING: Broken field entry " + mapping.getKey() + " (" + mapping.getValue().getDeobfName() + ")"); |
| 305 | System.out.println("WARNING: Broken field entry " + mapping.getKey() + " (" + mapping.getValue().getDeobfName() + ")"); | 305 | } |
| 306 | } | 306 | for (java.util.Map.Entry<BehaviorEntry, MethodMapping> mapping : checker.getDroppedMethodMappings().entrySet()) { |
| 307 | for (java.util.Map.Entry<BehaviorEntry, MethodMapping> mapping : checker.getDroppedMethodMappings().entrySet()) { | 307 | System.out.println("WARNING: Broken behavior entry " + mapping.getKey() + " (" + mapping.getValue().getDeobfName() + ")"); |
| 308 | System.out.println("WARNING: Broken behavior entry " + mapping.getKey() + " (" + mapping.getValue().getDeobfName() + ")"); | 308 | } |
| 309 | } | 309 | |
| 310 | 310 | // write out the converted mappings | |
| 311 | // write out the converted mappings | 311 | new MappingsEnigmaWriter().write(outMappingsFile, newMappings, true); |
| 312 | new MappingsEnigmaWriter().write(outMappingsFile, newMappings, true); | 312 | System.out.println("Wrote converted mappings to:\n\t" + outMappingsFile.getAbsolutePath()); |
| 313 | System.out.println("Wrote converted mappings to:\n\t" + outMappingsFile.getAbsolutePath()); | 313 | } |
| 314 | } | 314 | |
| 315 | 315 | private static class Deobfuscators { | |
| 316 | private static class Deobfuscators { | 316 | |
| 317 | 317 | public Deobfuscator source; | |
| 318 | public Deobfuscator source; | 318 | public Deobfuscator dest; |
| 319 | public Deobfuscator dest; | 319 | |
| 320 | 320 | public Deobfuscators(JarFile sourceJar, JarFile destJar) { | |
| 321 | public Deobfuscators(JarFile sourceJar, JarFile destJar) { | 321 | System.out.println("Indexing source jar..."); |
| 322 | System.out.println("Indexing source jar..."); | 322 | IndexerThread sourceIndexer = new IndexerThread(sourceJar); |
| 323 | IndexerThread sourceIndexer = new IndexerThread(sourceJar); | 323 | sourceIndexer.start(); |
| 324 | sourceIndexer.start(); | 324 | System.out.println("Indexing dest jar..."); |
| 325 | System.out.println("Indexing dest jar..."); | 325 | IndexerThread destIndexer = new IndexerThread(destJar); |
| 326 | IndexerThread destIndexer = new IndexerThread(destJar); | 326 | destIndexer.start(); |
| 327 | destIndexer.start(); | 327 | sourceIndexer.joinOrBail(); |
| 328 | sourceIndexer.joinOrBail(); | 328 | destIndexer.joinOrBail(); |
| 329 | destIndexer.joinOrBail(); | 329 | source = sourceIndexer.deobfuscator; |
| 330 | source = sourceIndexer.deobfuscator; | 330 | dest = destIndexer.deobfuscator; |
| 331 | dest = destIndexer.deobfuscator; | 331 | } |
| 332 | } | 332 | } |
| 333 | } | 333 | |
| 334 | 334 | private static class IndexerThread extends Thread { | |
| 335 | private static class IndexerThread extends Thread { | 335 | |
| 336 | 336 | public Deobfuscator deobfuscator; | |
| 337 | private JarFile jarFile; | 337 | private JarFile jarFile; |
| 338 | public Deobfuscator deobfuscator; | 338 | |
| 339 | 339 | public IndexerThread(JarFile jarFile) { | |
| 340 | public IndexerThread(JarFile jarFile) { | 340 | this.jarFile = jarFile; |
| 341 | this.jarFile = jarFile; | 341 | deobfuscator = null; |
| 342 | deobfuscator = null; | 342 | } |
| 343 | } | 343 | |
| 344 | 344 | public void joinOrBail() { | |
| 345 | public void joinOrBail() { | 345 | try { |
| 346 | try { | 346 | join(); |
| 347 | join(); | 347 | } catch (InterruptedException ex) { |
| 348 | } catch (InterruptedException ex) { | 348 | throw new Error(ex); |
| 349 | throw new Error(ex); | 349 | } |
| 350 | } | 350 | } |
| 351 | } | 351 | |
| 352 | 352 | @Override | |
| 353 | @Override | 353 | public void run() { |
| 354 | public void run() { | 354 | deobfuscator = new Deobfuscator(jarFile); |
| 355 | deobfuscator = new Deobfuscator(jarFile); | 355 | } |
| 356 | } | 356 | } |
| 357 | } | ||
| 358 | } \ No newline at end of file | 357 | } \ No newline at end of file |