From a0bdccdcf900ae47e985cf117d4150ddf57c5c41 Mon Sep 17 00:00:00 2001 From: Dmitry Isaenko Date: Mon, 22 Jul 2024 14:55:11 +0300 Subject: [PATCH] Simplify package2 tests chain --- src/test/java/libKonogonka/LKonTest.java | 25 +++++++++ .../examples/ExtractDecompressedKip1Test.java | 8 +-- .../package2/ExtractPackage2Test.java | 53 ++++++++----------- .../package2/Ini1ExtractTest.java | 39 ++++---------- .../package2/KernelBinExtractTest.java | 40 ++++---------- .../package2/Kip1ExtractDecompressedTest.java | 34 +++--------- .../package2/Kip1ExtractTest.java | 40 ++++---------- .../package2/LKonPackage2Test.java | 13 +++++ 8 files changed, 106 insertions(+), 146 deletions(-) create mode 100644 src/test/java/libKonogonka/LKonTest.java create mode 100644 src/test/java/libKonogonka/package2/LKonPackage2Test.java diff --git a/src/test/java/libKonogonka/LKonTest.java b/src/test/java/libKonogonka/LKonTest.java new file mode 100644 index 0000000..35ee291 --- /dev/null +++ b/src/test/java/libKonogonka/LKonTest.java @@ -0,0 +1,25 @@ +package libKonogonka; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Paths; + +public class LKonTest { + protected static KeyChainHolder keyChainHolder; + + protected static final String KEYS_FILE_LOCATION = "FilesForTests"+File.separator+"prod.keys"; + protected static final String XCI_HEADER_KEYS_FILE_LOCATION = "FilesForTests"+File.separator+"xci_header_key.txt"; + protected static final String PATH_TO_FIRMWARE = "/home/loper/Projects/tempPatchesPlayground/nintendo-switch-global-firmwares/"+ File.separator+"Firmware 14.1.0"; + protected static final String PATH_TO_FIRMWARES = "/home/loper/Projects/tempPatchesPlayground/nintendo-switch-global-firmwares/"; + protected static final String TEMP_DIR = System.getProperty("java.io.tmpdir"); + + @BeforeAll + protected static void makeKeys() throws Exception{ + String keyValue = new String(Files.readAllBytes(Paths.get(XCI_HEADER_KEYS_FILE_LOCATION))).trim(); + Assertions.assertNotEquals(0, keyValue.length()); + keyChainHolder = new KeyChainHolder(KEYS_FILE_LOCATION, keyValue); + } +} diff --git a/src/test/java/libKonogonka/examples/ExtractDecompressedKip1Test.java b/src/test/java/libKonogonka/examples/ExtractDecompressedKip1Test.java index 23fa5c1..0a0df31 100644 --- a/src/test/java/libKonogonka/examples/ExtractDecompressedKip1Test.java +++ b/src/test/java/libKonogonka/examples/ExtractDecompressedKip1Test.java @@ -23,7 +23,7 @@ public class ExtractDecompressedKip1Test { final String KEYS_FILE_LOCATION = "FilesForTests"+ File.separator+"prod.keys"; final String XCI_HEADER_KEYS_FILE_LOCATION = "FilesForTests"+File.separator+"xci_header_key.txt"; - final String pathToFirmwares = ". . ./tempPatchesPlayground/nintendo-switch-global-firmwares"; + final String pathToFirmwares = "/tmp"; private static KeyChainHolder keyChainHolder; @@ -34,8 +34,8 @@ public class ExtractDecompressedKip1Test { makeKeys(); File firmwaresDir = new File(pathToFirmwares); Assertions.assertNotNull(firmwaresDir); - //File[] fwDirs = new File(pathToFirmwares).listFiles((file, s) -> (s.matches("^Firmware (9\\.|[0-9][0-9]\\.).*") && ! s.endsWith(".zip"))); - File[] fwDirs = new File(pathToFirmwares).listFiles((file, s) -> s.equals("Firmware 14.1.2")); + File[] fwDirs = new File(pathToFirmwares).listFiles((file, s) -> (s.matches("^Firmware (9\\.|[0-9][0-9]\\.).*") && ! s.endsWith(".zip"))); + //File[] fwDirs = new File(pathToFirmwares).listFiles((file, s) -> s.equals("Firmware 14.1.2")); for (File fw : fwDirs) { if (fw.isFile()) @@ -120,7 +120,7 @@ public class ExtractDecompressedKip1Test { for (KIP1Provider kip1Provider : providerStream.getIni1Provider().getKip1List()){ String kip1Name = kip1Provider.getHeader().getName(); if (kip1Name.equals("FS")) { - System.out.println("Exported: "+kip1Provider.exportAsDecompressed(exportIntoFolder)); + System.out.println("Exported: "+kip1Provider.exportAsDecompressed(exportIntoFolder)+"\n"+exportIntoFolder); break; } } diff --git a/src/test/java/libKonogonka/package2/ExtractPackage2Test.java b/src/test/java/libKonogonka/package2/ExtractPackage2Test.java index 831b633..fb95b86 100644 --- a/src/test/java/libKonogonka/package2/ExtractPackage2Test.java +++ b/src/test/java/libKonogonka/package2/ExtractPackage2Test.java @@ -1,7 +1,6 @@ package libKonogonka.package2; import libKonogonka.Converter; -import libKonogonka.KeyChainHolder; import libKonogonka.fs.NCA.NCAProvider; import libKonogonka.fs.RomFs.FileSystemEntry; import libKonogonka.fs.RomFs.RomFsProvider; @@ -15,29 +14,18 @@ import java.util.*; import java.util.stream.Collectors; import java.util.zip.CRC32; +import static libKonogonka.Converter.byteArrToHexStringAsLE; + /* ..::::::::::::::::::::: # 1 :::::::::::::::::::::.. * This test validates (encrypted) package2 CRC32 equality and sizes match between reference values and * 1. package2 from RomFS exported root * 2. package2 from RomFS exported as stand-alone file * */ -public class ExtractPackage2Test { - final String KEYS_FILE_LOCATION = "FilesForTests"+File.separator+"prod.keys"; - final String XCI_HEADER_KEYS_FILE_LOCATION = "FilesForTests"+File.separator+"xci_header_key.txt"; - - final String pathToFirmware = "FilesForTests"+File.separator+"Firmware 14.1.0"; - - private static KeyChainHolder keyChainHolder; - - final String referenceFat = "FilesForTests"+File.separator+"reference_for_system2"+File.separator+"FAT"; - final String referenceExFat = "FilesForTests"+File.separator+"reference_for_system2"+File.separator+"ExFAT"; - final String exportFat = System.getProperty("java.io.tmpdir")+File.separator+"Exported_FAT"+File.separator+getClass().getSimpleName(); - final String exportExFat = System.getProperty("java.io.tmpdir")+File.separator+"Exported_ExFAT"+File.separator+getClass().getSimpleName(); - +public class ExtractPackage2Test extends LKonPackage2Test { @DisplayName("Extract package2 test") @Test void testSystem2() throws Exception{ - makeKeys(); String[] ncaFileNames = collectNcaFileNames(); List ncaProviders = makeNcaProviders(ncaFileNames); @@ -55,22 +43,27 @@ public class ExtractPackage2Test { Assertions.assertNotNull(system2FatNcaProvider); Assertions.assertNotNull(system2ExFatNcaProvider); - System.out.println("FAT " + system2FatNcaProvider.getFile().getName()); - System.out.println("ExFAT " + system2ExFatNcaProvider.getFile().getName()); + System.out.println("\n" + + "FAT " + system2FatNcaProvider.getFile().getName() + "\n" + + byteArrToHexStringAsLE(system2FatNcaProvider.getDecryptedKey0()) + "\n" + + byteArrToHexStringAsLE(system2FatNcaProvider.getDecryptedKey1()) + "\n" + + byteArrToHexStringAsLE(system2FatNcaProvider.getDecryptedKey2()) + "\n" + + byteArrToHexStringAsLE(system2FatNcaProvider.getDecryptedKey3()) + "\n~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n" + + "ExFAT " + system2ExFatNcaProvider.getFile().getName() + "\n" + + byteArrToHexStringAsLE(system2ExFatNcaProvider.getDecryptedKey0()) + "\n" + + byteArrToHexStringAsLE(system2ExFatNcaProvider.getDecryptedKey1()) + "\n" + + byteArrToHexStringAsLE(system2ExFatNcaProvider.getDecryptedKey2()) + "\n" + + byteArrToHexStringAsLE(system2ExFatNcaProvider.getDecryptedKey3())); Assertions.assertTrue(system2FatNcaProvider.getFile().getName().endsWith("1212c.nca")); Assertions.assertTrue(system2ExFatNcaProvider.getFile().getName().endsWith("cc081.nca")); - testExportedFiles(system2FatNcaProvider, exportFat, referenceFat); - testExportedFiles(system2ExFatNcaProvider, exportExFat, referenceExFat); - } - void makeKeys() throws Exception{ - String keyValue = new String(Files.readAllBytes(Paths.get(XCI_HEADER_KEYS_FILE_LOCATION))).trim(); - Assertions.assertNotEquals(0, keyValue.length()); - keyChainHolder = new KeyChainHolder(KEYS_FILE_LOCATION, keyValue); + testExportedFiles(system2FatNcaProvider, exportFat, REFERENCE_FAT); + testExportedFiles(system2ExFatNcaProvider, exportExFat, REFERENCE_EXFAT); } + String[] collectNcaFileNames(){ - File firmware = new File(pathToFirmware); + File firmware = new File(PATH_TO_FIRMWARE); Assertions.assertTrue(firmware.exists()); String[] ncaFileNames = firmware.list((File directory, String file) -> ( ! file.endsWith(".cnmt.nca") && file.endsWith(".nca"))); Assertions.assertNotNull(ncaFileNames); @@ -79,7 +72,7 @@ public class ExtractPackage2Test { List makeNcaProviders(String[] ncaFileNames) throws Exception{ List ncaProviders = new ArrayList<>(); for (String ncaFileName : ncaFileNames){ - File nca = new File(pathToFirmware+File.separator+ncaFileName); + File nca = new File(PATH_TO_FIRMWARE +File.separator+ncaFileName); NCAProvider provider = new NCAProvider(nca, keyChainHolder.getRawKeySet()); ncaProviders.add(provider); } @@ -96,10 +89,10 @@ public class ExtractPackage2Test { Path myFilePath1 = Paths.get(exportIntoFolder+File.separator+"ROOT"+File.separator+"nx"+File.separator+"package2"); Path myFilePath2 = Paths.get(exportIntoFolder+File.separator+"package2"); - System.out.println(); - System.out.println("Reference : " + referenceFilePath); - System.out.println("Own #1 : " + myFilePath1); - System.out.println("Own #2 : " + myFilePath2); + System.out.println("\n" + + "\nReference : " + referenceFilePath + + "\nOwn #1 : " + myFilePath1 + + "\nOwn #2 : " + myFilePath2); romFsProvider.exportContent(exportIntoFolder, romFsProvider.getRootEntry()); long referenceCrc32 = calculateReferenceCRC32(referenceFilePath); diff --git a/src/test/java/libKonogonka/package2/Ini1ExtractTest.java b/src/test/java/libKonogonka/package2/Ini1ExtractTest.java index 3ac56d0..3e048ce 100644 --- a/src/test/java/libKonogonka/package2/Ini1ExtractTest.java +++ b/src/test/java/libKonogonka/package2/Ini1ExtractTest.java @@ -1,7 +1,6 @@ package libKonogonka.package2; import libKonogonka.Converter; -import libKonogonka.KeyChainHolder; import libKonogonka.fs.NCA.NCAProvider; import libKonogonka.fs.RomFs.FileSystemEntry; import libKonogonka.fs.RomFs.RomFsProvider; @@ -27,19 +26,7 @@ import java.util.zip.CRC32; * 2. INI1.bin extracted from NCA file via streams * */ -public class Ini1ExtractTest { - final String KEYS_FILE_LOCATION = "FilesForTests"+File.separator+"prod.keys"; - final String XCI_HEADER_KEYS_FILE_LOCATION = "FilesForTests"+File.separator+"xci_header_key.txt"; - - final String pathToFirmware = "FilesForTests"+File.separator+"Firmware 14.1.0"; - - private static KeyChainHolder keyChainHolder; - - final String referenceFat = "FilesForTests"+File.separator+"reference_for_system2"+File.separator+"FAT"; - final String referenceExFat = "FilesForTests"+File.separator+"reference_for_system2"+File.separator+"ExFAT"; - final String exportFat = System.getProperty("java.io.tmpdir")+File.separator+"Exported_FAT"+File.separator+getClass().getSimpleName(); - final String exportExFat = System.getProperty("java.io.tmpdir")+File.separator+"Exported_ExFAT"+File.separator+getClass().getSimpleName(); - +public class Ini1ExtractTest extends LKonPackage2Test { @DisplayName("INI1.bin extract test") @Test void testSystem2() throws Exception{ @@ -61,22 +48,18 @@ public class Ini1ExtractTest { Assertions.assertNotNull(system2FatNcaProvider); Assertions.assertNotNull(system2ExFatNcaProvider); - System.out.println("FAT " + system2FatNcaProvider.getFile().getName()); - System.out.println("ExFAT " + system2ExFatNcaProvider.getFile().getName()); + System.out.println("FAT " + system2FatNcaProvider.getFile().getName() + + "\nExFAT " + system2ExFatNcaProvider.getFile().getName()); Assertions.assertTrue(system2FatNcaProvider.getFile().getName().endsWith("1212c.nca")); Assertions.assertTrue(system2ExFatNcaProvider.getFile().getName().endsWith("cc081.nca")); - testExportedFiles(system2FatNcaProvider, exportFat, referenceFat); - testExportedFiles(system2ExFatNcaProvider, exportExFat, referenceExFat); - } - void makeKeys() throws Exception{ - String keyValue = new String(Files.readAllBytes(Paths.get(XCI_HEADER_KEYS_FILE_LOCATION))).trim(); - Assertions.assertNotEquals(0, keyValue.length()); - keyChainHolder = new KeyChainHolder(KEYS_FILE_LOCATION, keyValue); + testExportedFiles(system2FatNcaProvider, exportFat, REFERENCE_FAT); + testExportedFiles(system2ExFatNcaProvider, exportExFat, REFERENCE_EXFAT); } + String[] collectNcaFileNames(){ - File firmware = new File(pathToFirmware); + File firmware = new File(PATH_TO_FIRMWARE); Assertions.assertTrue(firmware.exists()); String[] ncaFileNames = firmware.list((File directory, String file) -> ( ! file.endsWith(".cnmt.nca") && file.endsWith(".nca"))); Assertions.assertNotNull(ncaFileNames); @@ -85,7 +68,7 @@ public class Ini1ExtractTest { List makeNcaProviders(String[] ncaFileNames) throws Exception{ List ncaProviders = new ArrayList<>(); for (String ncaFileName : ncaFileNames){ - File nca = new File(pathToFirmware+File.separator+ncaFileName); + File nca = new File(PATH_TO_FIRMWARE +File.separator+ncaFileName); NCAProvider provider = new NCAProvider(nca, keyChainHolder.getRawKeySet()); ncaProviders.add(provider); } @@ -112,9 +95,9 @@ public class Ini1ExtractTest { Path referenceFilePath = Paths.get(referenceFilesFolder+File.separator+"package2"+File.separator+"INI1.bin"); Path myFilePath = Paths.get(exportIntoFolder+File.separator+"INI1.bin"); - System.out.println(); - System.out.println("Reference : " + referenceFilePath); - System.out.println("Own : " + myFilePath); + System.out.println("\n" + + "\nReference : " + referenceFilePath + + "\nOwn : " + myFilePath); long referenceCrc32 = calculateReferenceCRC32(referenceFilePath); romFsProvider.exportContent(exportIntoFolder, package2FileSystemEntry); diff --git a/src/test/java/libKonogonka/package2/KernelBinExtractTest.java b/src/test/java/libKonogonka/package2/KernelBinExtractTest.java index b56062b..c83273c 100644 --- a/src/test/java/libKonogonka/package2/KernelBinExtractTest.java +++ b/src/test/java/libKonogonka/package2/KernelBinExtractTest.java @@ -1,7 +1,6 @@ package libKonogonka.package2; import libKonogonka.Converter; -import libKonogonka.KeyChainHolder; import libKonogonka.fs.NCA.NCAProvider; import libKonogonka.fs.RomFs.FileSystemEntry; import libKonogonka.fs.RomFs.RomFsProvider; @@ -24,23 +23,10 @@ import java.util.zip.CRC32; * 2. Kernel.bin extracted from NCA file via streams * */ -public class KernelBinExtractTest { - final String KEYS_FILE_LOCATION = "FilesForTests"+File.separator+"prod.keys"; - final String XCI_HEADER_KEYS_FILE_LOCATION = "FilesForTests"+File.separator+"xci_header_key.txt"; - - final String pathToFirmware = "FilesForTests"+File.separator+"Firmware 14.1.0"; - - private static KeyChainHolder keyChainHolder; - - final String referenceFat = "FilesForTests"+File.separator+"reference_for_system2"+File.separator+"FAT"; - final String referenceExFat = "FilesForTests"+File.separator+"reference_for_system2"+File.separator+"ExFAT"; - final String exportFat = System.getProperty("java.io.tmpdir")+File.separator+"Exported_FAT"+File.separator+getClass().getSimpleName(); - final String exportExFat = System.getProperty("java.io.tmpdir")+File.separator+"Exported_ExFAT"+File.separator+getClass().getSimpleName(); - +public class KernelBinExtractTest extends LKonPackage2Test { @DisplayName("Kernel.bin extract test") @Test void testSystem2() throws Exception{ - makeKeys(); String[] ncaFileNames = collectNcaFileNames(); List ncaProviders = makeNcaProviders(ncaFileNames); @@ -58,22 +44,18 @@ public class KernelBinExtractTest { Assertions.assertNotNull(system2FatNcaProvider); Assertions.assertNotNull(system2ExFatNcaProvider); - System.out.println("FAT " + system2FatNcaProvider.getFile().getName()); - System.out.println("ExFAT " + system2ExFatNcaProvider.getFile().getName()); + System.out.println("FAT " + system2FatNcaProvider.getFile().getName() + + "\nExFAT " + system2ExFatNcaProvider.getFile().getName()); Assertions.assertTrue(system2FatNcaProvider.getFile().getName().endsWith("1212c.nca")); Assertions.assertTrue(system2ExFatNcaProvider.getFile().getName().endsWith("cc081.nca")); - testExportedFiles(system2FatNcaProvider, exportFat, referenceFat); - testExportedFiles(system2ExFatNcaProvider, exportExFat, referenceExFat); - } - void makeKeys() throws Exception{ - String keyValue = new String(Files.readAllBytes(Paths.get(XCI_HEADER_KEYS_FILE_LOCATION))).trim(); - Assertions.assertNotEquals(0, keyValue.length()); - keyChainHolder = new KeyChainHolder(KEYS_FILE_LOCATION, keyValue); + testExportedFiles(system2FatNcaProvider, exportFat, REFERENCE_FAT); + testExportedFiles(system2ExFatNcaProvider, exportExFat, REFERENCE_EXFAT); } + String[] collectNcaFileNames(){ - File firmware = new File(pathToFirmware); + File firmware = new File(PATH_TO_FIRMWARE); Assertions.assertTrue(firmware.exists()); String[] ncaFileNames = firmware.list((File directory, String file) -> ( ! file.endsWith(".cnmt.nca") && file.endsWith(".nca"))); Assertions.assertNotNull(ncaFileNames); @@ -82,7 +64,7 @@ public class KernelBinExtractTest { List makeNcaProviders(String[] ncaFileNames) throws Exception{ List ncaProviders = new ArrayList<>(); for (String ncaFileName : ncaFileNames){ - File nca = new File(pathToFirmware+File.separator+ncaFileName); + File nca = new File(PATH_TO_FIRMWARE +File.separator+ncaFileName); NCAProvider provider = new NCAProvider(nca, keyChainHolder.getRawKeySet()); ncaProviders.add(provider); } @@ -109,9 +91,9 @@ public class KernelBinExtractTest { Path referenceFilePath = Paths.get(referenceFilesFolder+File.separator+"package2"+File.separator+"Kernel.bin"); Path myFilePath = Paths.get(exportIntoFolder+File.separator+"Kernel.bin"); - System.out.println(); - System.out.println("Reference : " + referenceFilePath); - System.out.println("Own : " + myFilePath); + System.out.println("\n" + + "\nReference : " + referenceFilePath + + "\nOwn : " + myFilePath); long referenceCrc32 = calculateReferenceCRC32(referenceFilePath); romFsProvider.exportContent(exportIntoFolder, package2FileSystemEntry); diff --git a/src/test/java/libKonogonka/package2/Kip1ExtractDecompressedTest.java b/src/test/java/libKonogonka/package2/Kip1ExtractDecompressedTest.java index c121f05..7ead41c 100644 --- a/src/test/java/libKonogonka/package2/Kip1ExtractDecompressedTest.java +++ b/src/test/java/libKonogonka/package2/Kip1ExtractDecompressedTest.java @@ -1,7 +1,6 @@ package libKonogonka.package2; import libKonogonka.Converter; -import libKonogonka.KeyChainHolder; import libKonogonka.fs.NCA.NCAProvider; import libKonogonka.fs.RomFs.FileSystemEntry; import libKonogonka.fs.RomFs.RomFsProvider; @@ -29,23 +28,10 @@ import java.util.zip.CRC32; * 2. Decompressed KIP1 extracted from NCA file via streams * */ -public class Kip1ExtractDecompressedTest { - final String KEYS_FILE_LOCATION = "FilesForTests"+File.separator+"prod.keys"; - final String XCI_HEADER_KEYS_FILE_LOCATION = "FilesForTests"+File.separator+"xci_header_key.txt"; - - final String pathToFirmware = "FilesForTests"+File.separator+"Firmware 14.1.0"; - - private static KeyChainHolder keyChainHolder; - - final String referenceFat = "FilesForTests"+File.separator+"reference_for_system2"+File.separator+"FAT"+File.separator+"decompressed"; - final String referenceExFat = "FilesForTests"+File.separator+"reference_for_system2"+File.separator+"ExFAT"+File.separator+"decompressed"; - final String exportFat = System.getProperty("java.io.tmpdir")+File.separator+"Exported_FAT"+File.separator+getClass().getSimpleName(); - final String exportExFat = System.getProperty("java.io.tmpdir")+File.separator+"Exported_ExFAT"+File.separator+getClass().getSimpleName(); - +public class Kip1ExtractDecompressedTest extends LKonPackage2Test { @DisplayName("KIP1 extract test (case 'FS')") @Test void testSystem2() throws Exception{ - makeKeys(); String[] ncaFileNames = collectNcaFileNames(); List ncaProviders = makeNcaProviders(ncaFileNames); @@ -63,22 +49,18 @@ public class Kip1ExtractDecompressedTest { Assertions.assertNotNull(system2FatNcaProvider); Assertions.assertNotNull(system2ExFatNcaProvider); - System.out.println("FAT " + system2FatNcaProvider.getFile().getName()); - System.out.println("ExFAT " + system2ExFatNcaProvider.getFile().getName()); + System.out.println("FAT " + system2FatNcaProvider.getFile().getName() + + "\nExFAT " + system2ExFatNcaProvider.getFile().getName()); Assertions.assertTrue(system2FatNcaProvider.getFile().getName().endsWith("1212c.nca")); Assertions.assertTrue(system2ExFatNcaProvider.getFile().getName().endsWith("cc081.nca")); - testExportedFiles(system2FatNcaProvider, exportFat, referenceFat); - testExportedFiles(system2ExFatNcaProvider, exportExFat, referenceExFat); - } - void makeKeys() throws Exception{ - String keyValue = new String(Files.readAllBytes(Paths.get(XCI_HEADER_KEYS_FILE_LOCATION))).trim(); - Assertions.assertNotEquals(0, keyValue.length()); - keyChainHolder = new KeyChainHolder(KEYS_FILE_LOCATION, keyValue); + testExportedFiles(system2FatNcaProvider, exportFat, REFERENCE_FAT); + testExportedFiles(system2ExFatNcaProvider, exportExFat, REFERENCE_EXFAT); } + String[] collectNcaFileNames(){ - File firmware = new File(pathToFirmware); + File firmware = new File(PATH_TO_FIRMWARE); Assertions.assertTrue(firmware.exists()); String[] ncaFileNames = firmware.list((File directory, String file) -> ( ! file.endsWith(".cnmt.nca") && file.endsWith(".nca"))); Assertions.assertNotNull(ncaFileNames); @@ -87,7 +69,7 @@ public class Kip1ExtractDecompressedTest { List makeNcaProviders(String[] ncaFileNames) throws Exception{ List ncaProviders = new ArrayList<>(); for (String ncaFileName : ncaFileNames){ - File nca = new File(pathToFirmware+File.separator+ncaFileName); + File nca = new File(PATH_TO_FIRMWARE +File.separator+ncaFileName); NCAProvider provider = new NCAProvider(nca, keyChainHolder.getRawKeySet()); ncaProviders.add(provider); } diff --git a/src/test/java/libKonogonka/package2/Kip1ExtractTest.java b/src/test/java/libKonogonka/package2/Kip1ExtractTest.java index 838d140..f73be4d 100644 --- a/src/test/java/libKonogonka/package2/Kip1ExtractTest.java +++ b/src/test/java/libKonogonka/package2/Kip1ExtractTest.java @@ -1,7 +1,6 @@ package libKonogonka.package2; import libKonogonka.Converter; -import libKonogonka.KeyChainHolder; import libKonogonka.fs.NCA.NCAProvider; import libKonogonka.fs.RomFs.FileSystemEntry; import libKonogonka.fs.RomFs.RomFsProvider; @@ -28,23 +27,10 @@ import java.util.zip.CRC32; * 2. KIP1 extracted from NCA file via streams * */ -public class Kip1ExtractTest { - final String KEYS_FILE_LOCATION = "FilesForTests"+File.separator+"prod.keys"; - final String XCI_HEADER_KEYS_FILE_LOCATION = "FilesForTests"+File.separator+"xci_header_key.txt"; - - final String pathToFirmware = "FilesForTests"+File.separator+"Firmware 14.1.0"; - - private static KeyChainHolder keyChainHolder; - - final String referenceFat = "FilesForTests"+File.separator+"reference_for_system2"+File.separator+"FAT"; - final String referenceExFat = "FilesForTests"+File.separator+"reference_for_system2"+File.separator+"ExFAT"; - final String exportFat = System.getProperty("java.io.tmpdir")+File.separator+"Exported_FAT"+File.separator+getClass().getSimpleName(); - final String exportExFat = System.getProperty("java.io.tmpdir")+File.separator+"Exported_ExFAT"+File.separator+getClass().getSimpleName(); - +public class Kip1ExtractTest extends LKonPackage2Test { @DisplayName("KIP1 extract test (case 'FS')") @Test void testSystem2() throws Exception{ - makeKeys(); String[] ncaFileNames = collectNcaFileNames(); List ncaProviders = makeNcaProviders(ncaFileNames); @@ -62,22 +48,18 @@ public class Kip1ExtractTest { Assertions.assertNotNull(system2FatNcaProvider); Assertions.assertNotNull(system2ExFatNcaProvider); - System.out.println("FAT " + system2FatNcaProvider.getFile().getName()); - System.out.println("ExFAT " + system2ExFatNcaProvider.getFile().getName()); + System.out.println("FAT " + system2FatNcaProvider.getFile().getName() + + "\nExFAT " + system2ExFatNcaProvider.getFile().getName()); Assertions.assertTrue(system2FatNcaProvider.getFile().getName().endsWith("1212c.nca")); Assertions.assertTrue(system2ExFatNcaProvider.getFile().getName().endsWith("cc081.nca")); - testExportedFiles(system2FatNcaProvider, exportFat, referenceFat); - testExportedFiles(system2ExFatNcaProvider, exportExFat, referenceExFat); - } - void makeKeys() throws Exception{ - String keyValue = new String(Files.readAllBytes(Paths.get(XCI_HEADER_KEYS_FILE_LOCATION))).trim(); - Assertions.assertNotEquals(0, keyValue.length()); - keyChainHolder = new KeyChainHolder(KEYS_FILE_LOCATION, keyValue); + testExportedFiles(system2FatNcaProvider, exportFat, REFERENCE_FAT); + testExportedFiles(system2ExFatNcaProvider, exportExFat, REFERENCE_EXFAT); } + String[] collectNcaFileNames(){ - File firmware = new File(pathToFirmware); + File firmware = new File(PATH_TO_FIRMWARE); Assertions.assertTrue(firmware.exists()); String[] ncaFileNames = firmware.list((File directory, String file) -> ( ! file.endsWith(".cnmt.nca") && file.endsWith(".nca"))); Assertions.assertNotNull(ncaFileNames); @@ -86,7 +68,7 @@ public class Kip1ExtractTest { List makeNcaProviders(String[] ncaFileNames) throws Exception{ List ncaProviders = new ArrayList<>(); for (String ncaFileName : ncaFileNames){ - File nca = new File(pathToFirmware+File.separator+ncaFileName); + File nca = new File(PATH_TO_FIRMWARE +File.separator+ncaFileName); NCAProvider provider = new NCAProvider(nca, keyChainHolder.getRawKeySet()); ncaProviders.add(provider); } @@ -113,9 +95,9 @@ public class Kip1ExtractTest { Path referenceFilePath = Paths.get(referenceFilesFolder+File.separator+"ini1_extracted"+File.separator+"FS.kip1"); Path myFilePath = Paths.get(exportIntoFolder+File.separator+"FS.kip1"); - System.out.println(); - System.out.println("Reference : " + referenceFilePath); - System.out.println("Own : " + myFilePath); + System.out.println( + "\nReference : " + referenceFilePath + + "\nOwn : " + myFilePath); long referenceCrc32 = calculateReferenceCRC32(referenceFilePath); romFsProvider.exportContent(exportIntoFolder, package2FileSystemEntry); diff --git a/src/test/java/libKonogonka/package2/LKonPackage2Test.java b/src/test/java/libKonogonka/package2/LKonPackage2Test.java new file mode 100644 index 0000000..18984f4 --- /dev/null +++ b/src/test/java/libKonogonka/package2/LKonPackage2Test.java @@ -0,0 +1,13 @@ +package libKonogonka.package2; + +import libKonogonka.LKonTest; + +import java.io.File; + +public class LKonPackage2Test extends LKonTest { + protected static final String REFERENCE_FAT = "FilesForTests"+ File.separator+"reference_for_system2"+File.separator+"FAT"; + protected static final String REFERENCE_EXFAT = "FilesForTests"+File.separator+"reference_for_system2"+File.separator+"ExFAT"; + + protected String exportFat = TEMP_DIR+File.separator+"Exported_FAT"+File.separator+getClass().getSimpleName(); + protected String exportExFat = TEMP_DIR+File.separator+"Exported_ExFAT"+File.separator+getClass().getSimpleName(); +}