Introduce CheckA9lh() function

This commit is contained in:
d0k3 2016-11-15 23:12:14 +01:00
parent 924dd8216e
commit 943759bee9
4 changed files with 11 additions and 5 deletions

View File

@ -226,7 +226,7 @@ u32 SdFormatMenu(void) {
return 1; return 1;
} }
if (*(vu32*) 0x101401C0 == 0) { if (CheckA9lh()) {
InitSDCardFS(); // on A9LH: copy the payload from mem to SD root InitSDCardFS(); // on A9LH: copy the payload from mem to SD root
FileSetData("0:/arm9loaderhax.bin", (u8*) 0x23F00000, 0x40000, 0, true); FileSetData("0:/arm9loaderhax.bin", (u8*) 0x23F00000, 0x40000, 0, true);
DeinitSDCardFS(); DeinitSDCardFS();

View File

@ -111,7 +111,7 @@ bool InitNandCrypto(void)
{ {
// part #0: KeyX / KeyY for secret sector 0x96 // part #0: KeyX / KeyY for secret sector 0x96
// on a9lh this MUST be run before accessing the SHA register in any other way // 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 // store the current SHA256 from register
memcpy(OtpSha256, (void*)REG_SHAHASH, 32); memcpy(OtpSha256, (void*)REG_SHAHASH, 32);
} else { } else {
@ -138,7 +138,7 @@ bool InitNandCrypto(void)
// part #2: TWL KEY // part #2: TWL KEY
// see: https://www.3dbrew.org/wiki/Memory_layout#ARM9_ITCM // 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); u32* TwlCustId = (u32*) (0x01FFB808);
u8 TwlKeyX[16]; u8 TwlKeyX[16];
u8 TwlKeyY[16]; u8 TwlKeyY[16];
@ -165,7 +165,7 @@ bool InitNandCrypto(void)
// part #3: CTRNAND N3DS KEY // part #3: CTRNAND N3DS KEY
// thanks AuroraWright and Gelex for advice on this // thanks AuroraWright and Gelex for advice on this
// see: https://github.com/AuroraWright/Luma3DS/blob/master/source/crypto.c#L347 // 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 ctr[16] __attribute__((aligned(32)));
u8 keyY[16] __attribute__((aligned(32))); u8 keyY[16] __attribute__((aligned(32)));
u8 header[0x200]; u8 header[0x200];
@ -243,6 +243,11 @@ bool CheckSector0x96Crypto(void)
return !(memcmp(OtpSha256, zeroes, 32) == 0); return !(memcmp(OtpSha256, zeroes, 32) == 0);
} }
bool CheckA9lh(void)
{
return ((*(vu32*) 0x101401C0) == 0);
}
void CryptNand(u8* buffer, u32 sector, u32 count, u32 keyslot) void CryptNand(u8* buffer, u32 sector, u32 count, u32 keyslot)
{ {
u32 mode = (sector >= (0x0B100000 / 0x200)) ? AES_CNT_CTRNAND_MODE : AES_CNT_TWLNAND_MODE; u32 mode = (sector >= (0x0B100000 / 0x200)) ? AES_CNT_CTRNAND_MODE : AES_CNT_TWLNAND_MODE;

View File

@ -13,6 +13,7 @@ bool LoadKeyFromFile(const char* folder, u8* keydata, u32 keyslot, char type, ch
bool InitNandCrypto(void); bool InitNandCrypto(void);
bool CheckSlot0x05Crypto(void); bool CheckSlot0x05Crypto(void);
bool CheckSector0x96Crypto(void); bool CheckSector0x96Crypto(void);
bool CheckA9lh(void);
void CryptNand(u8* buffer, u32 sector, u32 count, u32 keyslot); void CryptNand(u8* buffer, u32 sector, u32 count, u32 keyslot);
void CryptSector0x96(u8* buffer, bool encrypt); void CryptSector0x96(u8* buffer, bool encrypt);

View File

@ -59,7 +59,7 @@ bool ReadVNandDir(VirtualFile* vfile, u32 nand_src) {
continue; // keyslot 0x05 not properly set up continue; // keyslot 0x05 not properly set up
if ((vfile->flags & VFLAG_NEEDS_OTP) && !CheckSector0x96Crypto()) if ((vfile->flags & VFLAG_NEEDS_OTP) && !CheckSector0x96Crypto())
return false; // sector 0x96 crypto not set up 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 vfile->flags &= ~VFLAG_A9LH_AREA; // flag is meaningless outside of A9LH / SysNAND
if (vfile->flags & VFLAG_NAND_SIZE) { if (vfile->flags & VFLAG_NAND_SIZE) {
if ((nand_src != NAND_SYSNAND) && (GetNandSizeSectors(NAND_SYSNAND) != GetNandSizeSectors(nand_src))) if ((nand_src != NAND_SYSNAND) && (GetNandSizeSectors(NAND_SYSNAND) != GetNandSizeSectors(nand_src)))