diff options
| author | 2015-02-23 23:29:22 -0500 | |
|---|---|---|
| committer | 2015-02-23 23:29:22 -0500 | |
| commit | 2dc7428e37bdd7a119f53d02ce157675509b0d63 (patch) | |
| tree | 68f409ac726166e427eea3a199eb462130c53ccd /src/cuchaz/enigma/CommandMain.java | |
| parent | make types serializable (diff) | |
| download | enigma-fork-2dc7428e37bdd7a119f53d02ce157675509b0d63.tar.gz enigma-fork-2dc7428e37bdd7a119f53d02ce157675509b0d63.tar.xz enigma-fork-2dc7428e37bdd7a119f53d02ce157675509b0d63.zip | |
lots of work in better handling of inner classes
also working on recognizing unobfuscated and deobfuscated jars
(needed for M3L)
Diffstat (limited to '')
| -rw-r--r-- | src/cuchaz/enigma/CommandMain.java | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/src/cuchaz/enigma/CommandMain.java b/src/cuchaz/enigma/CommandMain.java index 1ec2ad2..0253a92 100644 --- a/src/cuchaz/enigma/CommandMain.java +++ b/src/cuchaz/enigma/CommandMain.java | |||
| @@ -51,7 +51,7 @@ public class CommandMain { | |||
| 51 | try { | 51 | try { |
| 52 | 52 | ||
| 53 | // process the command | 53 | // process the command |
| 54 | String command = getArg(args, 0, "command"); | 54 | String command = getArg(args, 0, "command", true); |
| 55 | if (command.equalsIgnoreCase("deobfuscate")) { | 55 | if (command.equalsIgnoreCase("deobfuscate")) { |
| 56 | deobfuscate(args); | 56 | deobfuscate(args); |
| 57 | } else if(command.equalsIgnoreCase("decompile")) { | 57 | } else if(command.equalsIgnoreCase("decompile")) { |
| @@ -70,46 +70,55 @@ public class CommandMain { | |||
| 70 | System.out.println("Usage:"); | 70 | System.out.println("Usage:"); |
| 71 | System.out.println("\tjava -cp enigma.jar cuchaz.enigma.CommandMain <command>"); | 71 | System.out.println("\tjava -cp enigma.jar cuchaz.enigma.CommandMain <command>"); |
| 72 | System.out.println("\twhere <command> is one of:"); | 72 | System.out.println("\twhere <command> is one of:"); |
| 73 | System.out.println("\t\tdeobfuscate <mappings file> <in jar> <out jar>"); | 73 | System.out.println("\t\tdeobfuscate <in jar> <out jar> [<mappings file>]"); |
| 74 | System.out.println("\t\tdecompile <mappings file> <in jar> <out folder>"); | 74 | System.out.println("\t\tdecompile <in jar> <out folder> [<mappings file>]"); |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | private static void decompile(String[] args) | 77 | private static void decompile(String[] args) |
| 78 | throws Exception { | 78 | throws Exception { |
| 79 | File fileMappings = getReadableFile(getArg(args, 1, "mappings file")); | 79 | File fileJarIn = getReadableFile(getArg(args, 1, "in jar", true)); |
| 80 | File fileJarIn = getReadableFile(getArg(args, 2, "in jar")); | 80 | File fileJarOut = getWritableFolder(getArg(args, 2, "out folder", true)); |
| 81 | File fileJarOut = getWritableFolder(getArg(args, 3, "out folder")); | 81 | File fileMappings = getReadableFile(getArg(args, 3, "mappings file", false)); |
| 82 | Deobfuscator deobfuscator = getDeobfuscator(fileMappings, new JarFile(fileJarIn)); | 82 | Deobfuscator deobfuscator = getDeobfuscator(fileMappings, new JarFile(fileJarIn)); |
| 83 | deobfuscator.writeSources(fileJarOut, new ConsoleProgressListener()); | 83 | deobfuscator.writeSources(fileJarOut, new ConsoleProgressListener()); |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | private static void deobfuscate(String[] args) | 86 | private static void deobfuscate(String[] args) |
| 87 | throws Exception { | 87 | throws Exception { |
| 88 | File fileMappings = getReadableFile(getArg(args, 1, "mappings file")); | 88 | File fileJarIn = getReadableFile(getArg(args, 1, "in jar", true)); |
| 89 | File fileJarIn = getReadableFile(getArg(args, 2, "in jar")); | 89 | File fileJarOut = getWritableFile(getArg(args, 2, "out jar", true)); |
| 90 | File fileJarOut = getWritableFile(getArg(args, 3, "out jar")); | 90 | File fileMappings = getReadableFile(getArg(args, 3, "mappings file", false)); |
| 91 | Deobfuscator deobfuscator = getDeobfuscator(fileMappings, new JarFile(fileJarIn)); | 91 | Deobfuscator deobfuscator = getDeobfuscator(fileMappings, new JarFile(fileJarIn)); |
| 92 | deobfuscator.writeJar(fileJarOut, new ConsoleProgressListener()); | 92 | deobfuscator.writeJar(fileJarOut, new ConsoleProgressListener()); |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | private static Deobfuscator getDeobfuscator(File fileMappings, JarFile jar) | 95 | private static Deobfuscator getDeobfuscator(File fileMappings, JarFile jar) |
| 96 | throws Exception { | 96 | throws Exception { |
| 97 | System.out.println("Reading mappings..."); | ||
| 98 | Mappings mappings = new MappingsReader().read(new FileReader(fileMappings)); | ||
| 99 | System.out.println("Reading jar..."); | 97 | System.out.println("Reading jar..."); |
| 100 | Deobfuscator deobfuscator = new Deobfuscator(jar); | 98 | Deobfuscator deobfuscator = new Deobfuscator(jar); |
| 101 | deobfuscator.setMappings(mappings); | 99 | if (fileMappings != null) { |
| 100 | System.out.println("Reading mappings..."); | ||
| 101 | Mappings mappings = new MappingsReader().read(new FileReader(fileMappings)); | ||
| 102 | deobfuscator.setMappings(mappings); | ||
| 103 | } | ||
| 102 | return deobfuscator; | 104 | return deobfuscator; |
| 103 | } | 105 | } |
| 104 | 106 | ||
| 105 | private static String getArg(String[] args, int i, String name) { | 107 | private static String getArg(String[] args, int i, String name, boolean required) { |
| 106 | if (i >= args.length) { | 108 | if (i >= args.length) { |
| 107 | throw new IllegalArgumentException(name + " is required"); | 109 | if (required) { |
| 110 | throw new IllegalArgumentException(name + " is required"); | ||
| 111 | } else { | ||
| 112 | return null; | ||
| 113 | } | ||
| 108 | } | 114 | } |
| 109 | return args[i]; | 115 | return args[i]; |
| 110 | } | 116 | } |
| 111 | 117 | ||
| 112 | private static File getWritableFile(String path) { | 118 | private static File getWritableFile(String path) { |
| 119 | if (path == null) { | ||
| 120 | return null; | ||
| 121 | } | ||
| 113 | File file = new File(path).getAbsoluteFile(); | 122 | File file = new File(path).getAbsoluteFile(); |
| 114 | File dir = file.getParentFile(); | 123 | File dir = file.getParentFile(); |
| 115 | if (dir == null || !dir.exists()) { | 124 | if (dir == null || !dir.exists()) { |
| @@ -119,6 +128,9 @@ public class CommandMain { | |||
| 119 | } | 128 | } |
| 120 | 129 | ||
| 121 | private static File getWritableFolder(String path) { | 130 | private static File getWritableFolder(String path) { |
| 131 | if (path == null) { | ||
| 132 | return null; | ||
| 133 | } | ||
| 122 | File dir = new File(path).getAbsoluteFile(); | 134 | File dir = new File(path).getAbsoluteFile(); |
| 123 | if (!dir.exists()) { | 135 | if (!dir.exists()) { |
| 124 | throw new IllegalArgumentException("Cannot write to folder: " + dir); | 136 | throw new IllegalArgumentException("Cannot write to folder: " + dir); |
| @@ -127,6 +139,9 @@ public class CommandMain { | |||
| 127 | } | 139 | } |
| 128 | 140 | ||
| 129 | private static File getReadableFile(String path) { | 141 | private static File getReadableFile(String path) { |
| 142 | if (path == null) { | ||
| 143 | return null; | ||
| 144 | } | ||
| 130 | File file = new File(path).getAbsoluteFile(); | 145 | File file = new File(path).getAbsoluteFile(); |
| 131 | if (!file.exists()) { | 146 | if (!file.exists()) { |
| 132 | throw new IllegalArgumentException("Cannot find file: " + file.getAbsolutePath()); | 147 | throw new IllegalArgumentException("Cannot find file: " + file.getAbsolutePath()); |