mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-20 04:29:13 +12:00
[NCCH/NCSD] Pain
This commit is contained in:
parent
29241b41ce
commit
6b6cc7ca2f
3 changed files with 40 additions and 6 deletions
|
@ -3,23 +3,44 @@
|
|||
#include "memory.hpp"
|
||||
|
||||
bool NCCH::loadFromHeader(u8* header) {
|
||||
const u8* exheader = &header[0x200]; // Extended NCCH header
|
||||
|
||||
if (header[0x100] != 'N' || header[0x101] != 'C' || header[0x102] != 'C' || header[0x103] != 'H') {
|
||||
printf("Invalid header on NCCH\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
size = u64(*(u32*)&header[0x104]) * mediaUnit; // TODO: Maybe don't type pun because big endian will break
|
||||
exheaderSize = *(u32*)&header[0x180];
|
||||
|
||||
const u64 programID = *(u64*)&header[0x118];
|
||||
|
||||
// Read NCCH flags
|
||||
isNew3DS = header[0x188 + 4] == 2;
|
||||
mountRomFS = (header[0x188 + 7] & 0x1) != 0x1;
|
||||
fixedCryptoKey = (header[0x188 + 7] & 0x1) == 0x1;
|
||||
mountRomFS = (header[0x188 + 7] & 0x2) != 0x2;
|
||||
encrypted = (header[0x188 + 7] & 0x4) != 0x4;
|
||||
|
||||
compressExeFS = (exheader[0xD] & 1) != 0;
|
||||
stackSize = *(u32*)&exheader[0x1C];
|
||||
bssSize = *(u32*)&exheader[0x3C];
|
||||
bool encryptedExheader = encrypted;
|
||||
|
||||
if (fixedCryptoKey) {
|
||||
Helpers::panic("Fixed crypto keys for NCCH");
|
||||
}
|
||||
|
||||
if (exheaderSize != 0) {
|
||||
const u8* exheader = &header[0x200]; // Extended NCCH header
|
||||
const u64 jumpID = *(u64*)&exheader[0x1C0 + 0x8];
|
||||
|
||||
// TODO: How does this even work
|
||||
if (u32(programID) == u32(jumpID) && encryptedExheader) {
|
||||
printf("Exheader is supposedly ecrypted but not actually encrypted\n");
|
||||
encryptedExheader = false;
|
||||
} else if (encryptedExheader) {
|
||||
Helpers::panic("Encrypted exheader");
|
||||
}
|
||||
|
||||
compressExeFS = (exheader[0xD] & 1) != 0;
|
||||
stackSize = *(u32*)&exheader[0x1C];
|
||||
bssSize = *(u32*)&exheader[0x3C];
|
||||
}
|
||||
|
||||
printf("Stack size: %08X\nBSS size: %08X\n", stackSize, bssSize);
|
||||
|
||||
|
|
|
@ -64,5 +64,10 @@ std::optional<NCSD> Memory::loadNCSD(const std::filesystem::path& path) {
|
|||
}
|
||||
}
|
||||
|
||||
if (!ncsd.partitions[0].ncch.hasExtendedHeader()) {
|
||||
printf("NCSD's CXI doesn't have exheader?\n");
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return ncsd;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue