#pragma once #include "common.h" #define BUFFER_ADDRESS ((u8*) 0x21000000) // buffer must not be used for anything else! #define BUFFER_MAX_SIZE (1 * 1024 * 1024) // must be a multiple of 0x40 (64) #define NAND_SECTOR_SIZE 0x200 #define SECTORS_PER_READ (BUFFER_MAX_SIZE / NAND_SECTOR_SIZE) #define P_TWLN (1<<0) #define P_TWLP (1<<1) #define P_AGBSAVE (1<<2) #define P_FIRM0 (1<<3) #define P_FIRM1 (1<<4) #define P_CTRNAND (1<<5) // return values for the CheckEmuNAND() function #define EMUNAND_NOT_READY 0 // must be zero #define EMUNAND_READY 1 #define EMUNAND_GATEWAY 2 #define EMUNAND_REDNAND 3 // these offsets are used by Multi EmuNAND Creator #define EMUNAND_MULTI_OFFSET_O3DS 0x00200000 #define EMUNAND_MULTI_OFFSET_N3DS 0x00400000 typedef struct { u32 keyslot; u32 setKeyY; u8 ctr[16]; u8 keyY[16]; u32 size; u32 mode; u8* buffer; } __attribute__((packed)) CryptBufferInfo; typedef struct { char name[16]; u8 magic[8]; u32 offset; u32 size; u32 keyslot; u32 mode; } __attribute__((packed)) PartitionInfo; PartitionInfo* GetPartitionInfo(u32 partition_id); u32 CheckEmuNand(void); void SetNand(bool set_emunand, u32 base_sector); u32 GetNandCtr(u8* ctr, u32 offset); u32 CryptBuffer(CryptBufferInfo *info); int ReadNandSectors(u32 sector_no, u32 numsectors, u8 *out); int WriteNandSectors(u32 sector_no, u32 numsectors, u8 *in); u32 GetNandSize(void); u32 DecryptNandToMem(u8* buffer, u32 offset, u32 size, PartitionInfo* partition); u32 EncryptMemToNand(u8* buffer, u32 offset, u32 size, PartitionInfo* partition);