Include essential.exefs file in virtual NAND (if available)

This commit is contained in:
d0k3 2017-02-22 17:41:18 +01:00
parent e772d1b2f7
commit 12e9ca82d1
2 changed files with 18 additions and 3 deletions

View File

@ -3,7 +3,12 @@
#include "common.h" #include "common.h"
#include "exefs.h" #include "exefs.h"
#define ESSENTIAL_SECTOR 0x1 // start sector of the essential backup in NAND // start sector of the essential backup in NAND
// careful with this, essential backup should never reach sector 0x96
#define ESSENTIAL_SECTOR 0x1
// magic number for essential backup
#define ESSENTIAL_MAGIC 'n', 'a', 'n', 'd', '_', 'h', 'd', 'r', 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00
// /rw/sys/LocalFriendCodeSeed_B (/_A) file // /rw/sys/LocalFriendCodeSeed_B (/_A) file
// see: http://3dbrew.org/wiki/Nandrw/sys/LocalFriendCodeSeed_B // see: http://3dbrew.org/wiki/Nandrw/sys/LocalFriendCodeSeed_B

View File

@ -1,12 +1,14 @@
#include "vnand.h" #include "vnand.h"
#include "nand.h" #include "nand.h"
#include "agbsave.h" #include "agbsave.h"
#include "essentials.h"
#include "platform.h" #include "platform.h"
#define VFLAG_ON_O3DS NAND_TYPE_O3DS #define VFLAG_ON_O3DS NAND_TYPE_O3DS
#define VFLAG_ON_N3DS NAND_TYPE_N3DS #define VFLAG_ON_N3DS NAND_TYPE_N3DS
#define VFLAG_ON_NO3DS NAND_TYPE_NO3DS #define VFLAG_ON_NO3DS NAND_TYPE_NO3DS
#define VFLAG_ON_NAND (VFLAG_ON_O3DS | VFLAG_ON_N3DS | VFLAG_ON_NO3DS) #define VFLAG_ON_NAND (VFLAG_ON_O3DS | VFLAG_ON_N3DS | VFLAG_ON_NO3DS)
#define VFLAG_ESSENTIAL (1UL<<28)
#define VFLAG_GBA_VC (1UL<<29) #define VFLAG_GBA_VC (1UL<<29)
#define VFLAG_NEEDS_OTP (1UL<<30) #define VFLAG_NEEDS_OTP (1UL<<30)
#define VFLAG_NAND_SIZE (1UL<<31) #define VFLAG_NAND_SIZE (1UL<<31)
@ -32,8 +34,9 @@ static const VirtualFile vNandFileTemplates[] = {
{ "nand_hdr.bin" , 0x00000000, 0x00000200, 0xFF, VFLAG_ON_NAND }, { "nand_hdr.bin" , 0x00000000, 0x00000200, 0xFF, VFLAG_ON_NAND },
{ "twlmbr.bin" , 0x000001BE, 0x00000042, 0x03, VFLAG_ON_NAND }, { "twlmbr.bin" , 0x000001BE, 0x00000042, 0x03, VFLAG_ON_NAND },
{ "free0x01.bin" , 0x00000200, 0x00012A00, 0xFF, VFLAG_ON_NAND }, { "free0x01.bin" , 0x00000200, 0x00012A00, 0xFF, VFLAG_ON_NAND },
{ "free0x1D7800.bin" , 0x3AF00000, 0x00000000, 0xFF, VFLAG_ON_O3DS | VFLAG_NAND_SIZE }, { "essential.exefs" , 0x00000200, 0x00000000, 0xFF, VFLAG_ON_NAND | VFLAG_ESSENTIAL },
{ "free0x26C000.bin" , 0x4D800000, 0x00000000, 0xFF, VFLAG_ON_N3DS | VFLAG_ON_NO3DS | VFLAG_NAND_SIZE }, { "bonus0x1D7800.bin", 0x3AF00000, 0x00000000, 0xFF, VFLAG_ON_O3DS | VFLAG_NAND_SIZE },
{ "bonus0x26C000.bin", 0x4D800000, 0x00000000, 0xFF, VFLAG_ON_N3DS | VFLAG_ON_NO3DS | VFLAG_NAND_SIZE },
{ "gbavc.sav" , 0x0B100200, 0x00000000, 0x07, VFLAG_ON_NAND | VFLAG_GBA_VC }, { "gbavc.sav" , 0x0B100200, 0x00000000, 0x07, VFLAG_ON_NAND | VFLAG_GBA_VC },
}; };
@ -75,6 +78,13 @@ bool ReadVNandDir(VirtualFile* vfile, VirtualDir* vdir) { // uses a generic vdir
if (nand_size <= vfile->offset) continue; if (nand_size <= vfile->offset) continue;
vfile->size = nand_size - vfile->offset; vfile->size = nand_size - vfile->offset;
} }
if (vfile->flags & VFLAG_ESSENTIAL) {
const u8 magic[] = { ESSENTIAL_MAGIC };
u8 data[sizeof(magic)];
ReadNandBytes(data, vfile->offset, sizeof(magic), vfile->keyslot, nand_src);
if (memcmp(data, magic, sizeof(magic)) != 0) continue;
vfile->size = sizeof(EssentialBackup);
}
if (vfile->flags & VFLAG_GBA_VC) { if (vfile->flags & VFLAG_GBA_VC) {
if (CheckAgbSaveCmac(nand_src) != 0) continue; if (CheckAgbSaveCmac(nand_src) != 0) continue;
vfile->size = GetAgbSaveSize(nand_src); vfile->size = GetAgbSaveSize(nand_src);