From 25811e2b5276dc4a0d56363ff8d7be01d0b427cd Mon Sep 17 00:00:00 2001 From: TuxSH Date: Sat, 13 Aug 2016 11:47:10 +0200 Subject: [PATCH] Remove handling of kernel panics for SAFE_FIRM k9, fix it for LGY FIRMs. --- source/firm.c | 5 ++--- source/patches.c | 19 +++++++++++++++---- source/patches.h | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/source/firm.c b/source/firm.c index 9ab64f6..a75d910 100755 --- a/source/firm.c +++ b/source/firm.c @@ -358,7 +358,7 @@ static inline void patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32 //Kernel9/Process9 debugging patchExceptionHandlersInstall(arm9Section, section[2].size); patchSvcBreak9(arm9Section, section[2].size, (u32)(section[2].address)); - patchKernel9Panic(arm9Section, section[2].size); + patchKernel9Panic(arm9Section, section[2].size, NATIVE_FIRM); //Stub svcBreak11 with "bkpt 65535" patchSvcBreak11(arm11Section1, section[1].size); @@ -393,7 +393,7 @@ static inline void patchLegacyFirm(FirmwareType firmType) //Kernel9/Process9 debugging patchExceptionHandlersInstall(arm9Section, section[3].size); patchSvcBreak9(arm9Section, section[3].size, (u32)(section[3].address)); - patchKernel9Panic(arm9Section, section[3].size); + patchKernel9Panic(arm9Section, section[3].size, firmType); } applyLegacyFirmPatches((u8 *)firm, firmType); @@ -418,7 +418,6 @@ static inline void patchSafeFirm(void) //Kernel9/Process9 debugging patchExceptionHandlersInstall(arm9Section, section[2].size); patchSvcBreak9(arm9Section, section[2].size, (u32)(section[2].address)); - patchKernel9Panic(arm9Section, section[2].size); } } diff --git a/source/patches.c b/source/patches.c index 1ed0c7a..4c49c93 100644 --- a/source/patches.c +++ b/source/patches.c @@ -190,12 +190,23 @@ void patchSvcBreak11(u8 *pos, u32 size) *addr = 0xE12FFF7F; } -void patchKernel9Panic(u8 *pos, u32 size) +void patchKernel9Panic(u8 *pos, u32 size, FirmwareType firmType) { - const u8 pattern[] = {0x00, 0x20, 0xA0, 0xE3, 0x02, 0x30, 0xA0, 0xE1, 0x02, 0x10, 0xA0, 0xE1, 0x05, 0x00, 0xA0, 0xE3}; + if(firmType == TWL_FIRM || firmType == AGB_FIRM) + { + u8 *off = pos + ((isN3DS) ? 0x723C : 0x69A8); + *(u16 *)off = 0x4778; //bx pc + *(u16 *)(off + 2) = 0x46C0; //nop + *(u32 *)(off + 4) = 0xE12FFF7E; //bkpt 65534 + } - u32 *off = (u32 *)memsearch(pos, pattern, size, 16); - *off = 0xE12FFF7E; + else + { + const u8 pattern[] = {0x00, 0x20, 0xA0, 0xE3, 0x02, 0x30, 0xA0, 0xE1, 0x02, 0x10, 0xA0, 0xE1, 0x05, 0x00, 0xA0, 0xE3}; + + u32 *off = (u32 *)memsearch(pos, pattern, size, 16); + *off = 0xE12FFF7E; + } } void patchKernel11Panic(u8 *pos, u32 size) diff --git a/source/patches.h b/source/patches.h index a4be714..b7814b6 100644 --- a/source/patches.h +++ b/source/patches.h @@ -45,7 +45,7 @@ void patchFirmWriteSafe(u8 *pos, u32 size); void patchExceptionHandlersInstall(u8 *pos, u32 size); void patchSvcBreak9(u8 *pos, u32 size, u32 k9addr); void patchSvcBreak11(u8 *pos, u32 size); -void patchKernel9Panic(u8 *pos, u32 size); +void patchKernel9Panic(u8 *pos, u32 size, FirmwareType firmType); void patchKernel11Panic(u8 *pos, u32 size); void patchArm11SvcAccessChecks(u8 *pos, u32 size); void patchK11ModuleChecks(u8 *pos, u32 size);