Compare commits

..

No commits in common. "a0bdccdcf900ae47e985cf117d4150ddf57c5c41" and "c6e56956e1a608bb8581e2693867f59a2282a62e" have entirely different histories.

9 changed files with 151 additions and 134 deletions

View file

@ -45,14 +45,13 @@ public class RainbowDump {
return; return;
int k = 0; int k = 0;
boolean lastCharCyrillic = false;
stringBuilder.append(String.format("%s%08x %s", ANSI_BLUE, 0, ANSI_RESET)); stringBuilder.append(String.format("%s%08x %s", ANSI_BLUE, 0, ANSI_RESET));
for (int i = 0; i < byteArray.length; i++) { for (int i = 0; i < byteArray.length; i++) {
if (k == 8) if (k == 8)
stringBuilder.append(" "); stringBuilder.append(" ");
if (k == 16){ if (k == 16){
stringBuilder.append(ANSI_GREEN+"| "+ANSI_RESET); stringBuilder.append(ANSI_GREEN+"| "+ANSI_RESET);
lastCharCyrillic = printChars(byteArray, i, lastCharCyrillic); printChars(byteArray, i);
stringBuilder.append("\n") stringBuilder.append("\n")
.append(String.format("%s%08x %s", ANSI_BLUE, i, ANSI_RESET)); .append(String.format("%s%08x %s", ANSI_BLUE, i, ANSI_RESET));
k = 0; k = 0;
@ -80,44 +79,22 @@ public class RainbowDump {
} }
private static void printChars(byte[] byteArray, int pointer){ private static void printChars(byte[] byteArray, int pointer){
printChars(byteArray, pointer, false);
}
private static boolean printChars(byte[] byteArray, int pointer, boolean skipFirstByte){
int j; int j;
if (pointer < 16) if (pointer < 16)
j = 0; j = 0;
else else
j = pointer-16; j = pointer-16;
int utf8val = 0;
if (skipFirstByte){
++j;
stringBuilder.append(" ");
}
for (; j < pointer; j++){ 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 if ((byteArray[j] > 21) && (byteArray[j] < 126)) // man ascii
stringBuilder.append((char) byteArray[j]); stringBuilder.append((char) byteArray[j]);
else if (byteArray[j] == 0x0a) else if (byteArray[j] == 0x0a)
stringBuilder.append(""); //"" stringBuilder.append(""); //""
else if (byteArray[j] == 0x0d) else if (byteArray[j] == 0x0d)
stringBuilder.append(""); // "" 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 else
stringBuilder.append("."); stringBuilder.append(".");
} }
return (utf8val >= 0xd080 && utf8val <= 0xd3bf && j > pointer);
} }
public static void hexDumpUTF8Legacy(byte[] byteArray){ public static void hexDumpUTF8Legacy(byte[] byteArray){

View file

@ -1,25 +0,0 @@
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);
}
}

View file

@ -23,7 +23,7 @@ public class ExtractDecompressedKip1Test {
final String KEYS_FILE_LOCATION = "FilesForTests"+ File.separator+"prod.keys"; 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 XCI_HEADER_KEYS_FILE_LOCATION = "FilesForTests"+File.separator+"xci_header_key.txt";
final String pathToFirmwares = "/tmp"; final String pathToFirmwares = ". . ./tempPatchesPlayground/nintendo-switch-global-firmwares";
private static KeyChainHolder keyChainHolder; private static KeyChainHolder keyChainHolder;
@ -34,8 +34,8 @@ public class ExtractDecompressedKip1Test {
makeKeys(); makeKeys();
File firmwaresDir = new File(pathToFirmwares); File firmwaresDir = new File(pathToFirmwares);
Assertions.assertNotNull(firmwaresDir); 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.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.equals("Firmware 14.1.2"));
for (File fw : fwDirs) { for (File fw : fwDirs) {
if (fw.isFile()) if (fw.isFile())
@ -120,7 +120,7 @@ public class ExtractDecompressedKip1Test {
for (KIP1Provider kip1Provider : providerStream.getIni1Provider().getKip1List()){ for (KIP1Provider kip1Provider : providerStream.getIni1Provider().getKip1List()){
String kip1Name = kip1Provider.getHeader().getName(); String kip1Name = kip1Provider.getHeader().getName();
if (kip1Name.equals("FS")) { if (kip1Name.equals("FS")) {
System.out.println("Exported: "+kip1Provider.exportAsDecompressed(exportIntoFolder)+"\n"+exportIntoFolder); System.out.println("Exported: "+kip1Provider.exportAsDecompressed(exportIntoFolder));
break; break;
} }
} }

View file

@ -1,6 +1,7 @@
package libKonogonka.package2; package libKonogonka.package2;
import libKonogonka.Converter; import libKonogonka.Converter;
import libKonogonka.KeyChainHolder;
import libKonogonka.fs.NCA.NCAProvider; import libKonogonka.fs.NCA.NCAProvider;
import libKonogonka.fs.RomFs.FileSystemEntry; import libKonogonka.fs.RomFs.FileSystemEntry;
import libKonogonka.fs.RomFs.RomFsProvider; import libKonogonka.fs.RomFs.RomFsProvider;
@ -14,18 +15,29 @@ import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.zip.CRC32; import java.util.zip.CRC32;
import static libKonogonka.Converter.byteArrToHexStringAsLE;
/* ..::::::::::::::::::::: # 1 :::::::::::::::::::::.. /* ..::::::::::::::::::::: # 1 :::::::::::::::::::::..
* This test validates (encrypted) package2 CRC32 equality and sizes match between reference values and * This test validates (encrypted) package2 CRC32 equality and sizes match between reference values and
* 1. package2 from RomFS exported root * 1. package2 from RomFS exported root
* 2. package2 from RomFS exported as stand-alone file * 2. package2 from RomFS exported as stand-alone file
* */ * */
public class ExtractPackage2Test extends LKonPackage2Test { 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();
@DisplayName("Extract package2 test") @DisplayName("Extract package2 test")
@Test @Test
void testSystem2() throws Exception{ void testSystem2() throws Exception{
makeKeys();
String[] ncaFileNames = collectNcaFileNames(); String[] ncaFileNames = collectNcaFileNames();
List<NCAProvider> ncaProviders = makeNcaProviders(ncaFileNames); List<NCAProvider> ncaProviders = makeNcaProviders(ncaFileNames);
@ -43,27 +55,22 @@ public class ExtractPackage2Test extends LKonPackage2Test {
Assertions.assertNotNull(system2FatNcaProvider); Assertions.assertNotNull(system2FatNcaProvider);
Assertions.assertNotNull(system2ExFatNcaProvider); Assertions.assertNotNull(system2ExFatNcaProvider);
System.out.println("\n" + System.out.println("FAT " + system2FatNcaProvider.getFile().getName());
"FAT " + system2FatNcaProvider.getFile().getName() + "\n" + System.out.println("ExFAT " + system2ExFatNcaProvider.getFile().getName());
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(system2FatNcaProvider.getFile().getName().endsWith("1212c.nca"));
Assertions.assertTrue(system2ExFatNcaProvider.getFile().getName().endsWith("cc081.nca")); Assertions.assertTrue(system2ExFatNcaProvider.getFile().getName().endsWith("cc081.nca"));
testExportedFiles(system2FatNcaProvider, exportFat, REFERENCE_FAT); testExportedFiles(system2FatNcaProvider, exportFat, referenceFat);
testExportedFiles(system2ExFatNcaProvider, exportExFat, REFERENCE_EXFAT); 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);
} }
String[] collectNcaFileNames(){ String[] collectNcaFileNames(){
File firmware = new File(PATH_TO_FIRMWARE); File firmware = new File(pathToFirmware);
Assertions.assertTrue(firmware.exists()); Assertions.assertTrue(firmware.exists());
String[] ncaFileNames = firmware.list((File directory, String file) -> ( ! file.endsWith(".cnmt.nca") && file.endsWith(".nca"))); String[] ncaFileNames = firmware.list((File directory, String file) -> ( ! file.endsWith(".cnmt.nca") && file.endsWith(".nca")));
Assertions.assertNotNull(ncaFileNames); Assertions.assertNotNull(ncaFileNames);
@ -72,7 +79,7 @@ public class ExtractPackage2Test extends LKonPackage2Test {
List<NCAProvider> makeNcaProviders(String[] ncaFileNames) throws Exception{ List<NCAProvider> makeNcaProviders(String[] ncaFileNames) throws Exception{
List<NCAProvider> ncaProviders = new ArrayList<>(); List<NCAProvider> ncaProviders = new ArrayList<>();
for (String ncaFileName : ncaFileNames){ for (String ncaFileName : ncaFileNames){
File nca = new File(PATH_TO_FIRMWARE +File.separator+ncaFileName); File nca = new File(pathToFirmware+File.separator+ncaFileName);
NCAProvider provider = new NCAProvider(nca, keyChainHolder.getRawKeySet()); NCAProvider provider = new NCAProvider(nca, keyChainHolder.getRawKeySet());
ncaProviders.add(provider); ncaProviders.add(provider);
} }
@ -89,10 +96,10 @@ public class ExtractPackage2Test extends LKonPackage2Test {
Path myFilePath1 = Paths.get(exportIntoFolder+File.separator+"ROOT"+File.separator+"nx"+File.separator+"package2"); Path myFilePath1 = Paths.get(exportIntoFolder+File.separator+"ROOT"+File.separator+"nx"+File.separator+"package2");
Path myFilePath2 = Paths.get(exportIntoFolder+File.separator+"package2"); Path myFilePath2 = Paths.get(exportIntoFolder+File.separator+"package2");
System.out.println("\n" + System.out.println();
"\nReference : " + referenceFilePath + System.out.println("Reference : " + referenceFilePath);
"\nOwn #1 : " + myFilePath1 + System.out.println("Own #1 : " + myFilePath1);
"\nOwn #2 : " + myFilePath2); System.out.println("Own #2 : " + myFilePath2);
romFsProvider.exportContent(exportIntoFolder, romFsProvider.getRootEntry()); romFsProvider.exportContent(exportIntoFolder, romFsProvider.getRootEntry());
long referenceCrc32 = calculateReferenceCRC32(referenceFilePath); long referenceCrc32 = calculateReferenceCRC32(referenceFilePath);

View file

@ -1,6 +1,7 @@
package libKonogonka.package2; package libKonogonka.package2;
import libKonogonka.Converter; import libKonogonka.Converter;
import libKonogonka.KeyChainHolder;
import libKonogonka.fs.NCA.NCAProvider; import libKonogonka.fs.NCA.NCAProvider;
import libKonogonka.fs.RomFs.FileSystemEntry; import libKonogonka.fs.RomFs.FileSystemEntry;
import libKonogonka.fs.RomFs.RomFsProvider; import libKonogonka.fs.RomFs.RomFsProvider;
@ -26,7 +27,19 @@ import java.util.zip.CRC32;
* 2. INI1.bin extracted from NCA file via streams * 2. INI1.bin extracted from NCA file via streams
* */ * */
public class Ini1ExtractTest extends LKonPackage2Test { 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();
@DisplayName("INI1.bin extract test") @DisplayName("INI1.bin extract test")
@Test @Test
void testSystem2() throws Exception{ void testSystem2() throws Exception{
@ -48,18 +61,22 @@ public class Ini1ExtractTest extends LKonPackage2Test {
Assertions.assertNotNull(system2FatNcaProvider); Assertions.assertNotNull(system2FatNcaProvider);
Assertions.assertNotNull(system2ExFatNcaProvider); Assertions.assertNotNull(system2ExFatNcaProvider);
System.out.println("FAT " + system2FatNcaProvider.getFile().getName() + System.out.println("FAT " + system2FatNcaProvider.getFile().getName());
"\nExFAT " + system2ExFatNcaProvider.getFile().getName()); System.out.println("ExFAT " + system2ExFatNcaProvider.getFile().getName());
Assertions.assertTrue(system2FatNcaProvider.getFile().getName().endsWith("1212c.nca")); Assertions.assertTrue(system2FatNcaProvider.getFile().getName().endsWith("1212c.nca"));
Assertions.assertTrue(system2ExFatNcaProvider.getFile().getName().endsWith("cc081.nca")); Assertions.assertTrue(system2ExFatNcaProvider.getFile().getName().endsWith("cc081.nca"));
testExportedFiles(system2FatNcaProvider, exportFat, REFERENCE_FAT); testExportedFiles(system2FatNcaProvider, exportFat, referenceFat);
testExportedFiles(system2ExFatNcaProvider, exportExFat, REFERENCE_EXFAT); 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);
} }
String[] collectNcaFileNames(){ String[] collectNcaFileNames(){
File firmware = new File(PATH_TO_FIRMWARE); File firmware = new File(pathToFirmware);
Assertions.assertTrue(firmware.exists()); Assertions.assertTrue(firmware.exists());
String[] ncaFileNames = firmware.list((File directory, String file) -> ( ! file.endsWith(".cnmt.nca") && file.endsWith(".nca"))); String[] ncaFileNames = firmware.list((File directory, String file) -> ( ! file.endsWith(".cnmt.nca") && file.endsWith(".nca")));
Assertions.assertNotNull(ncaFileNames); Assertions.assertNotNull(ncaFileNames);
@ -68,7 +85,7 @@ public class Ini1ExtractTest extends LKonPackage2Test {
List<NCAProvider> makeNcaProviders(String[] ncaFileNames) throws Exception{ List<NCAProvider> makeNcaProviders(String[] ncaFileNames) throws Exception{
List<NCAProvider> ncaProviders = new ArrayList<>(); List<NCAProvider> ncaProviders = new ArrayList<>();
for (String ncaFileName : ncaFileNames){ for (String ncaFileName : ncaFileNames){
File nca = new File(PATH_TO_FIRMWARE +File.separator+ncaFileName); File nca = new File(pathToFirmware+File.separator+ncaFileName);
NCAProvider provider = new NCAProvider(nca, keyChainHolder.getRawKeySet()); NCAProvider provider = new NCAProvider(nca, keyChainHolder.getRawKeySet());
ncaProviders.add(provider); ncaProviders.add(provider);
} }
@ -95,9 +112,9 @@ public class Ini1ExtractTest extends LKonPackage2Test {
Path referenceFilePath = Paths.get(referenceFilesFolder+File.separator+"package2"+File.separator+"INI1.bin"); Path referenceFilePath = Paths.get(referenceFilesFolder+File.separator+"package2"+File.separator+"INI1.bin");
Path myFilePath = Paths.get(exportIntoFolder+File.separator+"INI1.bin"); Path myFilePath = Paths.get(exportIntoFolder+File.separator+"INI1.bin");
System.out.println("\n" + System.out.println();
"\nReference : " + referenceFilePath + System.out.println("Reference : " + referenceFilePath);
"\nOwn : " + myFilePath); System.out.println("Own : " + myFilePath);
long referenceCrc32 = calculateReferenceCRC32(referenceFilePath); long referenceCrc32 = calculateReferenceCRC32(referenceFilePath);
romFsProvider.exportContent(exportIntoFolder, package2FileSystemEntry); romFsProvider.exportContent(exportIntoFolder, package2FileSystemEntry);

View file

@ -1,6 +1,7 @@
package libKonogonka.package2; package libKonogonka.package2;
import libKonogonka.Converter; import libKonogonka.Converter;
import libKonogonka.KeyChainHolder;
import libKonogonka.fs.NCA.NCAProvider; import libKonogonka.fs.NCA.NCAProvider;
import libKonogonka.fs.RomFs.FileSystemEntry; import libKonogonka.fs.RomFs.FileSystemEntry;
import libKonogonka.fs.RomFs.RomFsProvider; import libKonogonka.fs.RomFs.RomFsProvider;
@ -23,10 +24,23 @@ import java.util.zip.CRC32;
* 2. Kernel.bin extracted from NCA file via streams * 2. Kernel.bin extracted from NCA file via streams
* */ * */
public class KernelBinExtractTest extends LKonPackage2Test { 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();
@DisplayName("Kernel.bin extract test") @DisplayName("Kernel.bin extract test")
@Test @Test
void testSystem2() throws Exception{ void testSystem2() throws Exception{
makeKeys();
String[] ncaFileNames = collectNcaFileNames(); String[] ncaFileNames = collectNcaFileNames();
List<NCAProvider> ncaProviders = makeNcaProviders(ncaFileNames); List<NCAProvider> ncaProviders = makeNcaProviders(ncaFileNames);
@ -44,18 +58,22 @@ public class KernelBinExtractTest extends LKonPackage2Test {
Assertions.assertNotNull(system2FatNcaProvider); Assertions.assertNotNull(system2FatNcaProvider);
Assertions.assertNotNull(system2ExFatNcaProvider); Assertions.assertNotNull(system2ExFatNcaProvider);
System.out.println("FAT " + system2FatNcaProvider.getFile().getName() + System.out.println("FAT " + system2FatNcaProvider.getFile().getName());
"\nExFAT " + system2ExFatNcaProvider.getFile().getName()); System.out.println("ExFAT " + system2ExFatNcaProvider.getFile().getName());
Assertions.assertTrue(system2FatNcaProvider.getFile().getName().endsWith("1212c.nca")); Assertions.assertTrue(system2FatNcaProvider.getFile().getName().endsWith("1212c.nca"));
Assertions.assertTrue(system2ExFatNcaProvider.getFile().getName().endsWith("cc081.nca")); Assertions.assertTrue(system2ExFatNcaProvider.getFile().getName().endsWith("cc081.nca"));
testExportedFiles(system2FatNcaProvider, exportFat, REFERENCE_FAT); testExportedFiles(system2FatNcaProvider, exportFat, referenceFat);
testExportedFiles(system2ExFatNcaProvider, exportExFat, REFERENCE_EXFAT); 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);
} }
String[] collectNcaFileNames(){ String[] collectNcaFileNames(){
File firmware = new File(PATH_TO_FIRMWARE); File firmware = new File(pathToFirmware);
Assertions.assertTrue(firmware.exists()); Assertions.assertTrue(firmware.exists());
String[] ncaFileNames = firmware.list((File directory, String file) -> ( ! file.endsWith(".cnmt.nca") && file.endsWith(".nca"))); String[] ncaFileNames = firmware.list((File directory, String file) -> ( ! file.endsWith(".cnmt.nca") && file.endsWith(".nca")));
Assertions.assertNotNull(ncaFileNames); Assertions.assertNotNull(ncaFileNames);
@ -64,7 +82,7 @@ public class KernelBinExtractTest extends LKonPackage2Test {
List<NCAProvider> makeNcaProviders(String[] ncaFileNames) throws Exception{ List<NCAProvider> makeNcaProviders(String[] ncaFileNames) throws Exception{
List<NCAProvider> ncaProviders = new ArrayList<>(); List<NCAProvider> ncaProviders = new ArrayList<>();
for (String ncaFileName : ncaFileNames){ for (String ncaFileName : ncaFileNames){
File nca = new File(PATH_TO_FIRMWARE +File.separator+ncaFileName); File nca = new File(pathToFirmware+File.separator+ncaFileName);
NCAProvider provider = new NCAProvider(nca, keyChainHolder.getRawKeySet()); NCAProvider provider = new NCAProvider(nca, keyChainHolder.getRawKeySet());
ncaProviders.add(provider); ncaProviders.add(provider);
} }
@ -91,9 +109,9 @@ public class KernelBinExtractTest extends LKonPackage2Test {
Path referenceFilePath = Paths.get(referenceFilesFolder+File.separator+"package2"+File.separator+"Kernel.bin"); Path referenceFilePath = Paths.get(referenceFilesFolder+File.separator+"package2"+File.separator+"Kernel.bin");
Path myFilePath = Paths.get(exportIntoFolder+File.separator+"Kernel.bin"); Path myFilePath = Paths.get(exportIntoFolder+File.separator+"Kernel.bin");
System.out.println("\n" + System.out.println();
"\nReference : " + referenceFilePath + System.out.println("Reference : " + referenceFilePath);
"\nOwn : " + myFilePath); System.out.println("Own : " + myFilePath);
long referenceCrc32 = calculateReferenceCRC32(referenceFilePath); long referenceCrc32 = calculateReferenceCRC32(referenceFilePath);
romFsProvider.exportContent(exportIntoFolder, package2FileSystemEntry); romFsProvider.exportContent(exportIntoFolder, package2FileSystemEntry);

View file

@ -1,6 +1,7 @@
package libKonogonka.package2; package libKonogonka.package2;
import libKonogonka.Converter; import libKonogonka.Converter;
import libKonogonka.KeyChainHolder;
import libKonogonka.fs.NCA.NCAProvider; import libKonogonka.fs.NCA.NCAProvider;
import libKonogonka.fs.RomFs.FileSystemEntry; import libKonogonka.fs.RomFs.FileSystemEntry;
import libKonogonka.fs.RomFs.RomFsProvider; import libKonogonka.fs.RomFs.RomFsProvider;
@ -28,10 +29,23 @@ import java.util.zip.CRC32;
* 2. Decompressed KIP1 extracted from NCA file via streams * 2. Decompressed KIP1 extracted from NCA file via streams
* */ * */
public class Kip1ExtractDecompressedTest extends LKonPackage2Test { 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();
@DisplayName("KIP1 extract test (case 'FS')") @DisplayName("KIP1 extract test (case 'FS')")
@Test @Test
void testSystem2() throws Exception{ void testSystem2() throws Exception{
makeKeys();
String[] ncaFileNames = collectNcaFileNames(); String[] ncaFileNames = collectNcaFileNames();
List<NCAProvider> ncaProviders = makeNcaProviders(ncaFileNames); List<NCAProvider> ncaProviders = makeNcaProviders(ncaFileNames);
@ -49,18 +63,22 @@ public class Kip1ExtractDecompressedTest extends LKonPackage2Test {
Assertions.assertNotNull(system2FatNcaProvider); Assertions.assertNotNull(system2FatNcaProvider);
Assertions.assertNotNull(system2ExFatNcaProvider); Assertions.assertNotNull(system2ExFatNcaProvider);
System.out.println("FAT " + system2FatNcaProvider.getFile().getName() + System.out.println("FAT " + system2FatNcaProvider.getFile().getName());
"\nExFAT " + system2ExFatNcaProvider.getFile().getName()); System.out.println("ExFAT " + system2ExFatNcaProvider.getFile().getName());
Assertions.assertTrue(system2FatNcaProvider.getFile().getName().endsWith("1212c.nca")); Assertions.assertTrue(system2FatNcaProvider.getFile().getName().endsWith("1212c.nca"));
Assertions.assertTrue(system2ExFatNcaProvider.getFile().getName().endsWith("cc081.nca")); Assertions.assertTrue(system2ExFatNcaProvider.getFile().getName().endsWith("cc081.nca"));
testExportedFiles(system2FatNcaProvider, exportFat, REFERENCE_FAT); testExportedFiles(system2FatNcaProvider, exportFat, referenceFat);
testExportedFiles(system2ExFatNcaProvider, exportExFat, REFERENCE_EXFAT); 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);
} }
String[] collectNcaFileNames(){ String[] collectNcaFileNames(){
File firmware = new File(PATH_TO_FIRMWARE); File firmware = new File(pathToFirmware);
Assertions.assertTrue(firmware.exists()); Assertions.assertTrue(firmware.exists());
String[] ncaFileNames = firmware.list((File directory, String file) -> ( ! file.endsWith(".cnmt.nca") && file.endsWith(".nca"))); String[] ncaFileNames = firmware.list((File directory, String file) -> ( ! file.endsWith(".cnmt.nca") && file.endsWith(".nca")));
Assertions.assertNotNull(ncaFileNames); Assertions.assertNotNull(ncaFileNames);
@ -69,7 +87,7 @@ public class Kip1ExtractDecompressedTest extends LKonPackage2Test {
List<NCAProvider> makeNcaProviders(String[] ncaFileNames) throws Exception{ List<NCAProvider> makeNcaProviders(String[] ncaFileNames) throws Exception{
List<NCAProvider> ncaProviders = new ArrayList<>(); List<NCAProvider> ncaProviders = new ArrayList<>();
for (String ncaFileName : ncaFileNames){ for (String ncaFileName : ncaFileNames){
File nca = new File(PATH_TO_FIRMWARE +File.separator+ncaFileName); File nca = new File(pathToFirmware+File.separator+ncaFileName);
NCAProvider provider = new NCAProvider(nca, keyChainHolder.getRawKeySet()); NCAProvider provider = new NCAProvider(nca, keyChainHolder.getRawKeySet());
ncaProviders.add(provider); ncaProviders.add(provider);
} }

View file

@ -1,6 +1,7 @@
package libKonogonka.package2; package libKonogonka.package2;
import libKonogonka.Converter; import libKonogonka.Converter;
import libKonogonka.KeyChainHolder;
import libKonogonka.fs.NCA.NCAProvider; import libKonogonka.fs.NCA.NCAProvider;
import libKonogonka.fs.RomFs.FileSystemEntry; import libKonogonka.fs.RomFs.FileSystemEntry;
import libKonogonka.fs.RomFs.RomFsProvider; import libKonogonka.fs.RomFs.RomFsProvider;
@ -27,10 +28,23 @@ import java.util.zip.CRC32;
* 2. KIP1 extracted from NCA file via streams * 2. KIP1 extracted from NCA file via streams
* */ * */
public class Kip1ExtractTest extends LKonPackage2Test { 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();
@DisplayName("KIP1 extract test (case 'FS')") @DisplayName("KIP1 extract test (case 'FS')")
@Test @Test
void testSystem2() throws Exception{ void testSystem2() throws Exception{
makeKeys();
String[] ncaFileNames = collectNcaFileNames(); String[] ncaFileNames = collectNcaFileNames();
List<NCAProvider> ncaProviders = makeNcaProviders(ncaFileNames); List<NCAProvider> ncaProviders = makeNcaProviders(ncaFileNames);
@ -48,18 +62,22 @@ public class Kip1ExtractTest extends LKonPackage2Test {
Assertions.assertNotNull(system2FatNcaProvider); Assertions.assertNotNull(system2FatNcaProvider);
Assertions.assertNotNull(system2ExFatNcaProvider); Assertions.assertNotNull(system2ExFatNcaProvider);
System.out.println("FAT " + system2FatNcaProvider.getFile().getName() + System.out.println("FAT " + system2FatNcaProvider.getFile().getName());
"\nExFAT " + system2ExFatNcaProvider.getFile().getName()); System.out.println("ExFAT " + system2ExFatNcaProvider.getFile().getName());
Assertions.assertTrue(system2FatNcaProvider.getFile().getName().endsWith("1212c.nca")); Assertions.assertTrue(system2FatNcaProvider.getFile().getName().endsWith("1212c.nca"));
Assertions.assertTrue(system2ExFatNcaProvider.getFile().getName().endsWith("cc081.nca")); Assertions.assertTrue(system2ExFatNcaProvider.getFile().getName().endsWith("cc081.nca"));
testExportedFiles(system2FatNcaProvider, exportFat, REFERENCE_FAT); testExportedFiles(system2FatNcaProvider, exportFat, referenceFat);
testExportedFiles(system2ExFatNcaProvider, exportExFat, REFERENCE_EXFAT); 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);
} }
String[] collectNcaFileNames(){ String[] collectNcaFileNames(){
File firmware = new File(PATH_TO_FIRMWARE); File firmware = new File(pathToFirmware);
Assertions.assertTrue(firmware.exists()); Assertions.assertTrue(firmware.exists());
String[] ncaFileNames = firmware.list((File directory, String file) -> ( ! file.endsWith(".cnmt.nca") && file.endsWith(".nca"))); String[] ncaFileNames = firmware.list((File directory, String file) -> ( ! file.endsWith(".cnmt.nca") && file.endsWith(".nca")));
Assertions.assertNotNull(ncaFileNames); Assertions.assertNotNull(ncaFileNames);
@ -68,7 +86,7 @@ public class Kip1ExtractTest extends LKonPackage2Test {
List<NCAProvider> makeNcaProviders(String[] ncaFileNames) throws Exception{ List<NCAProvider> makeNcaProviders(String[] ncaFileNames) throws Exception{
List<NCAProvider> ncaProviders = new ArrayList<>(); List<NCAProvider> ncaProviders = new ArrayList<>();
for (String ncaFileName : ncaFileNames){ for (String ncaFileName : ncaFileNames){
File nca = new File(PATH_TO_FIRMWARE +File.separator+ncaFileName); File nca = new File(pathToFirmware+File.separator+ncaFileName);
NCAProvider provider = new NCAProvider(nca, keyChainHolder.getRawKeySet()); NCAProvider provider = new NCAProvider(nca, keyChainHolder.getRawKeySet());
ncaProviders.add(provider); ncaProviders.add(provider);
} }
@ -95,9 +113,9 @@ public class Kip1ExtractTest extends LKonPackage2Test {
Path referenceFilePath = Paths.get(referenceFilesFolder+File.separator+"ini1_extracted"+File.separator+"FS.kip1"); Path referenceFilePath = Paths.get(referenceFilesFolder+File.separator+"ini1_extracted"+File.separator+"FS.kip1");
Path myFilePath = Paths.get(exportIntoFolder+File.separator+"FS.kip1"); Path myFilePath = Paths.get(exportIntoFolder+File.separator+"FS.kip1");
System.out.println( System.out.println();
"\nReference : " + referenceFilePath + System.out.println("Reference : " + referenceFilePath);
"\nOwn : " + myFilePath); System.out.println("Own : " + myFilePath);
long referenceCrc32 = calculateReferenceCRC32(referenceFilePath); long referenceCrc32 = calculateReferenceCRC32(referenceFilePath);
romFsProvider.exportContent(exportIntoFolder, package2FileSystemEntry); romFsProvider.exportContent(exportIntoFolder, package2FileSystemEntry);

View file

@ -1,13 +0,0 @@
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();
}