From 0e9ff44746a3a3f92927caddc7de65c82c020dce Mon Sep 17 00:00:00 2001 From: Aurora Date: Mon, 11 Apr 2016 22:16:51 +0200 Subject: [PATCH] Made N3DS >9.6 key generation version independent --- source/crypto.c | 10 +++++----- source/firm.c | 10 +++++----- source/patches.c | 4 ++-- source/patches.h | 4 ++-- source/screeninit.c | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/source/crypto.c b/source/crypto.c index e072be0..6601f6a 100755 --- a/source/crypto.c +++ b/source/crypto.c @@ -379,10 +379,10 @@ void arm9Loader(u8 *arm9Section, u32 mode) memcpy(arm9BinCTR, arm9Section + 0x20, 0x10); //Calculate the size of the ARM9 binary - u32 size = 0; + u32 arm9BinSize = 0; //http://stackoverflow.com/questions/12791077/atoi-implementation-in-c for(u8 *tmp = arm9Section + 0x30; *tmp; tmp++) - size = (size << 3) + (size << 1) + (*tmp) - '0'; + arm9BinSize = (arm9BinSize << 3) + (arm9BinSize << 1) + (*tmp) - '0'; if(mode) { @@ -401,13 +401,13 @@ void arm9Loader(u8 *arm9Section, u32 mode) aes_use_keyslot(arm9BinSlot); //Decrypt arm9bin - aes(arm9Section + 0x800, arm9Section + 0x800, size/AES_BLOCK_SIZE, arm9BinCTR, AES_CTR_MODE, AES_INPUT_BE | AES_INPUT_NORMAL); + aes(arm9Section + 0x800, arm9Section + 0x800, arm9BinSize / AES_BLOCK_SIZE, arm9BinCTR, AES_CTR_MODE, AES_INPUT_BE | AES_INPUT_NORMAL); //Set >=9.6 KeyXs if(mode) { - u8 *keyData = arm9Section + 0x89814; - u8 *decKey = keyData + 0x10; + u8 keyData[] = {0xDD, 0xDA, 0xA4, 0xC6, 0x2C, 0xC4, 0x50, 0xE9, 0xDA, 0xB6, 0x9B, 0x0D, 0x9D, 0x2A, 0x21, 0x98}; + u8 decKey[0x10]; //Set keys 0x19..0x1F keyXs aes_use_keyslot(0x11); diff --git a/source/firm.c b/source/firm.c index c55a447..a21c280 100755 --- a/source/firm.c +++ b/source/firm.c @@ -277,7 +277,7 @@ static inline void patchNativeFirm(u32 nandType, u32 emuHeader, u32 a9lhInstalle u32 unitInfoOffset; getUnitInfoValueSet(arm9Section, section[2].size, &unitInfoOffset); - *((u8*)unitInfoOffset + 3) = unitInfoPatch[0]; + *((u8*)unitInfoOffset + 3) = unitInfoPatch; } //Replace the FIRM loader with the injector @@ -286,11 +286,11 @@ static inline void patchNativeFirm(u32 nandType, u32 emuHeader, u32 a9lhInstalle static inline void patchEmuNAND(u8 *arm9Section, u8 *proc9Offset, u32 emuHeader) { - //Copy nandType code + //Copy emuNAND code void *emuCodeOffset = getEmuCode(proc9Offset); memcpy(emuCodeOffset, emunand, emunand_size); - //Add the data of the found nandType + //Add the data of the found emuNAND u32 *pos_offset = (u32 *)memsearch(emuCodeOffset, "NAND", emunand_size, 4); u32 *pos_header = (u32 *)memsearch(emuCodeOffset, "NCSD", emunand_size, 4); *pos_offset = emuOffset; @@ -304,7 +304,7 @@ static inline void patchEmuNAND(u8 *arm9Section, u8 *proc9Offset, u32 emuHeader) u32 branchOffset = (u32)emuCodeOffset - (u32)firm - section[2].offset + (u32)section[2].address; - //Add emunand hooks + //Add emuNAND hooks u32 emuRead, emuWrite; @@ -425,4 +425,4 @@ static inline void launchFirm(u32 bootType) //Final jump to arm9 kernel ((void (*)())firm->arm9Entry)(); -} +} \ No newline at end of file diff --git a/source/patches.c b/source/patches.c index 85fafb6..407ef25 100644 --- a/source/patches.c +++ b/source/patches.c @@ -19,7 +19,7 @@ const u16 sigPatch[2] = {0x2000, 0x4770}; const u16 writeBlock[2] = {0x2000, 0x46C0}; -const u8 unitInfoPatch[1] = {0xE3}; +const u8 unitInfoPatch = 0xE3; /************************************************** * Functions @@ -83,4 +83,4 @@ void getUnitInfoValueSet(u8 *pos, u32 size, u32 *off) const u8 pattern[] = {0x01, 0x10, 0xA0, 0x13}; *off = (u32)memsearch(pos, pattern, size, 4); -} +} \ No newline at end of file diff --git a/source/patches.h b/source/patches.h index dfa29e0..41485f1 100644 --- a/source/patches.h +++ b/source/patches.h @@ -15,7 +15,7 @@ const u32 mpuPatch[3]; const u16 nandRedir[2]; const u16 sigPatch[2]; const u16 writeBlock[2]; -const u8 unitInfoPatch[1]; +const u8 unitInfoPatch; /************************************************** * Functions @@ -26,4 +26,4 @@ void *getReboot(u8 *pos, u32 size); u32 getfOpen(u8 *proc9Offset, void *rebootOffset); u16 *getFirmWrite(u8 *pos, u32 size); void getLoader(u8 *pos, u32 size, u32 *loaderOffset, u32 *loaderSize); -void getUnitInfoValueSet(u8 *pos, u32 size, u32* off); +void getUnitInfoValueSet(u8 *pos, u32 size, u32* off); \ No newline at end of file diff --git a/source/screeninit.c b/source/screeninit.c index 28baae2..04fb723 100644 --- a/source/screeninit.c +++ b/source/screeninit.c @@ -32,7 +32,7 @@ void deinitScreens(void) *(vu32 *)0x10202A44 = 0; *(vu32 *)0x10202244 = 0; *(vu32 *)0x10202014 = 0; - + //Wait for the entry to be set while(!*arm11Entry);