diff options
| -rw-r--r-- | build.gradle | 4 | ||||
| -rw-r--r-- | src/main/java/cuchaz/enigma/Main.java | 105 | ||||
| -rw-r--r-- | src/main/java/cuchaz/enigma/api/service/ObfuscationTestService.java | 18 |
3 files changed, 98 insertions, 29 deletions
diff --git a/build.gradle b/build.gradle index 26405bd0..ca256805 100644 --- a/build.gradle +++ b/build.gradle | |||
| @@ -19,7 +19,7 @@ apply plugin: 'com.github.johnrengelman.shadow' | |||
| 19 | apply plugin: 'maven' | 19 | apply plugin: 'maven' |
| 20 | 20 | ||
| 21 | group = 'cuchaz' | 21 | group = 'cuchaz' |
| 22 | version = '0.13.2' | 22 | version = '0.14.0' |
| 23 | 23 | ||
| 24 | def generatedSourcesDir = "$buildDir/generated-src" | 24 | def generatedSourcesDir = "$buildDir/generated-src" |
| 25 | 25 | ||
| @@ -91,6 +91,8 @@ dependencies { | |||
| 91 | compile 'org.ow2.asm:asm-tree:7.1' | 91 | compile 'org.ow2.asm:asm-tree:7.1' |
| 92 | compile 'org.ow2.asm:asm-util:7.1' | 92 | compile 'org.ow2.asm:asm-util:7.1' |
| 93 | 93 | ||
| 94 | compile 'net.sf.jopt-simple:jopt-simple:6.0-alpha-3' | ||
| 95 | |||
| 94 | application name: "darcula", version: "1.0.0" | 96 | application name: "darcula", version: "1.0.0" |
| 95 | application 'de.sciss:syntaxpane:1.2.+' | 97 | application 'de.sciss:syntaxpane:1.2.+' |
| 96 | application 'me.xdrop:fuzzywuzzy:1.2.0' | 98 | application 'me.xdrop:fuzzywuzzy:1.2.0' |
diff --git a/src/main/java/cuchaz/enigma/Main.java b/src/main/java/cuchaz/enigma/Main.java index 76a3fff0..a6428405 100644 --- a/src/main/java/cuchaz/enigma/Main.java +++ b/src/main/java/cuchaz/enigma/Main.java | |||
| @@ -12,48 +12,97 @@ | |||
| 12 | package cuchaz.enigma; | 12 | package cuchaz.enigma; |
| 13 | 13 | ||
| 14 | import cuchaz.enigma.gui.Gui; | 14 | import cuchaz.enigma.gui.Gui; |
| 15 | import cuchaz.enigma.gui.GuiController; | ||
| 15 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; | 16 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; |
| 17 | import joptsimple.*; | ||
| 16 | 18 | ||
| 17 | import java.io.File; | 19 | import java.io.IOException; |
| 18 | import java.nio.file.Files; | 20 | import java.nio.file.Files; |
| 19 | import java.nio.file.Path; | 21 | import java.nio.file.Path; |
| 22 | import java.nio.file.Paths; | ||
| 20 | 23 | ||
| 21 | public class Main { | 24 | public class Main { |
| 22 | 25 | ||
| 23 | public static void main(String[] args) throws Exception { | 26 | public static void main(String[] args) throws IOException { |
| 24 | Gui gui = new Gui(); | 27 | OptionParser parser = new OptionParser(); |
| 25 | 28 | ||
| 26 | // parse command-line args | 29 | OptionSpec<Path> jar = parser.accepts("jar", "Jar file to open at startup") |
| 27 | if (args.length >= 1) { | 30 | .withRequiredArg() |
| 28 | gui.getController().openJar(getFile(args[0]).toPath()); | 31 | .withValuesConvertedBy(PathConverter.INSTANCE); |
| 29 | } | 32 | |
| 30 | if (args.length >= 2) { | 33 | OptionSpec<Path> mappings = parser.accepts("mappings", "Mappings file to open at startup") |
| 31 | Path mappingsFile = getFile(args[1]).toPath(); | 34 | .withRequiredArg() |
| 32 | if (Files.isDirectory(mappingsFile)) { | 35 | .withValuesConvertedBy(PathConverter.INSTANCE); |
| 33 | gui.getController().openMappings(MappingFormat.ENIGMA_DIRECTORY, mappingsFile); | 36 | |
| 34 | } else { | 37 | OptionSpec<Path> profile = parser.accepts("profile", "Profile json to apply at startup") |
| 35 | gui.getController().openMappings(MappingFormat.ENIGMA_FILE, mappingsFile); | 38 | .withRequiredArg() |
| 39 | .withValuesConvertedBy(PathConverter.INSTANCE); | ||
| 40 | |||
| 41 | parser.accepts("help", "Displays help information"); | ||
| 42 | |||
| 43 | try { | ||
| 44 | OptionSet options = parser.parse(args); | ||
| 45 | |||
| 46 | if (options.has("help")) { | ||
| 47 | parser.printHelpOn(System.out); | ||
| 48 | return; | ||
| 49 | } | ||
| 50 | |||
| 51 | Gui gui = new Gui(); | ||
| 52 | GuiController controller = gui.getController(); | ||
| 53 | |||
| 54 | if (options.has(jar)) { | ||
| 55 | Path jarPath = options.valueOf(jar); | ||
| 56 | controller.openJar(jarPath); | ||
| 36 | } | 57 | } |
| 37 | } | ||
| 38 | 58 | ||
| 39 | // DEBUG | 59 | if (options.has(mappings)) { |
| 40 | //gui.getController().openDeclaration(new ClassEntry("none/byp")); | 60 | Path mappingsPath = options.valueOf(mappings); |
| 61 | if (Files.isDirectory(mappingsPath)) { | ||
| 62 | controller.openMappings(MappingFormat.ENIGMA_DIRECTORY, mappingsPath); | ||
| 63 | } else { | ||
| 64 | controller.openMappings(MappingFormat.ENIGMA_FILE, mappingsPath); | ||
| 65 | } | ||
| 66 | } | ||
| 67 | } catch (OptionException e) { | ||
| 68 | System.out.println("Invalid arguments: " + e.getMessage()); | ||
| 69 | System.out.println(); | ||
| 70 | parser.printHelpOn(System.out); | ||
| 71 | } | ||
| 41 | } | 72 | } |
| 42 | 73 | ||
| 43 | private static File getFile(String path) { | 74 | private static class PathConverter implements ValueConverter<Path> { |
| 44 | // expand ~ to the home dir | 75 | static final ValueConverter<Path> INSTANCE = new PathConverter(); |
| 45 | if (path.startsWith("~")) { | 76 | |
| 46 | // get the home dir | 77 | PathConverter() { |
| 47 | File dirHome = new File(System.getProperty("user.home")); | 78 | } |
| 48 | 79 | ||
| 49 | // is the path just ~/ or is it ~user/ ? | 80 | @Override |
| 50 | if (path.startsWith("~/")) { | 81 | public Path convert(String path) { |
| 51 | return new File(dirHome, path.substring(2)); | 82 | // expand ~ to the home dir |
| 52 | } else { | 83 | if (path.startsWith("~")) { |
| 53 | return new File(dirHome.getParentFile(), path.substring(1)); | 84 | // get the home dir |
| 85 | Path dirHome = Paths.get(System.getProperty("user.home")); | ||
| 86 | |||
| 87 | // is the path just ~/ or is it ~user/ ? | ||
| 88 | if (path.startsWith("~/")) { | ||
| 89 | return dirHome.resolve(path.substring(2)); | ||
| 90 | } else { | ||
| 91 | return dirHome.getParent().resolve(path.substring(1)); | ||
| 92 | } | ||
| 54 | } | 93 | } |
| 94 | |||
| 95 | return Paths.get(path); | ||
| 55 | } | 96 | } |
| 56 | 97 | ||
| 57 | return new File(path); | 98 | @Override |
| 99 | public Class<? extends Path> valueType() { | ||
| 100 | return Path.class; | ||
| 101 | } | ||
| 102 | |||
| 103 | @Override | ||
| 104 | public String valuePattern() { | ||
| 105 | return "path"; | ||
| 106 | } | ||
| 58 | } | 107 | } |
| 59 | } | 108 | } |
diff --git a/src/main/java/cuchaz/enigma/api/service/ObfuscationTestService.java b/src/main/java/cuchaz/enigma/api/service/ObfuscationTestService.java index af0cf30b..c580f093 100644 --- a/src/main/java/cuchaz/enigma/api/service/ObfuscationTestService.java +++ b/src/main/java/cuchaz/enigma/api/service/ObfuscationTestService.java | |||
| @@ -1,9 +1,27 @@ | |||
| 1 | package cuchaz.enigma.api.service; | 1 | package cuchaz.enigma.api.service; |
| 2 | 2 | ||
| 3 | import com.google.common.base.Strings; | ||
| 4 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | ||
| 3 | import cuchaz.enigma.translation.representation.entry.Entry; | 5 | import cuchaz.enigma.translation.representation.entry.Entry; |
| 4 | 6 | ||
| 5 | public interface ObfuscationTestService extends EnigmaService { | 7 | public interface ObfuscationTestService extends EnigmaService { |
| 6 | EnigmaServiceType<ObfuscationTestService> TYPE = EnigmaServiceType.create("obfuscation_test"); | 8 | EnigmaServiceType<ObfuscationTestService> TYPE = EnigmaServiceType.create("obfuscation_test"); |
| 7 | 9 | ||
| 8 | boolean testDeobfuscated(Entry<?> entry); | 10 | boolean testDeobfuscated(Entry<?> entry); |
| 11 | |||
| 12 | final class Default implements ObfuscationTestService { | ||
| 13 | Default INSTANCE = new Default(); | ||
| 14 | |||
| 15 | Default() { | ||
| 16 | } | ||
| 17 | |||
| 18 | @Override | ||
| 19 | public boolean testDeobfuscated(Entry<?> entry) { | ||
| 20 | if (entry instanceof ClassEntry) { | ||
| 21 | String packageName = ((ClassEntry) entry).getPackageName(); | ||
| 22 | return Strings.isNullOrEmpty(packageName); | ||
| 23 | } | ||
| 24 | return false; | ||
| 25 | } | ||
| 26 | } | ||
| 9 | } | 27 | } |