diff options
| author | 2016-08-24 01:59:26 +0200 | |
|---|---|---|
| committer | 2016-08-24 01:59:26 +0200 | |
| commit | 6e9934a442394a9d0a81404c7480b8001939d92b (patch) | |
| tree | 28252cd87aae33ccc2da9f7c83dcf63db2f45578 /src | |
| parent | Revert Main.java (diff) | |
| download | enigma-6e9934a442394a9d0a81404c7480b8001939d92b.tar.gz enigma-6e9934a442394a9d0a81404c7480b8001939d92b.tar.xz enigma-6e9934a442394a9d0a81404c7480b8001939d92b.zip | |
Add mapping converter to command line system
Diffstat (limited to 'src')
4 files changed, 46 insertions, 7 deletions
diff --git a/src/main/java/cuchaz/enigma/CommandMain.java b/src/main/java/cuchaz/enigma/CommandMain.java index 06784584..54f2707b 100644 --- a/src/main/java/cuchaz/enigma/CommandMain.java +++ b/src/main/java/cuchaz/enigma/CommandMain.java | |||
| @@ -65,7 +65,10 @@ public class CommandMain { | |||
| 65 | protectify(args); | 65 | protectify(args); |
| 66 | } else if (command.equalsIgnoreCase("publify")) { | 66 | } else if (command.equalsIgnoreCase("publify")) { |
| 67 | publify(args); | 67 | publify(args); |
| 68 | } else { | 68 | } else if (command.equalsIgnoreCase("convertmappings")) { |
| 69 | convertMappings(args); | ||
| 70 | } | ||
| 71 | else { | ||
| 69 | throw new IllegalArgumentException("Command not recognized: " + command); | 72 | throw new IllegalArgumentException("Command not recognized: " + command); |
| 70 | } | 73 | } |
| 71 | } catch (IllegalArgumentException ex) { | 74 | } catch (IllegalArgumentException ex) { |
| @@ -82,6 +85,8 @@ public class CommandMain { | |||
| 82 | System.out.println("\t\tdeobfuscate <in jar> <out jar> [<mappings file>]"); | 85 | System.out.println("\t\tdeobfuscate <in jar> <out jar> [<mappings file>]"); |
| 83 | System.out.println("\t\tdecompile <in jar> <out folder> [<mappings file>]"); | 86 | System.out.println("\t\tdecompile <in jar> <out folder> [<mappings file>]"); |
| 84 | System.out.println("\t\tprotectify <in jar> <out jar>"); | 87 | System.out.println("\t\tprotectify <in jar> <out jar>"); |
| 88 | System.out.println("\t\tpublify <in jar> <out jar>"); | ||
| 89 | System.out.println("\t\tconvertmappings <enigma mappings> <converted mappings> <ENIGMA_FILE|ENIGMA_DIRECTORY|SRG_FILE>"); | ||
| 85 | } | 90 | } |
| 86 | 91 | ||
| 87 | private static void decompile(String[] args) throws Exception { | 92 | private static void decompile(String[] args) throws Exception { |
| @@ -125,6 +130,27 @@ public class CommandMain { | |||
| 125 | return deobfuscator; | 130 | return deobfuscator; |
| 126 | } | 131 | } |
| 127 | 132 | ||
| 133 | private static void convertMappings(String[] args) throws Exception { | ||
| 134 | File fileMappings = getReadableFile(getArg(args, 1, "enigma mapping", true)); | ||
| 135 | File result = getWritableFile(getArg(args, 2, "enigma mapping", true)); | ||
| 136 | String name = getArg(args, 3, "format type", true); | ||
| 137 | Mappings.FormatType formatType = Mappings.FormatType.valueOf(name.toUpperCase()); | ||
| 138 | if (formatType == null) | ||
| 139 | throw new IllegalArgumentException(name + "is not a valid mapping format!"); | ||
| 140 | System.out.println("Reading mappings..."); | ||
| 141 | Mappings mappings = new MappingsEnigmaReader().read(fileMappings); | ||
| 142 | System.out.println("Saving new mappings..."); | ||
| 143 | switch (formatType) | ||
| 144 | { | ||
| 145 | case SRG_FILE: | ||
| 146 | mappings.saveSRGMappings(result); | ||
| 147 | break; | ||
| 148 | default: | ||
| 149 | mappings.saveEnigmaMappings(result, Mappings.FormatType.ENIGMA_FILE != formatType); | ||
| 150 | break; | ||
| 151 | } | ||
| 152 | } | ||
| 153 | |||
| 128 | private static String getArg(String[] args, int i, String name, boolean required) { | 154 | private static String getArg(String[] args, int i, String name, boolean required) { |
| 129 | if (i >= args.length) { | 155 | if (i >= args.length) { |
| 130 | if (required) { | 156 | if (required) { |
diff --git a/src/main/java/cuchaz/enigma/gui/GuiController.java b/src/main/java/cuchaz/enigma/gui/GuiController.java index 4d428ac5..d6c170bd 100644 --- a/src/main/java/cuchaz/enigma/gui/GuiController.java +++ b/src/main/java/cuchaz/enigma/gui/GuiController.java | |||
| @@ -84,12 +84,12 @@ public class GuiController { | |||
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | public void saveEnigmaMappings(File file, boolean isDirectoryFormat) throws IOException { | 86 | public void saveEnigmaMappings(File file, boolean isDirectoryFormat) throws IOException { |
| 87 | new MappingsEnigmaWriter().write(file, this.deobfuscator.getMappings(), isDirectoryFormat); | 87 | this.deobfuscator.getMappings().saveEnigmaMappings(file, isDirectoryFormat); |
| 88 | this.isDirty = false; | 88 | this.isDirty = false; |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | public void saveSRGMappings(File file) throws IOException { | 91 | public void saveSRGMappings(File file) throws IOException { |
| 92 | new MappingsSRGWriter().write(file, this.deobfuscator); | 92 | this.deobfuscator.getMappings().saveSRGMappings(file); |
| 93 | this.isDirty = false; | 93 | this.isDirty = false; |
| 94 | } | 94 | } |
| 95 | 95 | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/Mappings.java b/src/main/java/cuchaz/enigma/mapping/Mappings.java index 171ddf16..47c42324 100644 --- a/src/main/java/cuchaz/enigma/mapping/Mappings.java +++ b/src/main/java/cuchaz/enigma/mapping/Mappings.java | |||
| @@ -13,6 +13,8 @@ package cuchaz.enigma.mapping; | |||
| 13 | import com.google.common.collect.Lists; | 13 | import com.google.common.collect.Lists; |
| 14 | import com.google.common.collect.Maps; | 14 | import com.google.common.collect.Maps; |
| 15 | 15 | ||
| 16 | import java.io.File; | ||
| 17 | import java.io.IOException; | ||
| 16 | import java.util.ArrayList; | 18 | import java.util.ArrayList; |
| 17 | import java.util.Collection; | 19 | import java.util.Collection; |
| 18 | import java.util.List; | 20 | import java.util.List; |
| @@ -202,6 +204,16 @@ public class Mappings { | |||
| 202 | return originMapping; | 204 | return originMapping; |
| 203 | } | 205 | } |
| 204 | 206 | ||
| 207 | public void saveEnigmaMappings(File file, boolean isDirectoryFormat) throws IOException | ||
| 208 | { | ||
| 209 | new MappingsEnigmaWriter().write(file, this, isDirectoryFormat); | ||
| 210 | } | ||
| 211 | |||
| 212 | public void saveSRGMappings(File file) throws IOException | ||
| 213 | { | ||
| 214 | new MappingsSRGWriter().write(file, this); | ||
| 215 | } | ||
| 216 | |||
| 205 | public enum FormatType | 217 | public enum FormatType |
| 206 | { | 218 | { |
| 207 | ENIGMA_FILE, ENIGMA_DIRECTORY, SRG_FILE | 219 | ENIGMA_FILE, ENIGMA_DIRECTORY, SRG_FILE |
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsSRGWriter.java b/src/main/java/cuchaz/enigma/mapping/MappingsSRGWriter.java index a05b9158..cede1c2e 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsSRGWriter.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsSRGWriter.java | |||
| @@ -2,6 +2,7 @@ package cuchaz.enigma.mapping; | |||
| 2 | 2 | ||
| 3 | import com.google.common.base.Charsets; | 3 | import com.google.common.base.Charsets; |
| 4 | import cuchaz.enigma.Deobfuscator; | 4 | import cuchaz.enigma.Deobfuscator; |
| 5 | import cuchaz.enigma.analysis.TranslationIndex; | ||
| 5 | 6 | ||
| 6 | import java.io.*; | 7 | import java.io.*; |
| 7 | import java.util.ArrayList; | 8 | import java.util.ArrayList; |
| @@ -13,13 +14,13 @@ import java.util.List; | |||
| 13 | */ | 14 | */ |
| 14 | public class MappingsSRGWriter { | 15 | public class MappingsSRGWriter { |
| 15 | 16 | ||
| 16 | public void write(File file, Deobfuscator deobfuscator) throws IOException { | 17 | public void write(File file, Mappings mappings) throws IOException { |
| 17 | if(file.exists()){ | 18 | if(file.exists()){ |
| 18 | file.delete(); | 19 | file.delete(); |
| 19 | } | 20 | } |
| 20 | file.createNewFile(); | 21 | file.createNewFile(); |
| 21 | 22 | ||
| 22 | Mappings mappings = deobfuscator.getMappings(); | 23 | TranslationIndex index = new TranslationIndex(); |
| 23 | 24 | ||
| 24 | PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), Charsets.UTF_8)); | 25 | PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), Charsets.UTF_8)); |
| 25 | List<String> fieldMappings = new ArrayList<>(); | 26 | List<String> fieldMappings = new ArrayList<>(); |
| @@ -43,7 +44,7 @@ public class MappingsSRGWriter { | |||
| 43 | } | 44 | } |
| 44 | 45 | ||
| 45 | for (MethodMapping methodMapping : sorted(innerClassMapping.methods())) { | 46 | for (MethodMapping methodMapping : sorted(innerClassMapping.methods())) { |
| 46 | methodMappings.add("MD: " + innerClassName + "/" + methodMapping.getObfName() + " " + methodMapping.getObfSignature().toString().replace("none/", "") + " " + innerDebofClassName + "/" + methodMapping.getDeobfName() + " " + deobfuscator.getTranslator(TranslationDirection.Deobfuscating).translateSignature(methodMapping.getObfSignature())); | 47 | methodMappings.add("MD: " + innerClassName + "/" + methodMapping.getObfName() + " " + methodMapping.getObfSignature().toString().replace("none/", "") + " " + innerDebofClassName + "/" + methodMapping.getDeobfName() + " " + mappings.getTranslator(TranslationDirection.Deobfuscating, index).translateSignature(methodMapping.getObfSignature())); |
| 47 | } | 48 | } |
| 48 | } | 49 | } |
| 49 | 50 | ||
| @@ -52,7 +53,7 @@ public class MappingsSRGWriter { | |||
| 52 | } | 53 | } |
| 53 | 54 | ||
| 54 | for (MethodMapping methodMapping : sorted(classMapping.methods())) { | 55 | for (MethodMapping methodMapping : sorted(classMapping.methods())) { |
| 55 | methodMappings.add("MD: " + classMapping.getObfFullName().replace("none/", "") + "/" + methodMapping.getObfName() + " " + methodMapping.getObfSignature().toString().replace("none/", "") + " " + classMapping.getDeobfName() + "/" + methodMapping.getDeobfName() + " " + deobfuscator.getTranslator(TranslationDirection.Deobfuscating).translateSignature(methodMapping.getObfSignature())); | 56 | methodMappings.add("MD: " + classMapping.getObfFullName().replace("none/", "") + "/" + methodMapping.getObfName() + " " + methodMapping.getObfSignature().toString().replace("none/", "") + " " + classMapping.getDeobfName() + "/" + methodMapping.getDeobfName() + " " + mappings.getTranslator(TranslationDirection.Deobfuscating, index).translateSignature(methodMapping.getObfSignature())); |
| 56 | } | 57 | } |
| 57 | } | 58 | } |
| 58 | for(String fd : fieldMappings){ | 59 | for(String fd : fieldMappings){ |