diff --git a/source/godmode.c b/source/godmode.c index 6c66878..3b31709 100644 --- a/source/godmode.c +++ b/source/godmode.c @@ -226,7 +226,7 @@ u32 SdFormatMenu(void) { return 1; } - if (*(vu32*) 0x101401C0 == 0) { + if (CheckA9lh()) { InitSDCardFS(); // on A9LH: copy the payload from mem to SD root FileSetData("0:/arm9loaderhax.bin", (u8*) 0x23F00000, 0x40000, 0, true); DeinitSDCardFS(); diff --git a/source/nand/nand.c b/source/nand/nand.c index 4dd3341..5ffe9f9 100644 --- a/source/nand/nand.c +++ b/source/nand/nand.c @@ -111,7 +111,7 @@ bool InitNandCrypto(void) { // part #0: KeyX / KeyY for secret sector 0x96 // on a9lh this MUST be run before accessing the SHA register in any other way - if ((*(u32*) 0x101401C0) == 0) { // for a9lh + if (CheckA9lh()) { // for a9lh // store the current SHA256 from register memcpy(OtpSha256, (void*)REG_SHAHASH, 32); } else { @@ -138,7 +138,7 @@ bool InitNandCrypto(void) // part #2: TWL KEY // see: https://www.3dbrew.org/wiki/Memory_layout#ARM9_ITCM - if ((*(vu32*) 0x101401C0) == 0) { // only for a9lh + if (CheckA9lh()) { // only for a9lh u32* TwlCustId = (u32*) (0x01FFB808); u8 TwlKeyX[16]; u8 TwlKeyY[16]; @@ -165,7 +165,7 @@ bool InitNandCrypto(void) // part #3: CTRNAND N3DS KEY // thanks AuroraWright and Gelex for advice on this // see: https://github.com/AuroraWright/Luma3DS/blob/master/source/crypto.c#L347 - if ((*(vu32*) 0x101401C0) == 0) { // only for a9lh + if (CheckA9lh()) { // only for a9lh u8 ctr[16] __attribute__((aligned(32))); u8 keyY[16] __attribute__((aligned(32))); u8 header[0x200]; @@ -243,6 +243,11 @@ bool CheckSector0x96Crypto(void) return !(memcmp(OtpSha256, zeroes, 32) == 0); } +bool CheckA9lh(void) +{ + return ((*(vu32*) 0x101401C0) == 0); +} + void CryptNand(u8* buffer, u32 sector, u32 count, u32 keyslot) { u32 mode = (sector >= (0x0B100000 / 0x200)) ? AES_CNT_CTRNAND_MODE : AES_CNT_TWLNAND_MODE; diff --git a/source/nand/nand.h b/source/nand/nand.h index 9aa6159..b73f549 100644 --- a/source/nand/nand.h +++ b/source/nand/nand.h @@ -13,6 +13,7 @@ bool LoadKeyFromFile(const char* folder, u8* keydata, u32 keyslot, char type, ch bool InitNandCrypto(void); bool CheckSlot0x05Crypto(void); bool CheckSector0x96Crypto(void); +bool CheckA9lh(void); void CryptNand(u8* buffer, u32 sector, u32 count, u32 keyslot); void CryptSector0x96(u8* buffer, bool encrypt); diff --git a/source/virtual/vnand.c b/source/virtual/vnand.c index 5acd0fc..d9e3ece 100644 --- a/source/virtual/vnand.c +++ b/source/virtual/vnand.c @@ -59,7 +59,7 @@ bool ReadVNandDir(VirtualFile* vfile, u32 nand_src) { continue; // keyslot 0x05 not properly set up if ((vfile->flags & VFLAG_NEEDS_OTP) && !CheckSector0x96Crypto()) return false; // sector 0x96 crypto not set up - if (!(nand_src & VRT_SYSNAND) || (*(vu32*) 0x101401C0)) + if (!(nand_src & VRT_SYSNAND) || !CheckA9lh()) vfile->flags &= ~VFLAG_A9LH_AREA; // flag is meaningless outside of A9LH / SysNAND if (vfile->flags & VFLAG_NAND_SIZE) { if ((nand_src != NAND_SYSNAND) && (GetNandSizeSectors(NAND_SYSNAND) != GetNandSizeSectors(nand_src)))