diff options
Diffstat (limited to 'src/cuchaz/enigma/ConvertMain.java')
| -rw-r--r-- | src/cuchaz/enigma/ConvertMain.java | 73 |
1 files changed, 2 insertions, 71 deletions
diff --git a/src/cuchaz/enigma/ConvertMain.java b/src/cuchaz/enigma/ConvertMain.java index a5a00e8..a45fb35 100644 --- a/src/cuchaz/enigma/ConvertMain.java +++ b/src/cuchaz/enigma/ConvertMain.java | |||
| @@ -4,12 +4,8 @@ import java.io.File; | |||
| 4 | import java.io.FileReader; | 4 | import java.io.FileReader; |
| 5 | import java.io.FileWriter; | 5 | import java.io.FileWriter; |
| 6 | import java.io.IOException; | 6 | import java.io.IOException; |
| 7 | import java.util.Set; | ||
| 8 | import java.util.jar.JarFile; | 7 | import java.util.jar.JarFile; |
| 9 | 8 | ||
| 10 | import com.google.common.collect.BiMap; | ||
| 11 | import com.google.common.collect.Sets; | ||
| 12 | |||
| 13 | import cuchaz.enigma.convert.ClassMatches; | 9 | import cuchaz.enigma.convert.ClassMatches; |
| 14 | import cuchaz.enigma.convert.FieldMatches; | 10 | import cuchaz.enigma.convert.FieldMatches; |
| 15 | import cuchaz.enigma.convert.MappingsConverter; | 11 | import cuchaz.enigma.convert.MappingsConverter; |
| @@ -17,18 +13,11 @@ import cuchaz.enigma.convert.MatchesReader; | |||
| 17 | import cuchaz.enigma.convert.MatchesWriter; | 13 | import cuchaz.enigma.convert.MatchesWriter; |
| 18 | import cuchaz.enigma.gui.ClassMatchingGui; | 14 | import cuchaz.enigma.gui.ClassMatchingGui; |
| 19 | import cuchaz.enigma.gui.FieldMatchingGui; | 15 | import cuchaz.enigma.gui.FieldMatchingGui; |
| 20 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 21 | import cuchaz.enigma.mapping.ClassMapping; | ||
| 22 | import cuchaz.enigma.mapping.ClassNameReplacer; | ||
| 23 | import cuchaz.enigma.mapping.EntryFactory; | ||
| 24 | import cuchaz.enigma.mapping.FieldEntry; | ||
| 25 | import cuchaz.enigma.mapping.FieldMapping; | ||
| 26 | import cuchaz.enigma.mapping.MappingParseException; | 16 | import cuchaz.enigma.mapping.MappingParseException; |
| 27 | import cuchaz.enigma.mapping.Mappings; | 17 | import cuchaz.enigma.mapping.Mappings; |
| 28 | import cuchaz.enigma.mapping.MappingsChecker; | 18 | import cuchaz.enigma.mapping.MappingsChecker; |
| 29 | import cuchaz.enigma.mapping.MappingsReader; | 19 | import cuchaz.enigma.mapping.MappingsReader; |
| 30 | import cuchaz.enigma.mapping.MappingsWriter; | 20 | import cuchaz.enigma.mapping.MappingsWriter; |
| 31 | import cuchaz.enigma.mapping.Type; | ||
| 32 | 21 | ||
| 33 | 22 | ||
| 34 | public class ConvertMain { | 23 | public class ConvertMain { |
| @@ -63,7 +52,7 @@ public class ConvertMain { | |||
| 63 | 52 | ||
| 64 | private static void computeClassMatches(File classMatchesFile, JarFile sourceJar, JarFile destJar, Mappings mappings) | 53 | private static void computeClassMatches(File classMatchesFile, JarFile sourceJar, JarFile destJar, Mappings mappings) |
| 65 | throws IOException { | 54 | throws IOException { |
| 66 | ClassMatches classMatches = MappingsConverter.computeMatches(sourceJar, destJar, mappings); | 55 | ClassMatches classMatches = MappingsConverter.computeClassMatches(sourceJar, destJar, mappings); |
| 67 | MatchesWriter.writeClasses(classMatches, classMatchesFile); | 56 | MatchesWriter.writeClasses(classMatches, classMatchesFile); |
| 68 | System.out.println("Wrote:\n\t" + classMatchesFile.getAbsolutePath()); | 57 | System.out.println("Wrote:\n\t" + classMatchesFile.getAbsolutePath()); |
| 69 | } | 58 | } |
| @@ -115,70 +104,12 @@ public class ConvertMain { | |||
| 115 | System.out.println("Writing field matches..."); | 104 | System.out.println("Writing field matches..."); |
| 116 | 105 | ||
| 117 | // get the matched and unmatched field mappings | 106 | // get the matched and unmatched field mappings |
| 118 | FieldMatches fieldMatches = new FieldMatches(); | 107 | FieldMatches fieldMatches = MappingsConverter.computeFieldMatches(destDeobfuscator, destMappings, classMatches); |
| 119 | |||
| 120 | // unmatched source fields are easy | ||
| 121 | MappingsChecker checker = new MappingsChecker(destDeobfuscator.getJarIndex()); | ||
| 122 | checker.dropBrokenMappings(destMappings); | ||
| 123 | for (FieldEntry destObfField : checker.getDroppedFieldMappings().keySet()) { | ||
| 124 | FieldEntry srcObfField = translate(destObfField, classMatches.getUniqueMatches().inverse()); | ||
| 125 | fieldMatches.addUnmatchedSourceField(srcObfField); | ||
| 126 | } | ||
| 127 | |||
| 128 | // get matched fields (anything that's left after the checks/drops is matched( | ||
| 129 | for (ClassMapping classMapping : destMappings.classes()) { | ||
| 130 | collectMatchedFields(fieldMatches, classMapping, classMatches); | ||
| 131 | } | ||
| 132 | |||
| 133 | // get unmatched dest fields | ||
| 134 | Set<FieldEntry> unmatchedDestFields = Sets.newHashSet(); | ||
| 135 | for (FieldEntry destFieldEntry : destDeobfuscator.getJarIndex().getObfFieldEntries()) { | ||
| 136 | if (!fieldMatches.isDestMatched(destFieldEntry)) { | ||
| 137 | unmatchedDestFields.add(destFieldEntry); | ||
| 138 | } | ||
| 139 | } | ||
| 140 | fieldMatches.addUnmatchedDestFields(unmatchedDestFields); | ||
| 141 | 108 | ||
| 142 | MatchesWriter.writeFields(fieldMatches, fieldMatchesFile); | 109 | MatchesWriter.writeFields(fieldMatches, fieldMatchesFile); |
| 143 | System.out.println("Wrote:\n\t" + fieldMatchesFile.getAbsolutePath()); | 110 | System.out.println("Wrote:\n\t" + fieldMatchesFile.getAbsolutePath()); |
| 144 | } | 111 | } |
| 145 | 112 | ||
| 146 | private static void collectMatchedFields(FieldMatches fieldMatches, ClassMapping destClassMapping, ClassMatches classMatches) { | ||
| 147 | |||
| 148 | // get the fields for this class | ||
| 149 | for (FieldMapping destFieldMapping : destClassMapping.fields()) { | ||
| 150 | FieldEntry destObfField = EntryFactory.getObfFieldEntry(destClassMapping, destFieldMapping); | ||
| 151 | FieldEntry srcObfField = translate(destObfField, classMatches.getUniqueMatches().inverse()); | ||
| 152 | fieldMatches.addMatch(srcObfField, destObfField); | ||
| 153 | } | ||
| 154 | |||
| 155 | // recurse | ||
| 156 | for (ClassMapping destInnerClassMapping : destClassMapping.innerClasses()) { | ||
| 157 | collectMatchedFields(fieldMatches, destInnerClassMapping, classMatches); | ||
| 158 | } | ||
| 159 | } | ||
| 160 | |||
| 161 | private static FieldEntry translate(FieldEntry in, BiMap<ClassEntry,ClassEntry> map) { | ||
| 162 | return new FieldEntry( | ||
| 163 | map.get(in.getClassEntry()), | ||
| 164 | in.getName(), | ||
| 165 | translate(in.getType(), map) | ||
| 166 | ); | ||
| 167 | } | ||
| 168 | |||
| 169 | private static Type translate(Type type, final BiMap<ClassEntry,ClassEntry> map) { | ||
| 170 | return new Type(type, new ClassNameReplacer() { | ||
| 171 | @Override | ||
| 172 | public String replace(String inClassName) { | ||
| 173 | ClassEntry outClassEntry = map.get(new ClassEntry(inClassName)); | ||
| 174 | if (outClassEntry == null) { | ||
| 175 | return null; | ||
| 176 | } | ||
| 177 | return outClassEntry.getName(); | ||
| 178 | } | ||
| 179 | }); | ||
| 180 | } | ||
| 181 | |||
| 182 | private static void editFieldMatches(JarFile sourceJar, JarFile destJar, File destMappingsFile, Mappings sourceMappings, File classMatchesFile, final File fieldMatchesFile) | 113 | private static void editFieldMatches(JarFile sourceJar, JarFile destJar, File destMappingsFile, Mappings sourceMappings, File classMatchesFile, final File fieldMatchesFile) |
| 183 | throws IOException, MappingParseException { | 114 | throws IOException, MappingParseException { |
| 184 | 115 | ||