Only reserve space in trimmed NDS files for RSA key if it exists (#804)

This commit is contained in:
Pk11 2023-04-09 13:38:35 -05:00 committed by GitHub
parent 64414e12ab
commit cae3d272d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 5 deletions

View File

@ -254,7 +254,7 @@ u32 InitCartRead(CartData* cdata) {
if (nds_header->device_capacity >= 15) return 1; // too big, not valid
if (cdata->cart_size == 0)
cdata->cart_size = (128 * 1024) << nds_header->device_capacity;
cdata->data_size = nds_header->ntr_rom_size + 0x88;
cdata->data_size = nds_header->ntr_rom_size;
cdata->arm9i_rom_offset = 0;
// TWL header
@ -273,6 +273,15 @@ u32 InitCartRead(CartData* cdata) {
NTR_CmdReadHeader(cdata->storage);
if (!NTR_Secure_Init(cdata->storage, NULL, Cart_GetID(), 1)) return 1;
}
} else {
// Check if immediately after the reported cart size
// is the magic number string 'ac' (auth code).
// If found, add 0x88 bytes for the download play RSA key.
u16 rsaMagic;
ReadCartBytes(&rsaMagic, cdata->data_size, 2, cdata, false);
if(rsaMagic == 0x6361) {
cdata->data_size += 0x88;
}
}
// store encrypted secure area

View File

@ -3296,12 +3296,21 @@ u64 GetGameFileTrimmedSize(const char* path) {
trimsize = GetAnyFileTrimmedSize(path);
} else if (filetype & GAME_NDS) {
TwlHeader hdr;
if (fvx_qread(path, &hdr, 0, sizeof(TwlHeader), NULL) != FR_OK)
if (fvx_qread(path, &hdr, 0, sizeof(TwlHeader), NULL) != FR_OK) {
return 0;
if (hdr.unit_code != 0x00) // DSi or NDS+DSi
} if (hdr.unit_code != 0x00) { // DSi or NDS+DSi
trimsize = hdr.ntr_twl_rom_size;
else if (hdr.ntr_rom_size) // regular NDS
trimsize = hdr.ntr_rom_size + 0x88;
} else if (hdr.ntr_rom_size) { // regular NDS
trimsize = hdr.ntr_rom_size;
// Check if immediately after the reported cart size
// is the magic number string 'ac' (auth code).
// If found, add 0x88 bytes for the download play RSA key.
u16 rsaMagic;
if(fvx_qread(path, &rsaMagic, trimsize, 2, NULL) == FR_OK && rsaMagic == 0x6361) {
trimsize += 0x88;
}
}
} else {
u8 hdr[0x200];
if (fvx_qread(path, &hdr, 0, 0x200, NULL) != FR_OK)