mirror of
https://github.com/d0k3/GodMode9.git
synced 2026-05-30 22:36:55 +00:00
This also fixes #958 Original commits: * initial work on cart save crypto/wearleveling * add support for n3ds only save crypto * use existing crc16 impl for save blockmap * fix missing aeskey select for card2 save decrypt * fix old/new cart media being swapped * fix 1 MiB save chips / blockmap type 2 * move cart save wearleveling/crypto to separate file * try 2nd wearlevel header on fail + minor fixes * save_ctr: zero out savectx before reading fallback header
44 lines
1.2 KiB
C
44 lines
1.2 KiB
C
#pragma once
|
|
|
|
#include "common.h"
|
|
|
|
#define NCSD_MEDIA_UNIT 0x200
|
|
|
|
#define NCSD_CINFO_OFFSET 0x200
|
|
#define NCSD_CINFO_SIZE 0x1000
|
|
#define NCSD_DINFO_OFFSET 0x1200
|
|
#define NCSD_DINFO_SIZE 0x300
|
|
#define NCSD_CNT0_OFFSET 0x4000
|
|
|
|
// wrapper defines
|
|
#define DecryptNcsdSequential(data, offset, size) CryptNcsdSequential(data, offset, size, NCCH_NOCRYPTO)
|
|
#define EncryptNcsdSequential(data, offset, size, crypto) CryptNcsdSequential(data, offset, size, crypto)
|
|
|
|
typedef struct {
|
|
u32 offset;
|
|
u32 size;
|
|
} PACKED_STRUCT NcchPartition;
|
|
|
|
// see: https://www.3dbrew.org/wiki/NCSD#NCSD_header
|
|
typedef struct {
|
|
u8 signature[0x100];
|
|
u8 magic[4];
|
|
u32 size;
|
|
u64 mediaId;
|
|
u8 partitions_fs_type[8];
|
|
u8 partitions_crypto_type[8];
|
|
NcchPartition partitions[8];
|
|
u8 hash_exthdr[0x20];
|
|
u8 size_addhdr[0x4];
|
|
u8 sector_zero_offset[0x4];
|
|
u8 partition_flags[8];
|
|
u8 partitionId_table[8][8];
|
|
u8 reserved[0x2F];
|
|
u8 extra_save_keysel;
|
|
} PACKED_STRUCT NcsdHeader;
|
|
|
|
u32 ValidateNcsdHeader(NcsdHeader* header);
|
|
u32 ValidateNcsdSignature(NcsdHeader* header);
|
|
u64 GetNcsdTrimmedSize(NcsdHeader* header);
|
|
u32 CryptNcsdSequential(void* data, u32 offset_data, u32 size_data, u16 crypto);
|