Compare commits
	
		
			2 commits
		
	
	
		
			8348c9f2ab
			...
			66e7338fa5
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
							 | 
						66e7338fa5 | ||
| 
							 | 
						fa236cb1ad | 
					 9 changed files with 244 additions and 9 deletions
				
			
		
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,2 @@
 | 
			
		|||
offsets.txt
 | 
			
		||||
environment.txt
 | 
			
		||||
| 
						 | 
				
			
			@ -29,7 +29,7 @@ public class AppPreferences {
 | 
			
		|||
 | 
			
		||||
    private final Preferences preferences;
 | 
			
		||||
    private final Locale locale;
 | 
			
		||||
    public static final String[] goldleafSupportedVersions = {"v0.5", "v0.7.x", "v0.8-0.9", "v0.10"};
 | 
			
		||||
    public static final String[] GOLDLEAF_SUPPORTED_VERSIONS = {"v0.5", "v0.7.x", "v0.8-0.9", "v0.10+"};
 | 
			
		||||
    private static final Font DEFAULT_FONT = Font.getDefault();
 | 
			
		||||
 | 
			
		||||
    private AppPreferences(){
 | 
			
		||||
| 
						 | 
				
			
			@ -42,13 +42,13 @@ public class AppPreferences {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    public String getTheme(){
 | 
			
		||||
        String theme = preferences.get("THEME", "/res/app_dark.css");           // Don't let user to change settings manually
 | 
			
		||||
        String theme = preferences.get("THEME", "/res/app_dark.css");           // Don't let user change settings manually
 | 
			
		||||
        if (!theme.matches("(^/res/app_dark.css$)|(^/res/app_light.css$)"))
 | 
			
		||||
            theme = "/res/app_dark.css";
 | 
			
		||||
        return theme;
 | 
			
		||||
    }
 | 
			
		||||
    public int getProtocol(){
 | 
			
		||||
        int protocolIndex = preferences.getInt("protocol_index", 0);           // Don't let user to change settings manually
 | 
			
		||||
        int protocolIndex = preferences.getInt("protocol_index", 0);           // Don't let user change settings manually
 | 
			
		||||
        if (protocolIndex < 0 || protocolIndex > 1)
 | 
			
		||||
            protocolIndex = 0;
 | 
			
		||||
        return protocolIndex;
 | 
			
		||||
| 
						 | 
				
			
			@ -56,7 +56,7 @@ public class AppPreferences {
 | 
			
		|||
    public void setProtocol(int protocolIndex){ preferences.putInt("protocol_index", protocolIndex); }
 | 
			
		||||
 | 
			
		||||
    public String getNetUsb(){
 | 
			
		||||
        String netUsb = preferences.get("NETUSB", "USB");           // Don't let user to change settings manually
 | 
			
		||||
        String netUsb = preferences.get("NETUSB", "USB");           // Don't let user change settings manually
 | 
			
		||||
        if (!netUsb.matches("(^USB$)|(^NET$)"))
 | 
			
		||||
            netUsb = "USB";
 | 
			
		||||
        return netUsb;
 | 
			
		||||
| 
						 | 
				
			
			@ -120,7 +120,7 @@ public class AppPreferences {
 | 
			
		|||
    public void setNspFileFilterGL(boolean prop){preferences.putBoolean("GL_NSP_FILTER", prop);}
 | 
			
		||||
 | 
			
		||||
    public int getGlVersion(){
 | 
			
		||||
        return preferences.getInt("gl_ver", goldleafSupportedVersions.length - 1);
 | 
			
		||||
        return preferences.getInt("gl_ver", GOLDLEAF_SUPPORTED_VERSIONS.length - 1);
 | 
			
		||||
    }
 | 
			
		||||
    public void setGlVersion(int version){ preferences.putInt("gl_ver", version);}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -38,7 +38,7 @@ public class SettingsBlockGoldleafController implements Initializable {
 | 
			
		|||
        final AppPreferences preferences = AppPreferences.getInstance();
 | 
			
		||||
 | 
			
		||||
        nspFilesFilterForGLCB.setSelected(preferences.getNspFileFilterGL());
 | 
			
		||||
        glVersionChoiceBox.getItems().addAll(AppPreferences.goldleafSupportedVersions);
 | 
			
		||||
        glVersionChoiceBox.getItems().addAll(AppPreferences.GOLDLEAF_SUPPORTED_VERSIONS);
 | 
			
		||||
 | 
			
		||||
        glVersionChoiceBox.getSelectionModel().select(preferences.getGlVersion());
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -75,7 +75,7 @@ public class GoldLeafCli {
 | 
			
		|||
    private String getGlSupportedVersions(){
 | 
			
		||||
        StringBuilder builder = new StringBuilder("Supported versions: \n");
 | 
			
		||||
 | 
			
		||||
        for (String a : AppPreferences.goldleafSupportedVersions){
 | 
			
		||||
        for (String a : AppPreferences.GOLDLEAF_SUPPORTED_VERSIONS){
 | 
			
		||||
            builder.append("\t");
 | 
			
		||||
            builder.append(a);
 | 
			
		||||
            builder.append("\n");
 | 
			
		||||
| 
						 | 
				
			
			@ -98,7 +98,7 @@ public class GoldLeafCli {
 | 
			
		|||
                    "Try 'ns-usbloader -g help' for more information.");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        for (String version : AppPreferences.goldleafSupportedVersions){
 | 
			
		||||
        for (String version : AppPreferences.GOLDLEAF_SUPPORTED_VERSIONS){
 | 
			
		||||
            if (version.equals(goldLeafVersion))
 | 
			
		||||
                return;
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -66,7 +66,7 @@ public class UsbCommunications extends CancellableRunnable {
 | 
			
		|||
            case "TinFoil":
 | 
			
		||||
                module = new TinFoil(handler, nspMap, this, logPrinter);
 | 
			
		||||
                break;
 | 
			
		||||
            case "GoldLeafv0.10":
 | 
			
		||||
            case "GoldLeafv0.10+":
 | 
			
		||||
                module = new GoldLeaf_010(handler, nspMap, this, logPrinter, nspFilterForGl);
 | 
			
		||||
                break;
 | 
			
		||||
            case "GoldLeafv0.8-0.9":
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										84
									
								
								src/test/java/integration/Environment.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										84
									
								
								src/test/java/integration/Environment.java
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,84 @@
 | 
			
		|||
/* Copyright WTFPL */
 | 
			
		||||
package integration;
 | 
			
		||||
 | 
			
		||||
import java.io.BufferedReader;
 | 
			
		||||
import java.io.FileReader;
 | 
			
		||||
import java.io.FileWriter;
 | 
			
		||||
import java.nio.file.Files;
 | 
			
		||||
import java.nio.file.Path;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
 | 
			
		||||
public class Environment {
 | 
			
		||||
    public final String CONTAINER = "environment.txt";
 | 
			
		||||
 | 
			
		||||
    private String atmosphere;
 | 
			
		||||
    private String prodkeys;
 | 
			
		||||
    private String firmwares;
 | 
			
		||||
    private String saveTo;
 | 
			
		||||
 | 
			
		||||
    public Environment() throws Exception{
 | 
			
		||||
        if (Files.notExists(Path.of(CONTAINER))) {
 | 
			
		||||
            boolean createdTemplate = createTemplate();
 | 
			
		||||
            throw new Exception("'environment.txt' not found\n" +
 | 
			
		||||
                    "Please "+(createdTemplate?"":"create and ") +
 | 
			
		||||
                    "set values in file");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        read();
 | 
			
		||||
 | 
			
		||||
        if (isNotValid())
 | 
			
		||||
            throw new Exception("'environment.txt' doesn't contain valid data\n");
 | 
			
		||||
    }
 | 
			
		||||
    private void read() throws Exception{
 | 
			
		||||
        HashMap<String, String> rawKeySet = new HashMap<>();
 | 
			
		||||
        try (BufferedReader br = new BufferedReader(new FileReader(CONTAINER))) {
 | 
			
		||||
            String fileLine;
 | 
			
		||||
            String[] keyValue;
 | 
			
		||||
            while ((fileLine = br.readLine()) != null) {
 | 
			
		||||
                keyValue = fileLine.trim().split("\\s+?=\\s+?", 2);
 | 
			
		||||
                if (keyValue.length == 2)
 | 
			
		||||
                    rawKeySet.put(keyValue[0], keyValue[1]);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        atmosphere = rawKeySet.get("ATMOSPHERE");
 | 
			
		||||
        prodkeys = rawKeySet.get("PRODKEYS");
 | 
			
		||||
        firmwares = rawKeySet.get("NS_GLOBAL_FIRMWARES");
 | 
			
		||||
        saveTo = rawKeySet.get("SAVE_TO");
 | 
			
		||||
    }
 | 
			
		||||
    private boolean isNotValid(){
 | 
			
		||||
        return atmosphere == null || atmosphere.isBlank() ||
 | 
			
		||||
                prodkeys == null || prodkeys.isBlank() ||
 | 
			
		||||
                firmwares == null || firmwares.isBlank();
 | 
			
		||||
    }
 | 
			
		||||
    private boolean createTemplate(){
 | 
			
		||||
        try(FileWriter writer = new FileWriter(CONTAINER)){
 | 
			
		||||
            writer.write(
 | 
			
		||||
                    "ATMOSPHERE = \n" +
 | 
			
		||||
                    "PRODKEYS = \n" +
 | 
			
		||||
                    "NS_GLOBAL_FIRMWARES = \n" +
 | 
			
		||||
                    "SAVE_TO = /tmp");
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception e){
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getAtmosphereLocation() {
 | 
			
		||||
        return atmosphere;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getProdkeysLocation() {
 | 
			
		||||
        return prodkeys;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getFirmwaresLocation() {
 | 
			
		||||
        return firmwares;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getSaveToLocation() {
 | 
			
		||||
        return saveTo;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										54
									
								
								src/test/java/integration/EsIntegrationTest.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								src/test/java/integration/EsIntegrationTest.java
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,54 @@
 | 
			
		|||
/* Copyright WTFPL */
 | 
			
		||||
package integration;
 | 
			
		||||
 | 
			
		||||
import nsusbloader.NSLMain;
 | 
			
		||||
import nsusbloader.Utilities.patches.es.EsPatchMaker;
 | 
			
		||||
import org.junit.jupiter.api.*;
 | 
			
		||||
 | 
			
		||||
import java.io.File;
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
 | 
			
		||||
public class EsIntegrationTest {
 | 
			
		||||
    static String pathToFirmware;
 | 
			
		||||
    static String pathToFirmwares;
 | 
			
		||||
    static String pathToKeysFile;
 | 
			
		||||
    static String saveTo;
 | 
			
		||||
 | 
			
		||||
    @BeforeAll
 | 
			
		||||
    static void init() throws Exception{
 | 
			
		||||
        NSLMain.isCli = true;
 | 
			
		||||
        Environment environment = new Environment();
 | 
			
		||||
        pathToKeysFile = environment.getProdkeysLocation();
 | 
			
		||||
        saveTo = environment.getSaveToLocation() + File.separator + "ES_LPR";
 | 
			
		||||
        pathToFirmwares = environment.getFirmwaresLocation();
 | 
			
		||||
        pathToFirmware = pathToFirmware + File.separator + "Firmware 14.1.0";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Disabled
 | 
			
		||||
    @DisplayName("ES Integration validation - everything")
 | 
			
		||||
    @Test
 | 
			
		||||
    void makeEss() throws Exception{
 | 
			
		||||
        File[] fwDirs = new File(pathToFirmwares).listFiles((file, s) -> {
 | 
			
		||||
            return s.matches("^Firmware (9\\.|[0-9][0-9]\\.).*");
 | 
			
		||||
            //return s.matches("^Firmware 10.0.1.*");
 | 
			
		||||
        });
 | 
			
		||||
        assert fwDirs != null;
 | 
			
		||||
        Arrays.sort(fwDirs);
 | 
			
		||||
        for (File dir : fwDirs){
 | 
			
		||||
            EsPatchMaker esPatchMaker = new EsPatchMaker(dir.getAbsolutePath(), pathToKeysFile, saveTo);
 | 
			
		||||
            Thread workThread = new Thread(esPatchMaker);
 | 
			
		||||
            workThread.start();
 | 
			
		||||
            workThread.join();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Disabled
 | 
			
		||||
    @DisplayName("ES Integration validation - one particular firmware")
 | 
			
		||||
    @Test
 | 
			
		||||
    void makeEs() throws Exception{
 | 
			
		||||
        EsPatchMaker esPatchMaker = new EsPatchMaker(pathToFirmware, pathToKeysFile, saveTo);
 | 
			
		||||
        Thread workThread = new Thread(esPatchMaker);
 | 
			
		||||
        workThread.start();
 | 
			
		||||
        workThread.join();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										60
									
								
								src/test/java/integration/FsIntegrationTest.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								src/test/java/integration/FsIntegrationTest.java
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,60 @@
 | 
			
		|||
/* Copyright WTFPL */
 | 
			
		||||
package integration;
 | 
			
		||||
 | 
			
		||||
import nsusbloader.NSLMain;
 | 
			
		||||
import nsusbloader.Utilities.patches.fs.FsPatchMaker;
 | 
			
		||||
import org.junit.jupiter.api.BeforeAll;
 | 
			
		||||
import org.junit.jupiter.api.Disabled;
 | 
			
		||||
import org.junit.jupiter.api.DisplayName;
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
 | 
			
		||||
import java.io.File;
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
 | 
			
		||||
public class FsIntegrationTest {
 | 
			
		||||
    static String pathToFirmware;
 | 
			
		||||
    static String pathToFirmwares;
 | 
			
		||||
    static String pathToKeysFile;
 | 
			
		||||
    static String saveTo;
 | 
			
		||||
 | 
			
		||||
    @BeforeAll
 | 
			
		||||
    static void init() throws Exception{
 | 
			
		||||
        NSLMain.isCli = true;
 | 
			
		||||
        Environment environment = new Environment();
 | 
			
		||||
        pathToKeysFile = environment.getProdkeysLocation();
 | 
			
		||||
        saveTo = environment.getSaveToLocation() + File.separator + "FS_LPR";
 | 
			
		||||
        pathToFirmwares = environment.getFirmwaresLocation();
 | 
			
		||||
        pathToFirmware = pathToFirmware + File.separator + "Firmware 13.0.0";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Disabled
 | 
			
		||||
    @DisplayName("FS Integration validation - everything")
 | 
			
		||||
    @Test
 | 
			
		||||
    void makeFss() throws Exception{
 | 
			
		||||
        File[] fwDirs = new File(pathToFirmwares).listFiles((file, s) -> {
 | 
			
		||||
            return (s.matches("^Firmware (9\\.|[0-9][0-9]\\.).*") && ! s.endsWith(".zip"));
 | 
			
		||||
            //return s.matches("^Firmware 10.0.1.*");
 | 
			
		||||
        });
 | 
			
		||||
        assert fwDirs != null;
 | 
			
		||||
        Arrays.sort(fwDirs);
 | 
			
		||||
 | 
			
		||||
        for (File dir : fwDirs){
 | 
			
		||||
            System.out.println("\n\t\t\t"+dir.getName());
 | 
			
		||||
            FsPatchMaker fsPatchMaker = new FsPatchMaker(dir.getAbsolutePath(), pathToKeysFile, saveTo);
 | 
			
		||||
            Thread workThread = new Thread(fsPatchMaker);
 | 
			
		||||
            workThread.start();
 | 
			
		||||
            workThread.join();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Disabled
 | 
			
		||||
    @DisplayName("FS Integration validation - one particular firmware")
 | 
			
		||||
    @Test
 | 
			
		||||
    void makeFs() throws Exception{
 | 
			
		||||
        System.out.println(pathToFirmware);
 | 
			
		||||
        FsPatchMaker fsPatchMaker = new FsPatchMaker(pathToFirmware, pathToKeysFile, saveTo);
 | 
			
		||||
        Thread workThread = new Thread(fsPatchMaker);
 | 
			
		||||
        workThread.start();
 | 
			
		||||
        workThread.join();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										35
									
								
								src/test/java/integration/LoaderIntegrationTest.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								src/test/java/integration/LoaderIntegrationTest.java
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,35 @@
 | 
			
		|||
/* Copyright WTFPL */
 | 
			
		||||
package integration;
 | 
			
		||||
 | 
			
		||||
import nsusbloader.NSLMain;
 | 
			
		||||
import nsusbloader.Utilities.patches.loader.LoaderPatchMaker;
 | 
			
		||||
import org.junit.jupiter.api.BeforeAll;
 | 
			
		||||
import org.junit.jupiter.api.Disabled;
 | 
			
		||||
import org.junit.jupiter.api.DisplayName;
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
 | 
			
		||||
import java.io.File;
 | 
			
		||||
 | 
			
		||||
public class LoaderIntegrationTest {
 | 
			
		||||
    static String pathToAtmo;
 | 
			
		||||
    static String saveTo;
 | 
			
		||||
 | 
			
		||||
    @BeforeAll
 | 
			
		||||
    static void init() throws Exception{
 | 
			
		||||
        NSLMain.isCli = true;
 | 
			
		||||
        Environment environment = new Environment();
 | 
			
		||||
        saveTo = environment.getSaveToLocation() + File.separator + "Loader_LPR";
 | 
			
		||||
        pathToAtmo = environment.getAtmosphereLocation();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Disabled
 | 
			
		||||
    @DisplayName("Loader Integration validation")
 | 
			
		||||
    @Test
 | 
			
		||||
    void makeLoader() throws Exception{
 | 
			
		||||
        System.out.println(pathToAtmo);
 | 
			
		||||
        LoaderPatchMaker patchMaker = new LoaderPatchMaker(pathToAtmo, saveTo);
 | 
			
		||||
        Thread workThread = new Thread(patchMaker);
 | 
			
		||||
        workThread.start();
 | 
			
		||||
        workThread.join();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in a new issue