Compare commits
2 commits
c6e56956e1
...
a0bdccdcf9
Author | SHA1 | Date | |
---|---|---|---|
|
a0bdccdcf9 | ||
|
68a2f32c82 |
9 changed files with 134 additions and 151 deletions
|
@ -39,19 +39,20 @@ public class RainbowDump {
|
|||
private static final String ANSI_BLUE = "\u001B[34m";
|
||||
|
||||
private static StringBuilder stringBuilder;
|
||||
public static void hexDumpUTF8(byte[] byteArray){
|
||||
public static void hexDumpUTF8(byte[] byteArray) {
|
||||
stringBuilder = new StringBuilder(" -- RainbowDump --\n");
|
||||
if (byteArray == null || byteArray.length == 0)
|
||||
return;
|
||||
|
||||
int k = 0;
|
||||
boolean lastCharCyrillic = false;
|
||||
stringBuilder.append(String.format("%s%08x %s", ANSI_BLUE, 0, ANSI_RESET));
|
||||
for (int i = 0; i < byteArray.length; i++) {
|
||||
if (k == 8)
|
||||
stringBuilder.append(" ");
|
||||
if (k == 16){
|
||||
stringBuilder.append(ANSI_GREEN+"| "+ANSI_RESET);
|
||||
printChars(byteArray, i);
|
||||
if (k == 16) {
|
||||
stringBuilder.append(ANSI_GREEN + "| " + ANSI_RESET);
|
||||
lastCharCyrillic = printChars(byteArray, i, lastCharCyrillic);
|
||||
stringBuilder.append("\n")
|
||||
.append(String.format("%s%08x %s", ANSI_BLUE, i, ANSI_RESET));
|
||||
k = 0;
|
||||
|
@ -68,7 +69,7 @@ public class RainbowDump {
|
|||
stringBuilder.append(" ");
|
||||
}
|
||||
}
|
||||
stringBuilder.append(ANSI_GREEN+"| "+ANSI_RESET);
|
||||
stringBuilder.append(ANSI_GREEN + "| " + ANSI_RESET);
|
||||
printChars(byteArray, byteArray.length);
|
||||
stringBuilder.append("\n")
|
||||
.append(ANSI_RESET)
|
||||
|
@ -79,22 +80,44 @@ public class RainbowDump {
|
|||
}
|
||||
|
||||
private static void printChars(byte[] byteArray, int pointer){
|
||||
printChars(byteArray, pointer, false);
|
||||
}
|
||||
private static boolean printChars(byte[] byteArray, int pointer, boolean skipFirstByte){
|
||||
int j;
|
||||
if (pointer < 16)
|
||||
j = 0;
|
||||
else
|
||||
j = pointer-16;
|
||||
|
||||
int utf8val = 0;
|
||||
if (skipFirstByte){
|
||||
++j;
|
||||
stringBuilder.append(" ");
|
||||
}
|
||||
|
||||
for (; j < pointer; j++){
|
||||
utf8val = 0;
|
||||
|
||||
if (byteArray.length > (j+1))
|
||||
utf8val = ((byteArray[j] & 0xff) << 8) | (byteArray[j+1] & 0xff);
|
||||
|
||||
if ((byteArray[j] > 21) && (byteArray[j] < 126)) // man ascii
|
||||
stringBuilder.append((char) byteArray[j]);
|
||||
else if (byteArray[j] == 0x0a)
|
||||
stringBuilder.append("↲"); //""
|
||||
else if (byteArray[j] == 0x0d)
|
||||
stringBuilder.append("←"); // "␍"
|
||||
else if (utf8val >= 0xd080 && utf8val <= 0xd3bf){
|
||||
byte[] arr = new byte[0x2];
|
||||
System.arraycopy(byteArray, j, arr, 0, 2);
|
||||
stringBuilder.append(new String(arr, StandardCharsets.UTF_8)+" ");
|
||||
++j;
|
||||
}
|
||||
else
|
||||
stringBuilder.append(".");
|
||||
}
|
||||
|
||||
return (utf8val >= 0xd080 && utf8val <= 0xd3bf && j > pointer);
|
||||
}
|
||||
|
||||
public static void hexDumpUTF8Legacy(byte[] byteArray){
|
||||
|
|
25
src/test/java/libKonogonka/LKonTest.java
Normal file
25
src/test/java/libKonogonka/LKonTest.java
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<NCAProvider> 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<NCAProvider> makeNcaProviders(String[] ncaFileNames) throws Exception{
|
||||
List<NCAProvider> 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);
|
||||
|
|
|
@ -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<NCAProvider> makeNcaProviders(String[] ncaFileNames) throws Exception{
|
||||
List<NCAProvider> 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);
|
||||
|
|
|
@ -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<NCAProvider> 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<NCAProvider> makeNcaProviders(String[] ncaFileNames) throws Exception{
|
||||
List<NCAProvider> 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);
|
||||
|
|
|
@ -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<NCAProvider> 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<NCAProvider> makeNcaProviders(String[] ncaFileNames) throws Exception{
|
||||
List<NCAProvider> 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);
|
||||
}
|
||||
|
|
|
@ -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<NCAProvider> 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<NCAProvider> makeNcaProviders(String[] ncaFileNames) throws Exception{
|
||||
List<NCAProvider> 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);
|
||||
|
|
13
src/test/java/libKonogonka/package2/LKonPackage2Test.java
Normal file
13
src/test/java/libKonogonka/package2/LKonPackage2Test.java
Normal file
|
@ -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();
|
||||
}
|
Loading…
Reference in a new issue