feat: Add support for encrypted NCSD

Missing version 1 support and seeded crypto but that would be enough for now.
This commit is contained in:
Mary 2023-06-19 23:13:38 +02:00
parent 2e5bc0cb14
commit 86dd7f54f5
8 changed files with 305 additions and 138 deletions

View file

@ -133,6 +133,8 @@ std::optional<u32> NCCHArchive::readFile(FileSession* file, u64 offset, u32 size
auto cxi = mem.getCXI();
IOFile& ioFile = mem.CXIFile;
NCCH::FSInfo fsInfo;
// Seek to file offset depending on if we're reading from RomFS, ExeFS, etc
switch (type) {
case PathType::RomFS: {
@ -142,9 +144,8 @@ std::optional<u32> NCCHArchive::readFile(FileSession* file, u64 offset, u32 size
Helpers::panic("Tried to read from NCCH with too big of an offset");
}
if (!ioFile.seek(cxi->fileOffset + romFSOffset + offset + 0x1000)) {
Helpers::panic("Failed to seek while reading from RomFS");
}
fsInfo = cxi->romFS;
offset += 0x1000;
break;
}
@ -153,7 +154,7 @@ std::optional<u32> NCCHArchive::readFile(FileSession* file, u64 offset, u32 size
}
std::unique_ptr<u8[]> data(new u8[size]);
auto [success, bytesRead] = ioFile.readBytes(&data[0], size);
auto [success, bytesRead] = cxi->readFromFile(ioFile, fsInfo, &data[0], offset, size);
if (!success) {
Helpers::panic("Failed to read from NCCH archive");

View file

@ -71,6 +71,8 @@ std::optional<u32> SelfNCCHArchive::readFile(FileSession* file, u64 offset, u32
auto cxi = mem.getCXI();
IOFile& ioFile = mem.CXIFile;
NCCH::FSInfo fsInfo;
// Seek to file offset depending on if we're reading from RomFS, ExeFS, etc
switch (type) {
case PathType::RomFS: {
@ -80,9 +82,8 @@ std::optional<u32> SelfNCCHArchive::readFile(FileSession* file, u64 offset, u32
Helpers::panic("Tried to read from SelfNCCH with too big of an offset");
}
if (!ioFile.seek(cxi->fileOffset + romFSOffset + offset + 0x1000)) {
Helpers::panic("Failed to seek while reading from RomFS");
}
fsInfo = cxi->romFS;
offset += 0x1000;
break;
}
@ -93,9 +94,7 @@ std::optional<u32> SelfNCCHArchive::readFile(FileSession* file, u64 offset, u32
Helpers::panic("Tried to read from SelfNCCH with too big of an offset");
}
if (!ioFile.seek(cxi->fileOffset + exeFSOffset + offset)) { // TODO: Not sure if this needs the + 0x1000
Helpers::panic("Failed to seek while reading from ExeFS");
}
fsInfo = cxi->exeFS;
break;
}
@ -104,7 +103,7 @@ std::optional<u32> SelfNCCHArchive::readFile(FileSession* file, u64 offset, u32
}
std::unique_ptr<u8[]> data(new u8[size]);
auto [success, bytesRead] = ioFile.readBytes(&data[0], size);
auto [success, bytesRead] = cxi->readFromFile(ioFile, fsInfo, &data[0], offset, size);
if (!success) {
Helpers::panic("Failed to read from SelfNCCH archive");