Compare commits

..

2 commits

Author SHA1 Message Date
Dmitry Isaenko
a0bdccdcf9 Simplify package2 tests chain 2024-07-22 14:55:11 +03:00
Dmitry Isaenko
68a2f32c82 Cyrillic support added to RainbowDump 2024-07-22 14:54:18 +03:00
9 changed files with 134 additions and 151 deletions

View file

@ -39,19 +39,20 @@ public class RainbowDump {
private static final String ANSI_BLUE = "\u001B[34m"; private static final String ANSI_BLUE = "\u001B[34m";
private static StringBuilder stringBuilder; private static StringBuilder stringBuilder;
public static void hexDumpUTF8(byte[] byteArray){ public static void hexDumpUTF8(byte[] byteArray) {
stringBuilder = new StringBuilder(" -- RainbowDump --\n"); stringBuilder = new StringBuilder(" -- RainbowDump --\n");
if (byteArray == null || byteArray.length == 0) if (byteArray == null || byteArray.length == 0)
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);
printChars(byteArray, i); lastCharCyrillic = printChars(byteArray, i, lastCharCyrillic);
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;
@ -68,7 +69,7 @@ public class RainbowDump {
stringBuilder.append(" "); stringBuilder.append(" ");
} }
} }
stringBuilder.append(ANSI_GREEN+"| "+ANSI_RESET); stringBuilder.append(ANSI_GREEN + "| " + ANSI_RESET);
printChars(byteArray, byteArray.length); printChars(byteArray, byteArray.length);
stringBuilder.append("\n") stringBuilder.append("\n")
.append(ANSI_RESET) .append(ANSI_RESET)
@ -79,22 +80,44 @@ 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

@ -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);
}
}

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 = ". . ./tempPatchesPlayground/nintendo-switch-global-firmwares"; final String pathToFirmwares = "/tmp";
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)); System.out.println("Exported: "+kip1Provider.exportAsDecompressed(exportIntoFolder)+"\n"+exportIntoFolder);
break; break;
} }
} }

View file

