diff --git a/arm9/source/firm.c b/arm9/source/firm.c index 6405308..1f44499 100755 --- a/arm9/source/firm.c +++ b/arm9/source/firm.c @@ -399,8 +399,8 @@ u32 patchNativeFirm(u32 firmVersion, FirmwareSource nandType, bool loadFromStora //Apply anti-anti-DG patches on 11.0+ if(firmVersion >= (ISN3DS ? 0x21 : 0x52)) ret += patchTitleInstallMinVersionChecks(process9Offset, process9Size, firmVersion); - //patch P9 AM ticket wrapper on 11.8+ to use 0 Key and IV, only on UNITINFO patch to prevent NIM from actually send any - if(doUnitinfoPatch && firmVersion >= (ISN3DS ? 0x35 : 0x64)) ret += patchP9AMTicketWrapperZeroKeyIV(process9Offset, process9Size); + //Patch P9 AM ticket wrapper on 11.8+ to use 0 Key and IV, only with UNITINFO patch on to prevent NIM from actually sending any + if(doUnitinfoPatch && firmVersion >= (ISN3DS ? 0x35 : 0x64)) ret += patchP9AMTicketWrapperZeroKeyIV(process9Offset, process9Size, firmVersion); //Apply UNITINFO patches if(doUnitinfoPatch) diff --git a/arm9/source/patches.c b/arm9/source/patches.c index ab75403..a81db25 100644 --- a/arm9/source/patches.c +++ b/arm9/source/patches.c @@ -549,6 +549,28 @@ u32 patchUnitInfoValueSet(u8 *pos, u32 size) return 0; } +u32 patchP9AMTicketWrapperZeroKeyIV(u8 *pos, u32 size, u32 firmVersion) +{ + static const u8 __rt_memclr_pattern[] = {0x00, 0x20, 0xA0, 0xE3, 0x04, 0x00, 0x51, 0xE3, 0x07, 0x00, 0x00, 0x3A}; + static const u8 pattern[] = {0x20, 0x21, 0xA6, 0xA8}; + + u32 function = (u32)memsearch(pos, __rt_memclr_pattern, size, sizeof(__rt_memclr_pattern)); + u32 *off = (u32 *)memsearch(pos, pattern, size, sizeof(pattern)); + + if(function == 0 || off == NULL) return firmVersion == 0xFFFFFFFF ? 0 : 1; + + s32 opjumpdistance = (s32)(function - ((u32)&off[2])) / 2; + + //Beyond limit + if(opjumpdistance < -0x1fffff || opjumpdistance > 0x1fffff) return 1; + + //r0 and r1 for old call are already correct for this one + //BLX __rt_memclr + off[1] = 0xE800F000U | (((u32)opjumpdistance & 0x7FF) << 16) | (((u32)opjumpdistance >> 11) & 0x3FF) | (((u32)opjumpdistance >> 21) & 0x400); + + return 0; +} + u32 patchLgySignatureChecks(u8 *pos, u32 size) { static const u8 pattern[] = {0x47, 0xC1, 0x17, 0x49}; @@ -667,25 +689,3 @@ u32 patchAgbBootSplash(u8 *pos, u32 size) return 0; } - -u32 patchP9AMTicketWrapperZeroKeyIV(u8* pos, u32 size) -{ - static const u8 __rt_memclr_pattern[] = {0x00, 0x20, 0xA0, 0xE3, 0x04, 0x00, 0x51, 0xE3, 0x07, 0x00, 0x00, 0x3A}; - static const u8 pattern[] = {0x20, 0x21, 0xA6, 0xA8}; - - u32 function = (u32)memsearch(pos, __rt_memclr_pattern, size, sizeof(__rt_memclr_pattern)); - u32 *off = (u32*)memsearch(pos, pattern, size, sizeof(pattern)); - - if(function == 0 || off == NULL) return 1; - - s32 opjumpdistance = (s32)(function - ((u32)&off[2])) / 2; - - //beyond limit - if(opjumpdistance < -0x1fffff || opjumpdistance > 0x1fffff) return 1; - - //r0 and r1 for old call are already correctly for this one - //BLX __rt_memclr - off[1] = 0xE800F000U | (((u32)opjumpdistance & 0x7FF) << 16) | (((u32)opjumpdistance >> 11) & 0x3FF) | (((u32)opjumpdistance >> 21) & 0x400); - - return 0; -} diff --git a/arm9/source/patches.h b/arm9/source/patches.h index b095045..f17bdc7 100644 --- a/arm9/source/patches.h +++ b/arm9/source/patches.h @@ -56,6 +56,7 @@ u32 patchSvcBreak9(u8 *pos, u32 size, u32 kernel9Address); u32 patchKernel9Panic(u8 *pos, u32 size); u32 patchP9AccessChecks(u8 *pos, u32 size); u32 patchUnitInfoValueSet(u8 *pos, u32 size); +u32 patchP9AMTicketWrapperZeroKeyIV(u8 *pos, u32 size, u32 firmVersion); u32 patchLgySignatureChecks(u8 *pos, u32 size); u32 patchTwlInvalidSignatureChecks(u8 *pos, u32 size); u32 patchTwlNintendoLogoChecks(u8 *pos, u32 size); @@ -64,4 +65,3 @@ u32 patchTwlFlashcartChecks(u8 *pos, u32 size, u32 firmVersion); u32 patchOldTwlFlashcartChecks(u8 *pos, u32 size); u32 patchTwlShaHashChecks(u8 *pos, u32 size); u32 patchAgbBootSplash(u8 *pos, u32 size); -u32 patchP9AMTicketWrapperZeroKeyIV(u8* pos, u32 size); diff --git a/arm9/source/utils.c b/arm9/source/utils.c index a048348..38f81ba 100644 --- a/arm9/source/utils.c +++ b/arm9/source/utils.c @@ -86,15 +86,16 @@ u32 waitInput(bool isMenu) if(!key) { - if (shouldShellShutdown) { + if(shouldShellShutdown) + { u8 shellState = I2C_readReg(I2C_DEV_MCU, 0xF); wait(3); - if (!(shellState & 2)) mcuPowerOff(); + if(!(shellState & 2)) mcuPowerOff(); } - u8 intstatus = I2C_readReg(I2C_DEV_MCU, 0x10); + u8 intStatus = I2C_readReg(I2C_DEV_MCU, 0x10); wait(3); - if (intstatus & 1) mcuPowerOff(); //Power button pressed + if(intStatus & 1) mcuPowerOff(); //Power button pressed oldKey = 0; dPadDelay = 0;