summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/ConvertMain.java
diff options
context:
space:
mode:
authorGravatar jeff2015-03-10 00:55:03 -0400
committerGravatar jeff2015-03-10 00:55:03 -0400
commit430df87ba5d855ca29bc53a5765a2862d2209098 (patch)
treeee427f009da8b29e7a66a4b4ce882120f9bb2cbf /src/cuchaz/enigma/ConvertMain.java
parentfield matcher is starting to be useful (diff)
downloadenigma-fork-430df87ba5d855ca29bc53a5765a2862d2209098.tar.gz
enigma-fork-430df87ba5d855ca29bc53a5765a2862d2209098.tar.xz
enigma-fork-430df87ba5d855ca29bc53a5765a2862d2209098.zip
tweaks and improvements to field matching gui
Diffstat (limited to 'src/cuchaz/enigma/ConvertMain.java')
-rw-r--r--src/cuchaz/enigma/ConvertMain.java73
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;
4import java.io.FileReader; 4import java.io.FileReader;
5import java.io.FileWriter; 5import java.io.FileWriter;
6import java.io.IOException; 6import java.io.IOException;
7import java.util.Set;
8import java.util.jar.JarFile; 7import java.util.jar.JarFile;
9 8
10import com.google.common.collect.BiMap;
11import com.google.common.collect.Sets;
12
13import cuchaz.enigma.convert.ClassMatches; 9import cuchaz.enigma.convert.ClassMatches;
14import cuchaz.enigma.convert.FieldMatches; 10import cuchaz.enigma.convert.FieldMatches;
15import cuchaz.enigma.convert.MappingsConverter; 11import cuchaz.enigma.convert.MappingsConverter;
@@ -17,18 +13,11 @@ import cuchaz.enigma.convert.MatchesReader;
17import cuchaz.enigma.convert.MatchesWriter; 13import cuchaz.enigma.convert.MatchesWriter;
18import cuchaz.enigma.gui.ClassMatchingGui; 14import cuchaz.enigma.gui.ClassMatchingGui;
19import cuchaz.enigma.gui.FieldMatchingGui; 15import cuchaz.enigma.gui.FieldMatchingGui;
20import cuchaz.enigma.mapping.ClassEntry;
21import cuchaz.enigma.mapping.ClassMapping;
22import cuchaz.enigma.mapping.ClassNameReplacer;
23import cuchaz.enigma.mapping.EntryFactory;
24import cuchaz.enigma.mapping.FieldEntry;
25import cuchaz.enigma.mapping.FieldMapping;
26import cuchaz.enigma.mapping.MappingParseException; 16import cuchaz.enigma.mapping.MappingParseException;
27import cuchaz.enigma.mapping.Mappings; 17import cuchaz.enigma.mapping.Mappings;
28import cuchaz.enigma.mapping.MappingsChecker; 18import cuchaz.enigma.mapping.MappingsChecker;
29import cuchaz.enigma.mapping.MappingsReader; 19import cuchaz.enigma.mapping.MappingsReader;
30import cuchaz.enigma.mapping.MappingsWriter; 20import cuchaz.enigma.mapping.MappingsWriter;
31import cuchaz.enigma.mapping.Type;
32 21
33 22
34public class ConvertMain { 23public 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