@ -1,7 +1,6 @@
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;
@ -15,29 +14,18 @@ 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 { public class ExtractPackage2Test extends LKonPackage2Test {
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);
@ -55,22 +43,27 @@ public class ExtractPackage2Test {
Assertions.assertNotNull(system2FatNcaProvider); Assertions.assertNotNull(system2FatNcaProvider);
Assertions.assertNotNull(system2ExFatNcaProvider); Assertions.assertNotNull(system2ExFatNcaProvider);
System.out.println("FAT " + system2FatNcaProvider.getFile().getName()); System.out.println("\n" +
System.out.println("ExFAT " + system2ExFatNcaProvider.getFile().getName()); "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(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, referenceFat); testExportedFiles(system2FatNcaProvider, exportFat, REFERENCE_FAT);
testExportedFiles(system2ExFatNcaProvider, exportExFat, referenceExFat); testExportedFiles(system2ExFatNcaProvider, exportExFat, REFERENCE_EXFAT);
}
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(pathToFirmware); File firmware = new File(PATH_TO_FIRMWARE);
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);
@ -79,7 +72,7 @@ public class ExtractPackage2Test {
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(pathToFirmware+File.separator+ncaFileName); File nca = new File(PATH_TO_FIRMWARE +File.separator+ncaFileName);
NCAProvider provider = new NCAProvider(nca, keyChainHolder.getRawKeySet()); NCAProvider provider = new NCAProvider(nca, keyChainHolder.getRawKeySet());
ncaProviders.add(provider); 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 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(); System.out.println("\n" +
System.out.println("Reference : " + referenceFilePath); "\nReference : " + referenceFilePath +
System.out.println("Own #1 : " + myFilePath1); "\nOwn #1 : " + myFilePath1 +
System.out.println("Own #2 : " + myFilePath2); "\nOwn #2 : " + myFilePath2);
romFsProvider.exportContent(exportIntoFolder, romFsProvider.getRootEntry()); romFsProvider.exportContent(exportIntoFolder, romFsProvider.getRootEntry());
long referenceCrc32 = calculateReferenceCRC32(referenceFilePath); long referenceCrc32 = calculateReferenceCRC32(referenceFilePath);

View file

@ -1,7 +1,6 @@
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,19 +26,7 @@ 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 { public class Ini1ExtractTest extends LKonPackage2Test {
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{
@ -61,22 +48,18 @@ public class Ini1ExtractTest {
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() +
System.out.println("ExFAT " + system2ExFatNcaProvider.getFile().getName()); "\nExFAT " + 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, referenceFat); testExportedFiles(system2FatNcaProvider, exportFat, REFERENCE_FAT);
testExportedFiles(system2ExFatNcaProvider, exportExFat, referenceExFat); testExportedFiles(system2ExFatNcaProvider, exportExFat, REFERENCE_EXFAT);
}
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(pathToFirmware); File firmware = new File(PATH_TO_FIRMWARE);
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);
@ -85,7 +68,7 @@ public class Ini1ExtractTest {
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(pathToFirmware+File.separator+ncaFileName); File nca = new File(PATH_TO_FIRMWARE +File.separator+ncaFileName);
NCAProvider provider = new NCAProvider(nca, keyChainHolder.getRawKeySet()); NCAProvider provider = new NCAProvider(nca, keyChainHolder.getRawKeySet());
ncaProviders.add(provider); ncaProviders.add(provider);
} }
@ -112,9 +95,9 @@ public class Ini1ExtractTest {
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(); System.out.println("\n" +
System.out.println("Reference : " + referenceFilePath); "\nReference : " + referenceFilePath +
System.out.println("Own : " + myFilePath); "\nOwn : " + myFilePath);
long referenceCrc32 = calculateReferenceCRC32(referenceFilePath); long referenceCrc32 = calculateReferenceCRC32(referenceFilePath);
romFsProvider.exportContent(exportIntoFolder, package2FileSystemEntry); romFsProvider.exportContent(exportIntoFolder, package2FileSystemEntry);

View file

@ -1,7 +1,6 @@
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;
@ -24,23 +23,10 @@ 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 { public class KernelBinExtractTest extends LKonPackage2Test {
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);
@ -58,22 +44,18 @@ public class KernelBinExtractTest {
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() +
System.out.println("ExFAT " + system2ExFatNcaProvider.getFile().getName()); "\nExFAT " + 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, referenceFat); testExportedFiles(system2FatNcaProvider, exportFat, REFERENCE_FAT);
testExportedFiles(system2ExFatNcaProvider, exportExFat, referenceExFat); testExportedFiles(system2ExFatNcaProvider, exportExFat, REFERENCE_EXFAT);
}
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(pathToFirmware); File firmware = new File(PATH_TO_FIRMWARE);
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);
@ -82,7 +64,7 @@ public class KernelBinExtractTest {
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(pathToFirmware+File.separator+ncaFileName); File nca = new File(PATH_TO_FIRMWARE +File.separator+ncaFileName);
NCAProvider provider = new NCAProvider(nca, keyChainHolder.getRawKeySet()); NCAProvider provider = new NCAProvider(nca, keyChainHolder.getRawKeySet());
ncaProviders.add(provider); ncaProviders.add(provider);
} }
@ -109,9 +91,9 @@ public class KernelBinExtractTest {
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(); System.out.println("\n" +
System.out.println("Reference : " + referenceFilePath); "\nReference : " + referenceFilePath +
System.out.println("Own : " + myFilePath); "\nOwn : " + myFilePath);
long referenceCrc32 = calculateReferenceCRC32(referenceFilePath); long referenceCrc32 = calculateReferenceCRC32(referenceFilePath);
romFsProvider.exportContent(exportIntoFolder, package2FileSystemEntry); romFsProvider.exportContent(exportIntoFolder, package2FileSystemEntry);

View file

@ -1,7 +1,6 @@
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;
@ -29,23 +28,10 @@ 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 { public class Kip1ExtractDecompressedTest extends LKonPackage2Test {
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);
@ -63,22 +49,18 @@ public class Kip1ExtractDecompressedTest {
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() +
System.out.println("ExFAT " + system2ExFatNcaProvider.getFile().getName()); "\nExFAT " + 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, referenceFat); testExportedFiles(system2FatNcaProvider, exportFat, REFERENCE_FAT);
testExportedFiles(system2ExFatNcaProvider, exportExFat, referenceExFat); testExportedFiles(system2ExFatNcaProvider, exportExFat, REFERENCE_EXFAT);
}
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(pathToFirmware); File firmware = new File(PATH_TO_FIRMWARE);
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);
@ -87,7 +69,7 @@ public class Kip1ExtractDecompressedTest {
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(pathToFirmware+File.separator+ncaFileName); File nca = new File(PATH_TO_FIRMWARE +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,7 +1,6 @@
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,23 +27,10 @@ import java.util.zip.CRC32;
* 2. KIP1 extracted from NCA file via streams * 2. KIP1 extracted from NCA file via streams
* */ * */
public class Kip1ExtractTest { public class Kip1ExtractTest extends LKonPackage2Test {
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);
@ -62,22 +48,18 @@ public class Kip1ExtractTest {
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() +
System.out.println("ExFAT " + system2ExFatNcaProvider.getFile().getName()); "\nExFAT " + 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, referenceFat); testExportedFiles(system2FatNcaProvider, exportFat, REFERENCE_FAT);
testExportedFiles(system2ExFatNcaProvider, exportExFat, referenceExFat); testExportedFiles(system2ExFatNcaProvider, exportExFat, REFERENCE_EXFAT);
}
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(pathToFirmware); File firmware = new File(PATH_TO_FIRMWARE);
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);
@ -86,7 +68,7 @@ public class Kip1ExtractTest {
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(pathToFirmware+File.separator+ncaFileName); File nca = new File(PATH_TO_FIRMWARE +File.separator+ncaFileName);
NCAProvider provider = new NCAProvider(nca, keyChainHolder.getRawKeySet()); NCAProvider provider = new NCAProvider(nca, keyChainHolder.getRawKeySet());
ncaProviders.add(provider); ncaProviders.add(provider);
} }
@ -113,9 +95,9 @@ public class Kip1ExtractTest {
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(
System.out.println("Reference : " + referenceFilePath); "\nReference : " + referenceFilePath +
System.out.println("Own : " + myFilePath); "\nOwn : " + myFilePath);
long referenceCrc32 = calculateReferenceCRC32(referenceFilePath); long referenceCrc32 = calculateReferenceCRC32(referenceFilePath);
romFsProvider.exportContent(exportIntoFolder, package2FileSystemEntry); romFsProvider.exportContent(exportIntoFolder, package2FileSystemEntry);

View 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();
}