Inject essential backup to NAND on safe restore

This commit is contained in:
d0k3 2017-02-21 22:12:36 +01:00
parent 56aff4dd4c
commit f76c753340
2 changed files with 23 additions and 13 deletions

View File

@ -1,6 +1,9 @@
#pragma once
#include "common.h"
#include "exefs.h"
#define ESSENTIAL_SECTOR 0x1 // start sector of the essential backup in NAND
// /rw/sys/LocalFriendCodeSeed_B (/_A) file
// see: http://3dbrew.org/wiki/Nandrw/sys/LocalFriendCodeSeed_B
@ -29,3 +32,16 @@ typedef struct {
u8 unknown;
char serial[0xF];
} __attribute__((packed)) SecureInfo;
// includes all essential system files
// (this is of our own making)
typedef struct {
ExeFsHeader header;
u8 nand_hdr[0x200];
SecureInfo secinfo;
u8 padding_secinfo[0x200 - sizeof(SecureInfo)];
MovableSed movable;
u8 padding_movable[0x200 - sizeof(MovableSed)];
LocalFriendCodeSeed frndseed;
u8 padding_frndseed[0x200 - sizeof(LocalFriendCodeSeed)];
} __attribute__((packed)) EssentialBackup;

View File

@ -2,8 +2,7 @@
#include "nand.h"
#include "firm.h"
#include "fatmbr.h"
#include "sysfiles.h" // for essential backup struct
#include "exefs.h" // for essential backup struct
#include "essentials.h" // for essential backup struct
#include "image.h"
#include "fsinit.h"
#include "fsperm.h"
@ -11,16 +10,6 @@
#include "ui.h"
#include "vff.h"
typedef struct {
ExeFsHeader header;
u8 nand_hdr[0x200];
SecureInfo secinfo;
u8 padding_secinfo[0x200 - sizeof(SecureInfo)];
MovableSed movable;
u8 padding_movable[0x200 - sizeof(MovableSed)];
LocalFriendCodeSeed frndseed;
u8 padding_frndseed[0x200 - sizeof(LocalFriendCodeSeed)];
} __attribute__((packed)) EssentialBackup;
u32 ReadNandFile(FIL* file, void* buffer, u32 sector, u32 count, u32 keyslot) {
u32 offset = sector * 0x200;
@ -211,6 +200,11 @@ u32 SafeRestoreNandDump(const char* path) {
}
if (!SetWritePermissions(PERM_SYS_LVL2, true)) return 1;
// inject essential backup to NAND
EssentialBackup* essential = (EssentialBackup*) TEMP_BUFFER;
if (BuildEssentialBackup("1:/nand.bin", essential) == 0)
WriteNandSectors((u8*) essential, ESSENTIAL_SECTOR, (sizeof(EssentialBackup) + 0x1FF) / 0x200, 0xFF, NAND_SYSNAND);
// open file, get size
if (fvx_open(&file, path, FA_READ | FA_OPEN_EXISTING) != FR_OK)
return 1;