diff --git a/README.md b/README.md index 72bf437..1b1d899 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ Sometimes I add new posts about this project [on my blog page](https://developer * [Pablo Curiel (DarkMatterCore)](https://github.com/DarkMatterCore) * [wolfposd](https://github.com/wolfposd) * [agungrbudiman](https://github.com/agungrbudiman) +* Perfect algorithms and great examples taken from mrdude project [mrdude2478/IPS_Patch_Creator](https://github.com/mrdude2478/IPS_Patch_Creator/) * French by [Stephane Meden (JackFromNice)](https://github.com/JackFromNice) * Italian by [unbranched](https://github.com/unbranched) @@ -63,9 +64,7 @@ Sometimes I add new posts about this project [on my blog page](https://developer ### System requirements -JRE/JDK 8u60 or higher for Windows - -JDK 11 for MacOS and Linux +JDK 11 for macOS and Linux ### Supported Goldleaf versions | Goldleaf version | NS-USBloader version | @@ -130,8 +129,6 @@ Set 'Security & Privacy' settings if needed. ##### Windows: -* [Download and install Java JRE](http://java.com/download/) (8u60 or higher) -* Get this application (JAR file) and double-click on it (alternatively open 'cmd', go to place where jar located and execute via `java -jar thisAppName.jar`) * Once application opens click on 'Gear' icon. * Click 'Download and install drivers' * Install drivers @@ -235,10 +232,10 @@ Handling successful/failed installation is a purpose of the other side applicati #### What is this '-legacy' jar?! -**JAR with NO postfixes** recommended for Windows users, Linux users and MacOS users who're using Mojave or later versions. +**JAR with NO postfixes** recommended for Windows users, Linux users and macOS users who're using Mojave or later versions. -**JAR with '-legacy' postfix** is for MacOS users who're still using OS X releases before (!) Mojave. -(It also works for Linux and for Windows but sometimes it doesn't work for Windows and I don't know why). +**JAR with '-legacy' postfix** is for macOS users who're still using OS X releases before (!) Mojave. +(It also works for Linux and for Windows, but sometimes it doesn't work for Windows and I don't know why). We have this situation because of weird behaviour inside usb4java library used in this application for USB interactions. In '-legacy' it's v1.2.0 and in 'normal' it's v1.3.0 diff --git a/src/main/java/nsusbloader/AppPreferences.java b/src/main/java/nsusbloader/AppPreferences.java index 58fae45..0b54289 100644 --- a/src/main/java/nsusbloader/AppPreferences.java +++ b/src/main/java/nsusbloader/AppPreferences.java @@ -144,4 +144,9 @@ public class AppPreferences { public String getPatchesSaveToLocation(){ return FilesHelper.getRealFolder(preferences.get("patches_saveto", System.getProperty("user.home"))); } public void setPatchesSaveToLocation(String value){ preferences.put("patches_saveto", value); } + + public boolean getPatchesTabInvisible(){return preferences.getBoolean("patches_tab_visible", true); } + public void setPatchesTabInvisible(boolean value){preferences.putBoolean("patches_tab_visible", value);} + public String getPatchOffset(String type, int moduleNumber, int offsetId){ return preferences.get(String.format("%s_%02x_%02x", type, moduleNumber, offsetId), ""); } + public void setPatchOffset(String fullTypeSpecifier, String offset){ preferences.put(fullTypeSpecifier, offset); } } diff --git a/src/main/java/nsusbloader/Controllers/NSLMainController.java b/src/main/java/nsusbloader/Controllers/NSLMainController.java index cfff368..533c450 100644 --- a/src/main/java/nsusbloader/Controllers/NSLMainController.java +++ b/src/main/java/nsusbloader/Controllers/NSLMainController.java @@ -70,9 +70,13 @@ public class NSLMainController implements Initializable { MediatorControl.getInstance().setController(this); - if (AppPreferences.getInstance().getAutoCheckUpdates()){ + AppPreferences preferences = AppPreferences.getInstance(); + + if (preferences.getAutoCheckUpdates()) checkForUpdates(); - } + + if (preferences.getPatchesTabInvisible()) + mainTabPane.getTabs().remove(3); openLastOpenedTab(); } diff --git a/src/main/java/nsusbloader/Controllers/PatchesController.java b/src/main/java/nsusbloader/Controllers/PatchesController.java index 5aeb672..20f1244 100644 --- a/src/main/java/nsusbloader/Controllers/PatchesController.java +++ b/src/main/java/nsusbloader/Controllers/PatchesController.java @@ -24,7 +24,9 @@ import javafx.fxml.Initializable; import javafx.scene.input.DragEvent; import javafx.scene.input.TransferMode; +import java.io.BufferedReader; import java.io.File; +import java.io.FileReader; import java.net.URL; import java.util.List; import java.util.ResourceBundle; @@ -128,7 +130,10 @@ public class PatchesController implements Initializable { List filesDropped = event.getDragboard().getFiles(); for (File file : filesDropped){ if (file.isDirectory()) { - locationFirmwareLbl.setText(file.getAbsolutePath()); + if (file.getName().toLowerCase().contains("atmosphe")) + locationAtmosphereLbl.setText(file.getAbsolutePath()); + else + locationFirmwareLbl.setText(file.getAbsolutePath()); continue; } String fileName = file.getName().toLowerCase(); @@ -137,10 +142,42 @@ public class PatchesController implements Initializable { ! fileName.equals("dev.keys") && ! fileName.equals("title.keys"))) locationKeysLbl.setText(file.getAbsolutePath()); + else if (fileName.equals("offsets.txt")) + setOffsets(file); } event.setDropCompleted(true); event.consume(); } + + private void setOffsets(File fileWithOffsets){ + AppPreferences preferences = AppPreferences.getInstance(); + + try (BufferedReader reader = new BufferedReader(new FileReader(fileWithOffsets))) { + String fileLine; + String[] lineValues; + while ((fileLine = reader.readLine()) != null) { + lineValues = fileLine.trim().split("\\s+?=\\s+?", 2); + if (lineValues.length == 2) { + String[] pointer = lineValues[0].split("_", 3); + if (! pointer[0].equals("ES") && ! pointer[0].equals("FS")) + continue; + if (! pointer[1].matches("^([0-9A-Fa-f]{2})$")) + continue; + if (! pointer[2].matches("^([0-9A-Fa-f]{2})$")) + continue; + if (! lineValues[1].matches("^(([0-9A-Fa-f]{2})|\\.)+?$")) + continue; + preferences.setPatchOffset(lineValues[0], lineValues[1]); + + System.out.println(pointer[0]+"_"+pointer[1]+"_"+pointer[2]+" = "+lineValues[1]); + } + } + } + catch (Exception e){ + e.printStackTrace(); + } + } + @FXML private void selectFirmware(){ DirectoryChooser directoryChooser = new DirectoryChooser(); diff --git a/src/main/java/nsusbloader/Utilities/WindowsDrivers/DriversInstall.java b/src/main/java/nsusbloader/Utilities/WindowsDrivers/DriversInstall.java index 0526134..daa483e 100644 --- a/src/main/java/nsusbloader/Utilities/WindowsDrivers/DriversInstall.java +++ b/src/main/java/nsusbloader/Utilities/WindowsDrivers/DriversInstall.java @@ -32,9 +32,6 @@ import javafx.scene.layout.VBox; import javafx.stage.Stage; import nsusbloader.AppPreferences; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; import java.util.ResourceBundle; public class DriversInstall { diff --git a/src/main/java/nsusbloader/Utilities/patches/es/finders/HeuristicEs1.java b/src/main/java/nsusbloader/Utilities/patches/es/finders/HeuristicEs1.java index 7f84c6f..7130d2e 100644 --- a/src/main/java/nsusbloader/Utilities/patches/es/finders/HeuristicEs1.java +++ b/src/main/java/nsusbloader/Utilities/patches/es/finders/HeuristicEs1.java @@ -19,6 +19,7 @@ package nsusbloader.Utilities.patches.es.finders; import libKonogonka.Converter; +import nsusbloader.AppPreferences; import nsusbloader.Utilities.patches.AHeuristic; import nsusbloader.Utilities.patches.BinToAsmPrinter; import nsusbloader.Utilities.patches.SimplyFind; @@ -26,7 +27,7 @@ import nsusbloader.Utilities.patches.SimplyFind; import java.util.List; class HeuristicEs1 extends AHeuristic { - private static final String PATTERN = "1F90013128.8052"; + private static final String PATTERN = AppPreferences.getInstance().getPatchOffset("ES", 1, 0); private final List findings; private final byte[] where; diff --git a/src/main/java/nsusbloader/Utilities/patches/es/finders/HeuristicEs2.java b/src/main/java/nsusbloader/Utilities/patches/es/finders/HeuristicEs2.java index 365c17f..6ee3ce1 100644 --- a/src/main/java/nsusbloader/Utilities/patches/es/finders/HeuristicEs2.java +++ b/src/main/java/nsusbloader/Utilities/patches/es/finders/HeuristicEs2.java @@ -19,6 +19,7 @@ package nsusbloader.Utilities.patches.es.finders; import libKonogonka.Converter; +import nsusbloader.AppPreferences; import nsusbloader.Utilities.patches.AHeuristic; import nsusbloader.Utilities.patches.BinToAsmPrinter; import nsusbloader.Utilities.patches.SimplyFind; @@ -27,7 +28,7 @@ import java.util.ArrayList; import java.util.List; class HeuristicEs2 extends AHeuristic { - private static final String PATTERN = ".D2.52"; + private static final String PATTERN = AppPreferences.getInstance().getPatchOffset("ES", 2, 0); private List findings; private final byte[] where; diff --git a/src/main/java/nsusbloader/Utilities/patches/es/finders/HeuristicEs3.java b/src/main/java/nsusbloader/Utilities/patches/es/finders/HeuristicEs3.java index 2bde638..ecc8149 100644 --- a/src/main/java/nsusbloader/Utilities/patches/es/finders/HeuristicEs3.java +++ b/src/main/java/nsusbloader/Utilities/patches/es/finders/HeuristicEs3.java @@ -19,6 +19,7 @@ package nsusbloader.Utilities.patches.es.finders; import libKonogonka.Converter; +import nsusbloader.AppPreferences; import nsusbloader.Utilities.patches.AHeuristic; import nsusbloader.Utilities.patches.BinToAsmPrinter; import nsusbloader.Utilities.patches.SimplyFind; @@ -26,8 +27,8 @@ import nsusbloader.Utilities.patches.SimplyFind; import java.util.List; class HeuristicEs3 extends AHeuristic { - private static final String PATTERN0 = "..FF97"; - private static final String PATTERN1 = "......FF97"; // aka "E0230091..FF97"; + private static final String PATTERN0 = AppPreferences.getInstance().getPatchOffset("ES", 3, 0); + private static final String PATTERN1 = AppPreferences.getInstance().getPatchOffset("ES", 3, 1); private final List findings; private final byte[] where; diff --git a/src/main/java/nsusbloader/Utilities/patches/fs/FsIniMaker.java b/src/main/java/nsusbloader/Utilities/patches/fs/FsIniMaker.java index 64551ef..4b4084d 100644 --- a/src/main/java/nsusbloader/Utilities/patches/fs/FsIniMaker.java +++ b/src/main/java/nsusbloader/Utilities/patches/fs/FsIniMaker.java @@ -77,9 +77,9 @@ public class FsIniMaker { private void makeFwVersionInformationNotice(boolean isFat32, byte[] fwVersion){ String fwVersionFormatted = fwVersion[3]+"."+fwVersion[2]+"."+fwVersion[1]+"."+fwVersion[0]; if (isFat32) - firmwareVersionInformationNotice = "\n#FS "+fwVersionFormatted+"\n"; + firmwareVersionInformationNotice = "\n#FS (FAT)"+fwVersionFormatted+"\n"; else - firmwareVersionInformationNotice = "\n#FS "+fwVersionFormatted+"-ExFAT\n"; + firmwareVersionInformationNotice = "\n#FS (ExFAT) "+fwVersionFormatted+"\n"; } private void makeSectionDeclaration(String patchName){ diff --git a/src/main/java/nsusbloader/Utilities/patches/fs/FsPatch.java b/src/main/java/nsusbloader/Utilities/patches/fs/FsPatch.java index 0e49699..cd2b528 100644 --- a/src/main/java/nsusbloader/Utilities/patches/fs/FsPatch.java +++ b/src/main/java/nsusbloader/Utilities/patches/fs/FsPatch.java @@ -88,13 +88,6 @@ public class FsPatch { logPrinter.print(" == Debug information ==\n"+wizard.getDebug(), EMsgType.NULL); } private KIP1Provider getKIP1Provider() throws Exception{ - System.out.println("ncaProvider "+ncaProvider); - System.out.println("CONTENT "+ncaProvider.getNCAContentProvider(0)); - System.out.println("CONTENT "+ncaProvider.getNCAContentProvider(1)); - System.out.println("CONTENT "+ncaProvider.getNCAContentProvider(2)); - System.out.println("CONTENT "+ncaProvider.getNCAContentProvider(3)); - - RomFsProvider romFsProvider = ncaProvider.getNCAContentProvider(0).getRomfs(); FileSystemEntry package2FsEntry = romFsProvider.getRootEntry().getContent() diff --git a/src/main/java/nsusbloader/Utilities/patches/fs/finders/HeuristicFs1.java b/src/main/java/nsusbloader/Utilities/patches/fs/finders/HeuristicFs1.java index db539b4..d5e6f67 100644 --- a/src/main/java/nsusbloader/Utilities/patches/fs/finders/HeuristicFs1.java +++ b/src/main/java/nsusbloader/Utilities/patches/fs/finders/HeuristicFs1.java @@ -19,6 +19,7 @@ package nsusbloader.Utilities.patches.fs.finders; import libKonogonka.Converter; +import nsusbloader.AppPreferences; import nsusbloader.Utilities.patches.AHeuristic; import nsusbloader.Utilities.patches.BinToAsmPrinter; import nsusbloader.Utilities.patches.SimplyFind; @@ -27,7 +28,7 @@ import java.util.ArrayList; import java.util.List; class HeuristicFs1 extends AHeuristic { - private static final String PATTERN = "..0036....1F..71..0054..4839"; // TBZ + private static final String PATTERN = AppPreferences.getInstance().getPatchOffset("FS", 1, 0); // TBZ private final byte[] where; private final List findings; diff --git a/src/main/java/nsusbloader/Utilities/patches/fs/finders/HeuristicFs2.java b/src/main/java/nsusbloader/Utilities/patches/fs/finders/HeuristicFs2.java index 8047cae..bc8f5c8 100644 --- a/src/main/java/nsusbloader/Utilities/patches/fs/finders/HeuristicFs2.java +++ b/src/main/java/nsusbloader/Utilities/patches/fs/finders/HeuristicFs2.java @@ -19,6 +19,7 @@ package nsusbloader.Utilities.patches.fs.finders; import libKonogonka.Converter; +import nsusbloader.AppPreferences; import nsusbloader.Utilities.patches.AHeuristic; import nsusbloader.Utilities.patches.BinToAsmPrinter; import nsusbloader.Utilities.patches.SimplyFind; @@ -27,7 +28,7 @@ import java.util.ArrayList; import java.util.List; class HeuristicFs2 extends AHeuristic { - private static final String PATTERN = "...94081c00121f050071..0054"; // "...94"->BL "081c0012"->AND "1f050071"->CMP "..0054"->B.cond (only '54' is signature!) + private static final String PATTERN = AppPreferences.getInstance().getPatchOffset("FS", 2, 0); private final byte[] where; private final List findings; diff --git a/src/main/java/nsusbloader/cli/CommandLineInterface.java b/src/main/java/nsusbloader/cli/CommandLineInterface.java index d5965c8..461c5f5 100644 --- a/src/main/java/nsusbloader/cli/CommandLineInterface.java +++ b/src/main/java/nsusbloader/cli/CommandLineInterface.java @@ -67,6 +67,11 @@ public class CommandLineInterface { new GoldLeafCli(arguments); return; } + if (cli.hasOption("experimental")){ + final String[] arguments = cli.getOptionValues("experimental"); + new ExperimentalCli(arguments); + return; + } /* if (cli.hasOption("x") || cli.hasOption("nxdt")){ final String[] arguments = cli.getOptionValues("nxdt"); @@ -153,6 +158,12 @@ public class CommandLineInterface { .hasArgs() .argName("...") .build(); + final Option experimentalOption = Option.builder() + .longOpt("experimental") + .desc("Enable testing and experimental functions") + .hasArgs() + .argName("y|n") + .build(); /* nxdumptool */ /* final Option nxdtOption = Option.builder("x") @@ -183,6 +194,7 @@ public class CommandLineInterface { group.addOption(helpOption); group.addOption(tinfoilOption); group.addOption(glOption); + group.addOption(experimentalOption); //group.addOption(nxdtOption); group.addOption(splitOption); group.addOption(mergeOption); diff --git a/src/main/java/nsusbloader/cli/ExperimentalCli.java b/src/main/java/nsusbloader/cli/ExperimentalCli.java new file mode 100644 index 0000000..ebe7ee2 --- /dev/null +++ b/src/main/java/nsusbloader/cli/ExperimentalCli.java @@ -0,0 +1,46 @@ +/* + Copyright 2019-2023 Dmitry Isaenko + + This file is part of NS-USBloader. + + NS-USBloader is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + NS-USBloader is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with NS-USBloader. If not, see . + */ +package nsusbloader.cli; + +import nsusbloader.AppPreferences; + +public class ExperimentalCli { + ExperimentalCli(String[] arguments) throws IncorrectSetupException{ + if (arguments == null || arguments.length == 0) + throw new IncorrectSetupException("No arguments.\nShould be 'y' or 'n'"); + + if (arguments.length > 1) + throw new IncorrectSetupException("Too many arguments.\nShould be 'y' or 'n' only"); + + String arg = arguments[0].toLowerCase().substring(0, 1); + + if (arg.equals("y")) { + AppPreferences.getInstance().setPatchesTabInvisible(false); + System.out.println("Experimental functions enabled"); + return; + } + if (arg.equals("n")) { + AppPreferences.getInstance().setPatchesTabInvisible(true); + System.out.println("Experimental functions disabled"); + return; + } + + throw new IncorrectSetupException("Incorrect arguments.\nCould be 'y' or 'n' only"); + } +} diff --git a/src/main/java/nsusbloader/cli/GoldLeafCli.java b/src/main/java/nsusbloader/cli/GoldLeafCli.java index c9a146f..21e2610 100644 --- a/src/main/java/nsusbloader/cli/GoldLeafCli.java +++ b/src/main/java/nsusbloader/cli/GoldLeafCli.java @@ -34,7 +34,7 @@ public class GoldLeafCli { private int parseFileSince = 1; - public GoldLeafCli(String[] arguments) throws InterruptedException, IncorrectSetupException{ + GoldLeafCli(String[] arguments) throws InterruptedException, IncorrectSetupException{ this.arguments = arguments; checkArguments(); @@ -43,7 +43,7 @@ public class GoldLeafCli { runGoldLeafBackend(); } - public void checkArguments() throws IncorrectSetupException{ + private void checkArguments() throws IncorrectSetupException{ if (arguments == null || arguments.length == 0) { throw new IncorrectSetupException("No arguments.\n" + "Try 'ns-usbloader -g help' for more information."); @@ -83,7 +83,7 @@ public class GoldLeafCli { return builder.toString(); } - public void parseGoldLeafVersion() throws IncorrectSetupException{ + private void parseGoldLeafVersion() throws IncorrectSetupException{ String argument1 = arguments[0]; if (! argument1.startsWith("ver=")) { @@ -107,7 +107,7 @@ public class GoldLeafCli { getGlSupportedVersions()); } - public void parseFilesArguments() throws IncorrectSetupException{ + private void parseFilesArguments() throws IncorrectSetupException{ filesList = new ArrayList<>(); File file; @@ -123,7 +123,7 @@ public class GoldLeafCli { } } - public void runGoldLeafBackend() throws InterruptedException { + private void runGoldLeafBackend() throws InterruptedException { Runnable task = new UsbCommunications(filesList, "GoldLeaf"+goldLeafVersion, filterForNsp); diff --git a/src/main/java/nsusbloader/cli/NxdtCli.java b/src/main/java/nsusbloader/cli/NxdtCli.java index e914988..240e89c 100644 --- a/src/main/java/nsusbloader/cli/NxdtCli.java +++ b/src/main/java/nsusbloader/cli/NxdtCli.java @@ -27,7 +27,7 @@ public class NxdtCli { private final String[] arguments; private String saveTo; - public NxdtCli(String[] arguments) throws InterruptedException, IncorrectSetupException{ + NxdtCli(String[] arguments) throws InterruptedException, IncorrectSetupException{ this.arguments = arguments; parseArgument(); runBackend(); diff --git a/src/main/java/nsusbloader/cli/TinfoilUsbCli.java b/src/main/java/nsusbloader/cli/TinfoilUsbCli.java index ad751f0..07b8cd3 100644 --- a/src/main/java/nsusbloader/cli/TinfoilUsbCli.java +++ b/src/main/java/nsusbloader/cli/TinfoilUsbCli.java @@ -29,7 +29,7 @@ public class TinfoilUsbCli { private final String[] arguments; private List filesList; - public TinfoilUsbCli(String[] arguments) throws InterruptedException, IncorrectSetupException{ + TinfoilUsbCli(String[] arguments) throws InterruptedException, IncorrectSetupException{ this.arguments = arguments; checkArguments(); parseFilesArguments(); diff --git a/src/main/resources/NSLMain.fxml b/src/main/resources/NSLMain.fxml index e096a0f..caf33c2 100644 --- a/src/main/resources/NSLMain.fxml +++ b/src/main/resources/NSLMain.fxml @@ -52,7 +52,7 @@ Steps to roll NXDT functionality back: - + diff --git a/src/main/resources/PatchesTab.fxml b/src/main/resources/PatchesTab.fxml index ee72f6c..6daa977 100644 --- a/src/main/resources/PatchesTab.fxml +++ b/src/main/resources/PatchesTab.fxml @@ -129,8 +129,8 @@ -