Do not hardcode the FIRM version check for the module patch, check for the free space to be enough
This commit is contained in:
parent
6afc8b3b5c
commit
9862256ca7
@ -302,7 +302,7 @@ static inline void patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32
|
|||||||
process9MemAddr;
|
process9MemAddr;
|
||||||
u8 *process9Offset = getProcess9(arm9Section + 0x15000, section[2].size - 0x15000, &process9Size, &process9MemAddr);
|
u8 *process9Offset = getProcess9(arm9Section + 0x15000, section[2].size - 0x15000, &process9Size, &process9MemAddr);
|
||||||
|
|
||||||
//Find Kernel11 SVC table and free space locations
|
//Find Kernel11 SVC table and handler, exceptions page and free space locations
|
||||||
u8 *freeK11Space;
|
u8 *freeK11Space;
|
||||||
u32 *arm11SvcHandler,
|
u32 *arm11SvcHandler,
|
||||||
*arm11ExceptionsPage,
|
*arm11ExceptionsPage,
|
||||||
@ -361,11 +361,7 @@ static inline void patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32
|
|||||||
if(CONFIG(9))
|
if(CONFIG(9))
|
||||||
{
|
{
|
||||||
patchArm11SvcAccessChecks(arm11SvcHandler);
|
patchArm11SvcAccessChecks(arm11SvcHandler);
|
||||||
|
patchK11ModuleChecks(arm11Section1, section[1].size, &freeK11Space);
|
||||||
//FIRMs between 9.3 and 10.4 don't have enough space on N3DS
|
|
||||||
if(!isN3DS || firmVersion <= 4 || firmVersion >= 0x21)
|
|
||||||
patchK11ModuleChecks(arm11Section1, section[1].size, &freeK11Space);
|
|
||||||
|
|
||||||
patchP9AccessChecks(process9Offset, process9Size);
|
patchP9AccessChecks(process9Offset, process9Size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -332,18 +332,22 @@ void patchK11ModuleChecks(u8 *pos, u32 size, u8 **freeK11Space)
|
|||||||
/* We have to detour a function in the ARM11 kernel because builtin modules
|
/* We have to detour a function in the ARM11 kernel because builtin modules
|
||||||
are compressed in memory and are only decompressed at runtime */
|
are compressed in memory and are only decompressed at runtime */
|
||||||
|
|
||||||
//Inject our code into the free space
|
//Check that we have enough free space
|
||||||
memcpy(*freeK11Space, k11modules, k11modules_size);
|
if(*(u32 *)(*freeK11Space + k11modules_size - 4) == 0xFFFFFFFF)
|
||||||
|
{
|
||||||
|
//Inject our code into the free space
|
||||||
|
memcpy(*freeK11Space, k11modules, k11modules_size);
|
||||||
|
|
||||||
//Look for the code that decompresses the .code section of the builtin modules
|
//Look for the code that decompresses the .code section of the builtin modules
|
||||||
const u8 pattern[] = {0xE5, 0x48, 0x00, 0x9D};
|
const u8 pattern[] = {0xE5, 0x48, 0x00, 0x9D};
|
||||||
|
|
||||||
u32 *off = (u32 *)(memsearch(pos, pattern, size, sizeof(pattern)) - 0xB);
|
u32 *off = (u32 *)(memsearch(pos, pattern, size, sizeof(pattern)) - 0xB);
|
||||||
|
|
||||||
//Inject a jump (BL) instruction to our code at the offset we found
|
//Inject a jump (BL) instruction to our code at the offset we found
|
||||||
*off = 0xEB000000 | (((((u32)*freeK11Space) - ((u32)off + 8)) >> 2) & 0xFFFFFF);
|
*off = 0xEB000000 | (((((u32)*freeK11Space) - ((u32)off + 8)) >> 2) & 0xFFFFFF);
|
||||||
|
|
||||||
(*freeK11Space) += k11modules_size;
|
*freeK11Space += k11modules_size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void patchUnitInfoValueSet(u8 *pos, u32 size)
|
void patchUnitInfoValueSet(u8 *pos, u32 size)
|
||||||
|
Reference in New Issue
Block a user