summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/ConvertMain.java
diff options
context:
space:
mode:
authorGravatar jeff2015-03-11 11:03:16 -0400
committerGravatar jeff2015-03-11 11:03:16 -0400
commite33b4003a5c423894e7aef575faff359dd1d33b1 (patch)
tree6fa674b5ff8dbc699a44b6423149ad7e6eaae250 /src/cuchaz/enigma/ConvertMain.java
parentnothing of consequence (diff)
downloadenigma-fork-e33b4003a5c423894e7aef575faff359dd1d33b1.tar.gz
enigma-fork-e33b4003a5c423894e7aef575faff359dd1d33b1.tar.xz
enigma-fork-e33b4003a5c423894e7aef575faff359dd1d33b1.zip
generalized field matching
added method matching
Diffstat (limited to 'src/cuchaz/enigma/ConvertMain.java')
-rw-r--r--src/cuchaz/enigma/ConvertMain.java82
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;
7import java.util.jar.JarFile; 7import java.util.jar.JarFile;
8 8
9import cuchaz.enigma.convert.ClassMatches; 9import cuchaz.enigma.convert.ClassMatches;
10import cuchaz.enigma.convert.FieldMatches;
11import cuchaz.enigma.convert.MappingsConverter; 10import cuchaz.enigma.convert.MappingsConverter;
12import cuchaz.enigma.convert.MatchesReader; 11import cuchaz.enigma.convert.MatchesReader;
13import cuchaz.enigma.convert.MatchesWriter; 12import cuchaz.enigma.convert.MatchesWriter;
13import cuchaz.enigma.convert.MemberMatches;
14import cuchaz.enigma.gui.ClassMatchingGui; 14import cuchaz.enigma.gui.ClassMatchingGui;
15import cuchaz.enigma.gui.FieldMatchingGui; 15import cuchaz.enigma.gui.MemberMatchingGui;
16import cuchaz.enigma.mapping.BehaviorEntry;
17import cuchaz.enigma.mapping.FieldEntry;
16import cuchaz.enigma.mapping.MappingParseException; 18import cuchaz.enigma.mapping.MappingParseException;
17import cuchaz.enigma.mapping.Mappings; 19import cuchaz.enigma.mapping.Mappings;
18import cuchaz.enigma.mapping.MappingsChecker; 20import 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;