From 9d84a92b1f7270342571fcc4ed1717c82037bed7 Mon Sep 17 00:00:00 2001 From: Aurora Date: Mon, 26 Sep 2016 13:53:58 +0200 Subject: [PATCH] Minor stuff --- source/crypto.c | 23 ++++++++++------------- source/crypto.h | 2 +- source/firm.c | 10 +++++----- source/firm.h | 2 +- source/fs.c | 2 +- source/fs.h | 2 +- 6 files changed, 19 insertions(+), 22 deletions(-) diff --git a/source/crypto.c b/source/crypto.c index 82fff5b..6966053 100755 --- a/source/crypto.c +++ b/source/crypto.c @@ -349,19 +349,16 @@ u32 ctrNandRead(u32 sector, u32 sectorCount, u8 *outbuf) void set6x7xKeys(void) { - if(!isDevUnit) - { - const u8 __attribute__((aligned(4))) keyX0x25[AES_BLOCK_SIZE] = {0xCE, 0xE7, 0xD8, 0xAB, 0x30, 0xC0, 0x0D, 0xAE, 0x85, 0x0E, 0xF5, 0xE3, 0x82, 0xAC, 0x5A, 0xF3}; - const u8 __attribute__((aligned(4))) keyY0x2F[AES_BLOCK_SIZE] = {0xC3, 0x69, 0xBA, 0xA2, 0x1E, 0x18, 0x8A, 0x88, 0xA9, 0xAA, 0x94, 0xE5, 0x50, 0x6A, 0x9F, 0x16}; + const u8 __attribute__((aligned(4))) keyX0x25[AES_BLOCK_SIZE] = {0xCE, 0xE7, 0xD8, 0xAB, 0x30, 0xC0, 0x0D, 0xAE, 0x85, 0x0E, 0xF5, 0xE3, 0x82, 0xAC, 0x5A, 0xF3}; + const u8 __attribute__((aligned(4))) keyY0x2F[AES_BLOCK_SIZE] = {0xC3, 0x69, 0xBA, 0xA2, 0x1E, 0x18, 0x8A, 0x88, 0xA9, 0xAA, 0x94, 0xE5, 0x50, 0x6A, 0x9F, 0x16}; - aes_setkey(0x25, keyX0x25, AES_KEYX, AES_INPUT_BE | AES_INPUT_NORMAL); - aes_setkey(0x2F, keyY0x2F, AES_KEYY, AES_INPUT_BE | AES_INPUT_NORMAL); + aes_setkey(0x25, keyX0x25, AES_KEYX, AES_INPUT_BE | AES_INPUT_NORMAL); + aes_setkey(0x2F, keyY0x2F, AES_KEYY, AES_INPUT_BE | AES_INPUT_NORMAL); - /* [3dbrew] The first 0x10-bytes are checked by the v6.0/v7.0 NATIVE_FIRM keyinit function, - when non-zero it clears this block and continues to do the key generation. - Otherwise when this block was already all-zero, it immediately returns. */ - memset32((void *)0x01FFCD00, 0, 0x10); - } + /* [3dbrew] The first 0x10-bytes are checked by the v6.0/v7.0 NATIVE_FIRM keyinit function, + when non-zero it clears this block and continues to do the key generation. + Otherwise when this block was already all-zero, it immediately returns. */ + memset32((void *)0x01FFCD00, 0, 0x10); } void decryptExeFs(u8 *inbuf) @@ -382,8 +379,8 @@ void decryptExeFs(u8 *inbuf) void decryptNusFirm(const u8 *inbuf, u8 *outbuf, u32 ncchSize) { const u8 keyY0x3D[AES_BLOCK_SIZE] = {0x0C, 0x76, 0x72, 0x30, 0xF0, 0x99, 0x8F, 0x1C, 0x46, 0x82, 0x82, 0x02, 0xFA, 0xAC, 0xBE, 0x4C}; - u8 __attribute__((aligned(4))) cetkIv[AES_BLOCK_SIZE] = {0}; u8 __attribute__((aligned(4))) titleKey[AES_BLOCK_SIZE]; + u8 __attribute__((aligned(4))) cetkIv[AES_BLOCK_SIZE] = {0}; memcpy(titleKey, inbuf + 0x1BF, sizeof(titleKey)); memcpy(cetkIv, inbuf + 0x1DC, 8); @@ -485,7 +482,7 @@ void computePinHash(u8 *outbuf, const u8 *inbuf) u8 __attribute__((aligned(4))) cid[AES_BLOCK_SIZE]; u8 __attribute__((aligned(4))) cipherText[AES_BLOCK_SIZE]; - if(!didShaHashBackup) + if(isA9lh && !didShaHashBackup) { memcpy(shaHashBackup, (void *)REG_SHA_HASH, sizeof(shaHashBackup)); didShaHashBackup = true; diff --git a/source/crypto.h b/source/crypto.h index 133d6bc..b64aaa7 100755 --- a/source/crypto.h +++ b/source/crypto.h @@ -102,7 +102,7 @@ #define SHA_1_HASH_SIZE (160 / 8) extern u32 emuOffset; -extern bool isN3DS, isDevUnit; +extern bool isN3DS, isDevUnit, isA9lh; extern FirmwareSource firmSource; void ctrNandInit(void); diff --git a/source/firm.c b/source/firm.c index 34ac415..a33e48e 100755 --- a/source/firm.c +++ b/source/firm.c @@ -45,13 +45,13 @@ static const firmSectionHeader *section; u32 emuOffset; bool isN3DS, isDevUnit, + isA9lh, isFirmlaunch; CfgData configData; FirmwareSource firmSource; void main(void) { - bool isA9lh; u32 configTemp, emuHeader; FirmwareType firmType; @@ -253,7 +253,7 @@ void main(void) switch(firmType) { case NATIVE_FIRM: - patchNativeFirm(firmVersion, nandType, emuHeader, isA9lh, devMode); + patchNativeFirm(firmVersion, nandType, emuHeader, devMode); break; case SAFE_FIRM: case NATIVE_FIRM1X2X: @@ -338,7 +338,7 @@ static inline u32 loadFirm(FirmwareType *firmType, FirmwareSource firmSource, bo return firmVersion; } -static inline void patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32 emuHeader, bool isA9lh, u32 devMode) +static inline void patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32 emuHeader, u32 devMode) { u8 *arm9Section = (u8 *)firm + section[2].offset, *arm11Section1 = (u8 *)firm + section[1].offset; @@ -350,8 +350,8 @@ static inline void patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32 firm->arm9Entry = (u8 *)0x801B01C; } - //Sets the 7.x NCCH KeyX and the 6.x gamecard save data KeyY on >= 6.0 O3DS FIRMs, if not using A9LH - else if(!isA9lh && firmVersion >= 0x29) set6x7xKeys(); + //Sets the 7.x NCCH KeyX and the 6.x gamecard save data KeyY on >= 6.0 O3DS FIRMs, if not using A9LH or a dev unit + else if(!isA9lh && firmVersion >= 0x29 && !isDevUnit) set6x7xKeys(); //Find the Process9 .code location, size and memory address u32 process9Size, diff --git a/source/firm.h b/source/firm.h index e17de99..8cd68ef 100644 --- a/source/firm.h +++ b/source/firm.h @@ -48,7 +48,7 @@ typedef struct firmHeader { } firmHeader; static inline u32 loadFirm(FirmwareType *firmType, FirmwareSource firmSource, bool loadFromSd); -static inline void patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32 emuHeader, bool isA9lh, u32 devMode); +static inline void patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32 emuHeader, u32 devMode); static inline void patchLegacyFirm(FirmwareType firmType, u32 firmVersion, u32 devMode); static inline void patch1x2xNativeAndSafeFirm(u32 devMode); static inline void copySection0AndInjectSystemModules(FirmwareType firmType, bool loadFromSd); diff --git a/source/fs.c b/source/fs.c index a71df19..40daa11 100644 --- a/source/fs.c +++ b/source/fs.c @@ -139,7 +139,7 @@ void loadPayload(u32 pressed) { loaderAddress[1] = payloadSize; - restoreShaHashBackup(); + if(isA9lh) restoreShaHashBackup(); initScreens(); flushDCacheRange(loaderAddress, loader_bin_size); diff --git a/source/fs.h b/source/fs.h index bc5d6b8..0682fb5 100644 --- a/source/fs.h +++ b/source/fs.h @@ -26,7 +26,7 @@ #define PATTERN(a) a "_*.bin" -extern bool isN3DS; +extern bool isN3DS, isA9lh; void mountFs(void); u32 fileRead(void *dest, const char *path, u32 maxSize);