From d6b2a223a7973941e5e4fb45c8ceec4885891496 Mon Sep 17 00:00:00 2001 From: jeff Date: Mon, 9 Mar 2015 12:53:11 -0400 Subject: starting on field matching gui --- src/cuchaz/enigma/ConvertMain.java | 136 +++++++++++++++++++++++++++++-------- 1 file changed, 108 insertions(+), 28 deletions(-) (limited to 'src/cuchaz/enigma/ConvertMain.java') 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; import java.io.IOException; import java.util.jar.JarFile; +import cuchaz.enigma.convert.ClassMatches; +import cuchaz.enigma.convert.FieldMatches; import cuchaz.enigma.convert.MappingsConverter; -import cuchaz.enigma.convert.Matches; import cuchaz.enigma.convert.MatchesReader; import cuchaz.enigma.convert.MatchesWriter; import cuchaz.enigma.gui.ClassMatchingGui; -import cuchaz.enigma.gui.ClassMatchingGui.SaveListener; +import cuchaz.enigma.gui.FieldMatchingGui; import cuchaz.enigma.mapping.MappingParseException; import cuchaz.enigma.mapping.Mappings; +import cuchaz.enigma.mapping.MappingsChecker; import cuchaz.enigma.mapping.MappingsReader; import cuchaz.enigma.mapping.MappingsWriter; @@ -30,11 +32,13 @@ public class ConvertMain { File inMappingsFile = new File("../Enigma Mappings/1.8.mappings"); File outMappingsFile = new File("../Enigma Mappings/1.8.3.mappings"); Mappings mappings = new MappingsReader().read(new FileReader(inMappingsFile)); - File matchingFile = new File(inMappingsFile.getName() + ".matching"); + File classMatchingFile = new File(inMappingsFile.getName() + ".class.matching"); + File fieldMatchingFile = new File(inMappingsFile.getName() + ".field.matching"); - //computeMatches(matchingFile, sourceJar, destJar, mappings); - editMatches(matchingFile, sourceJar, destJar, mappings); - //convertMappings(outMappingsFile, sourceJar, destJar, mappings, matchingFile); + //computeMatches(classMatchingFile, sourceJar, destJar, mappings); + //editClasssMatches(classMatchingFile, sourceJar, destJar, mappings); + //convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchingFile); + editFieldMatches(sourceJar, destJar, outMappingsFile, mappings, classMatchingFile, fieldMatchingFile); /* TODO // write out the converted mappings @@ -45,28 +49,25 @@ public class ConvertMain { */ } - private static void computeMatches(File matchingFile, JarFile sourceJar, JarFile destJar, Mappings mappings) + private static void computeMatches(File classMatchingFile, JarFile sourceJar, JarFile destJar, Mappings mappings) throws IOException { - Matches matches = MappingsConverter.computeMatches(sourceJar, destJar, mappings); - MatchesWriter.write(matches, matchingFile); - System.out.println("Wrote:\n\t" + matchingFile.getAbsolutePath()); + ClassMatches classMatches = MappingsConverter.computeMatches(sourceJar, destJar, mappings); + MatchesWriter.writeClasses(classMatches, classMatchingFile); + System.out.println("Wrote:\n\t" + classMatchingFile.getAbsolutePath()); } - private static void editMatches(final File matchingFile, JarFile sourceJar, JarFile destJar, Mappings mappings) + private static void editClasssMatches(final File classMatchingFile, JarFile sourceJar, JarFile destJar, Mappings mappings) throws IOException { System.out.println("Reading matches..."); - Matches matches = MatchesReader.read(matchingFile); - System.out.println("Indexing source jar..."); - Deobfuscator sourceDeobfuscator = new Deobfuscator(sourceJar); - sourceDeobfuscator.setMappings(mappings); - System.out.println("Indexing dest jar..."); - Deobfuscator destDeobfuscator = new Deobfuscator(destJar); + ClassMatches classMatches = MatchesReader.readClasses(classMatchingFile); + Deobfuscators deobfuscators = new Deobfuscators(sourceJar, destJar); + deobfuscators.source.setMappings(mappings); System.out.println("Starting GUI..."); - new ClassMatchingGui(matches, sourceDeobfuscator, destDeobfuscator).setSaveListener(new SaveListener() { + new ClassMatchingGui(classMatches, deobfuscators.source, deobfuscators.dest).setSaveListener(new ClassMatchingGui.SaveListener() { @Override - public void save(Matches matches) { + public void save(ClassMatches matches) { try { - MatchesWriter.write(matches, matchingFile); + MatchesWriter.writeClasses(matches, classMatchingFile); } catch (IOException ex) { throw new Error(ex); } @@ -74,21 +75,100 @@ public class ConvertMain { }); } - private static void convertMappings(File outMappingsFile, JarFile sourceJar, JarFile destJar, Mappings mappings, File matchingFile) + private static void convertMappings(File outMappingsFile, JarFile sourceJar, JarFile destJar, Mappings mappings, File classMatchingFile) throws IOException { System.out.println("Reading matches..."); - Matches matches = MatchesReader.read(matchingFile); - System.out.println("Indexing source jar..."); - Deobfuscator sourceDeobfuscator = new Deobfuscator(sourceJar); - sourceDeobfuscator.setMappings(mappings); - System.out.println("Indexing dest jar..."); - Deobfuscator destDeobfuscator = new Deobfuscator(destJar); + ClassMatches classMatches = MatchesReader.readClasses(classMatchingFile); + Deobfuscators deobfuscators = new Deobfuscators(sourceJar, destJar); + deobfuscators.source.setMappings(mappings); - Mappings newMappings = MappingsConverter.newMappings(matches, mappings, sourceDeobfuscator, destDeobfuscator); + Mappings newMappings = MappingsConverter.newMappings(classMatches, mappings, deobfuscators.source, deobfuscators.source); try (FileWriter out = new FileWriter(outMappingsFile)) { new MappingsWriter().write(out, newMappings); } System.out.println("Write converted mappings to: " + outMappingsFile.getAbsolutePath()); } + + private static void editFieldMatches(JarFile sourceJar, JarFile destJar, File destMappingsFile, Mappings sourceMappings, File classMatchingFile, final File fieldMatchingFile) + throws IOException, MappingParseException { + + System.out.println("Reading matches..."); + ClassMatches classMatches = MatchesReader.readClasses(classMatchingFile); + FieldMatches fieldMatches; + if (fieldMatchingFile.exists() /* TEMP */ && false) { + // TODO + //fieldMatches = MatchesReader.readFields(fieldMatchingFile); + } else { + fieldMatches = new FieldMatches(); + } + + // prep deobfuscators + Deobfuscators deobfuscators = new Deobfuscators(sourceJar, destJar); + deobfuscators.source.setMappings(sourceMappings); + Mappings destMappings = new MappingsReader().read(new FileReader(destMappingsFile)); + MappingsChecker checker = new MappingsChecker(deobfuscators.dest.getJarIndex()); + checker.dropBrokenMappings(destMappings); + deobfuscators.dest.setMappings(destMappings); + + new FieldMatchingGui(classMatches, fieldMatches, checker.getDroppedFieldMappings(), deobfuscators.source, deobfuscators.dest).setSaveListener(new FieldMatchingGui.SaveListener() { + @Override + public void save(FieldMatches matches) { + /* TODO + try { + MatchesWriter.writeFields(matches, fieldMatchingFile); + } catch (IOException ex) { + throw new Error(ex); + } + */ + } + }); + } + + private static class Deobfuscators { + + public Deobfuscator source; + public Deobfuscator dest; + + public Deobfuscators(JarFile sourceJar, JarFile destJar) { + System.out.println("Indexing source jar..."); + IndexerThread sourceIndexer = new IndexerThread(sourceJar); + sourceIndexer.start(); + System.out.println("Indexing dest jar..."); + IndexerThread destIndexer = new IndexerThread(destJar); + destIndexer.start(); + sourceIndexer.joinOrBail(); + destIndexer.joinOrBail(); + source = sourceIndexer.deobfuscator; + dest = destIndexer.deobfuscator; + } + } + + private static class IndexerThread extends Thread { + + private JarFile m_jarFile; + public Deobfuscator deobfuscator; + + public IndexerThread(JarFile jarFile) { + m_jarFile = jarFile; + deobfuscator = null; + } + + public void joinOrBail() { + try { + join(); + } catch (InterruptedException ex) { + throw new Error(ex); + } + } + + @Override + public void run() { + try { + deobfuscator = new Deobfuscator(m_jarFile); + } catch (IOException ex) { + throw new Error(ex); + } + } + } } -- cgit v1.2.3