diff --git a/pom.xml b/pom.xml index 9c55c3a..14f1da0 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 de.mas jwudtool - 0.4 + 0.5 @@ -79,7 +79,7 @@ com.github.Maschell JNUSLib - 90e83fe + 822cf2d diff --git a/src/main/java/de/mas/jwudtool/Main.java b/src/main/java/de/mas/jwudtool/Main.java index 233bfae..85681bd 100644 --- a/src/main/java/de/mas/jwudtool/Main.java +++ b/src/main/java/de/mas/jwudtool/Main.java @@ -58,7 +58,7 @@ public class Main { } CommandLineParser parser = new DefaultParser(); - CommandLine cmd = null; + CommandLine cmd; try { cmd = parser.parse(options, args); } catch (MissingArgumentException e) { @@ -76,14 +76,18 @@ public class Main { boolean devMode = false; byte[] titlekey = null; - readKey(new File(HOMEPATH + File.separator + "common.key")).ifPresent(key -> Main.commonKey = key); - readKey(new File("common.key")).ifPresent(key -> Main.commonKey = key); - if (cmd.hasOption(OPTION_HELP)) { showHelp(options); return; } + if (cmd.hasOption(OPTION_DEVMODE)) { + devMode = true; + } + + readKey(new File(HOMEPATH + File.separator + (devMode ? "devcommon.key" : "common.key"))).ifPresent(key -> Main.commonKey = key); + readKey(new File("common.key")).ifPresent(key -> Main.commonKey = key); + if (cmd.hasOption(OPTION_IN)) { input = cmd.getOptionValue(OPTION_IN); } @@ -114,10 +118,6 @@ public class Main { overwrite = true; } - if (cmd.hasOption(OPTION_DEVMODE)) { - devMode = true; - } - if (cmd.hasOption(OPTION_COMPRESS)) { boolean verify = true; System.out.println("Compressing: " + input); @@ -171,6 +171,7 @@ public class Main { return; } } + System.out.println("Done!"); } private static void extract(String input, String output, boolean devMode, boolean overwrite, byte[] titlekey, String arg) throws Exception { @@ -183,39 +184,35 @@ public class Main { boolean extractHashes = false; switch (arg) { - case "all": - extractAll = true; - break; - case "content": - extractContent = true; - break; - case "ticket": - extractTicket = true; - break; - case "hashes": - extractHashes = true; - break; - default: - System.out.println("Argument not found:" + arg); - return; + case "all": + extractAll = true; + break; + case "content": + extractContent = true; + break; + case "ticket": + extractTicket = true; + break; + case "hashes": + extractHashes = true; + break; + default: + System.out.println("Argument not found:" + arg); + return; } + assert input != null; File inputFile = new File(input); System.out.println("Extracting: " + inputFile.getAbsolutePath()); - WiiUDisc wudInfo = null; + WiiUDisc wudInfo; if (!devMode) { wudInfo = WUDLoader.load(inputFile.getAbsolutePath(), titlekey); } else { wudInfo = WUDLoader.loadDev(inputFile.getAbsolutePath()); } - if (wudInfo == null) { - System.out.println("Failed to load WUX " + inputFile.getAbsolutePath()); - return; - } - List titles = WUDLoader.getGamePartionsAsNUSTitles(wudInfo, Main.commonKey); System.out.println("Found " + titles.size() + " titles on the Disc."); for (val title : titles) { @@ -248,23 +245,19 @@ public class Main { private static void decryptFile(String input, String output, String regex, boolean devMode, boolean overwrite, byte[] titlekey) throws Exception { if (input == null) { System.out.println("You need to provide an input file"); + return; } File inputFile = new File(input); System.out.println("Decrypting: " + inputFile.getAbsolutePath()); - WiiUDisc wudInfo = null; + WiiUDisc wudInfo; if (!devMode) { wudInfo = WUDLoader.load(inputFile.getAbsolutePath(), titlekey); } else { wudInfo = WUDLoader.loadDev(inputFile.getAbsolutePath()); } - if (wudInfo == null) { - System.out.println("Failed to load Wii U Disc Image " + inputFile.getAbsolutePath()); - return; - } - List partitions = WUDLoader.getPartitonsAsFSTDataProvider(wudInfo, Main.commonKey); System.out.println("Found " + partitions.size() + " titles on the Disc."); @@ -326,7 +319,7 @@ public class Main { } System.out.println("Parsing WUD image."); WUDImage image = new WUDImage(inputImage); - Optional outputFile = Optional.empty(); + Optional outputFile; if (!decompress) { outputFile = WUDService.compressWUDToWUX(image, output, overwrite); if (outputFile.isPresent()) { @@ -358,10 +351,10 @@ public class Main { byte[] key; try { key = Files.readAllBytes(file.toPath()); - if (key != null && key.length == 16) { + if (key.length == 16) { return Optional.of(key); } - } catch (IOException e) { + } catch (IOException ignored) { } } return Optional.empty();