forked from Mirror/GodMode9
Inject essential backup to NAND on safe restore
This commit is contained in:
parent
56aff4dd4c
commit
f76c753340
@ -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;
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user