parent
7271850df2
commit
7bd0e4f5b4
@ -35,7 +35,10 @@
|
|||||||
#include "buttons.h"
|
#include "buttons.h"
|
||||||
#include "pin.h"
|
#include "pin.h"
|
||||||
#include "../build/injector.h"
|
#include "../build/injector.h"
|
||||||
|
|
||||||
|
#ifdef DEV
|
||||||
#include "exceptions.h"
|
#include "exceptions.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
extern u16 launchedFirmTidLow[8]; //Defined in start.s
|
extern u16 launchedFirmTidLow[8]; //Defined in start.s
|
||||||
|
|
||||||
@ -360,12 +363,19 @@ 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);
|
||||||
|
|
||||||
|
#ifdef DEV
|
||||||
//Find Kernel11 SVC table and handler, exceptions page and free space locations
|
//Find Kernel11 SVC table and handler, exceptions page and free space locations
|
||||||
u32 baseK11VA;
|
u32 baseK11VA;
|
||||||
u8 *freeK11Space;
|
u8 *freeK11Space;
|
||||||
u32 *arm11SvcHandler,
|
u32 *arm11SvcHandler,
|
||||||
*arm11ExceptionsPage,
|
*arm11ExceptionsPage,
|
||||||
*arm11SvcTable = getKernel11Info(arm11Section1, section[1].size, &baseK11VA, &freeK11Space, &arm11SvcHandler, &arm11ExceptionsPage);
|
*arm11SvcTable = getKernel11Info(arm11Section1, section[1].size, &baseK11VA, &freeK11Space, &arm11SvcHandler, &arm11ExceptionsPage);
|
||||||
|
#else
|
||||||
|
//Find Kernel11 SVC table and free space locations
|
||||||
|
u32 baseK11VA;
|
||||||
|
u8 *freeK11Space;
|
||||||
|
u32 *arm11SvcTable = getKernel11Info(arm11Section1, section[1].size, &baseK11VA, &freeK11Space);
|
||||||
|
#endif
|
||||||
|
|
||||||
//Apply signature patches
|
//Apply signature patches
|
||||||
patchSignatureChecks(process9Offset, process9Size);
|
patchSignatureChecks(process9Offset, process9Size);
|
||||||
@ -511,7 +521,7 @@ static inline void copySection0AndInjectSystemModules(FirmwareType firmType)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static inline void copySection0AndInjectSystemModules(FirmwareType firmType)
|
static inline void copySection0AndInjectSystemModules(void)
|
||||||
{
|
{
|
||||||
u32 srcModuleSize,
|
u32 srcModuleSize,
|
||||||
dstModuleSize;
|
dstModuleSize;
|
||||||
@ -524,7 +534,7 @@ static inline void copySection0AndInjectSystemModules(FirmwareType firmType)
|
|||||||
|
|
||||||
void *module;
|
void *module;
|
||||||
|
|
||||||
if(firmType == NATIVE_FIRM && memcmp(moduleName, "loader", 6) == 0)
|
if(memcmp(moduleName, "loader", 6) == 0)
|
||||||
{
|
{
|
||||||
module = (void *)injector;
|
module = (void *)injector;
|
||||||
dstModuleSize = injector_size;
|
dstModuleSize = injector_size;
|
||||||
@ -542,7 +552,8 @@ static inline void copySection0AndInjectSystemModules(FirmwareType firmType)
|
|||||||
|
|
||||||
static inline void launchFirm(FirmwareType firmType)
|
static inline void launchFirm(FirmwareType firmType)
|
||||||
{
|
{
|
||||||
//Allow module injection and/or inject 3ds_injector on new NATIVE_FIRMs and LGY FIRMs (with DEV set)
|
#ifdef DEV
|
||||||
|
//Allow module injection and/or inject 3ds_injector on new NATIVE_FIRMs and LGY FIRMs
|
||||||
u32 sectionNum;
|
u32 sectionNum;
|
||||||
if(firmType != SAFE_FIRM && firmType != NATIVE_FIRM1X2X)
|
if(firmType != SAFE_FIRM && firmType != NATIVE_FIRM1X2X)
|
||||||
{
|
{
|
||||||
@ -550,6 +561,16 @@ static inline void launchFirm(FirmwareType firmType)
|
|||||||
sectionNum = 1;
|
sectionNum = 1;
|
||||||
}
|
}
|
||||||
else sectionNum = 0;
|
else sectionNum = 0;
|
||||||
|
#else
|
||||||
|
//If we're booting NATIVE_FIRM, section0 needs to be copied separately to inject 3ds_injector
|
||||||
|
u32 sectionNum;
|
||||||
|
if(firmType == NATIVE_FIRM)
|
||||||
|
{
|
||||||
|
copySection0AndInjectSystemModules();
|
||||||
|
sectionNum = 1;
|
||||||
|
}
|
||||||
|
else sectionNum = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
//Copy FIRM sections to respective memory locations
|
//Copy FIRM sections to respective memory locations
|
||||||
for(; sectionNum < 4 && section[sectionNum].size; sectionNum++)
|
for(; sectionNum < 4 && section[sectionNum].size; sectionNum++)
|
||||||
|
@ -52,6 +52,10 @@ static inline void patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32
|
|||||||
static inline void patchLegacyFirm(FirmwareType firmType);
|
static inline void patchLegacyFirm(FirmwareType firmType);
|
||||||
static inline void patch1x2xNativeAndSafeFirm(void);
|
static inline void patch1x2xNativeAndSafeFirm(void);
|
||||||
|
|
||||||
|
#ifdef DEV
|
||||||
static inline void copySection0AndInjectSystemModules(FirmwareType firmType);
|
static inline void copySection0AndInjectSystemModules(FirmwareType firmType);
|
||||||
|
#else
|
||||||
|
static inline void copySection0AndInjectSystemModules(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
static inline void launchFirm(FirmwareType firmType);
|
static inline void launchFirm(FirmwareType firmType);
|
@ -45,6 +45,7 @@ u8 *getProcess9(u8 *pos, u32 size, u32 *process9Size, u32 *process9MemAddr)
|
|||||||
return off - 0x204 + (*(u32 *)(off - 0x64) * 0x200) + 0x200;
|
return off - 0x204 + (*(u32 *)(off - 0x64) * 0x200) + 0x200;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef DEV
|
||||||
u32 *getKernel11Info(u8 *pos, u32 size, u32 *baseK11VA, u8 **freeK11Space, u32 **arm11SvcHandler, u32 **arm11ExceptionsPage)
|
u32 *getKernel11Info(u8 *pos, u32 size, u32 *baseK11VA, u8 **freeK11Space, u32 **arm11SvcHandler, u32 **arm11ExceptionsPage)
|
||||||
{
|
{
|
||||||
const u8 pattern[] = {0x00, 0xB0, 0x9C, 0xE5};
|
const u8 pattern[] = {0x00, 0xB0, 0x9C, 0xE5};
|
||||||
@ -64,6 +65,26 @@ u32 *getKernel11Info(u8 *pos, u32 size, u32 *baseK11VA, u8 **freeK11Space, u32 *
|
|||||||
|
|
||||||
return arm11SvcTable;
|
return arm11SvcTable;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
u32 *getKernel11Info(u8 *pos, u32 size, u32 *baseK11VA, u8 **freeK11Space)
|
||||||
|
{
|
||||||
|
const u8 pattern[] = {0x00, 0xB0, 0x9C, 0xE5};
|
||||||
|
|
||||||
|
u32 *arm11ExceptionsPage = (u32 *)memsearch(pos, pattern, size, sizeof(pattern)) - 0xB;
|
||||||
|
|
||||||
|
u32 svcOffset = (-((arm11ExceptionsPage[2] & 0xFFFFFF) << 2) & (0xFFFFFF << 2)) - 8; //Branch offset + 8 for prefetch
|
||||||
|
u32 pointedInstructionVA = 0xFFFF0008 - svcOffset;
|
||||||
|
*baseK11VA = pointedInstructionVA & 0xFFFF0000; //This assumes that the pointed instruction has an offset < 0x10000, iirc that's always the case
|
||||||
|
u32 *arm11SvcTable = (u32 *)(pos + *(u32 *)(pos + pointedInstructionVA - *baseK11VA + 8) - *baseK11VA); //SVC handler address
|
||||||
|
while(*arm11SvcTable) arm11SvcTable++; //Look for SVC0 (NULL)
|
||||||
|
|
||||||
|
const u8 pattern2[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||||
|
|
||||||
|
*freeK11Space = memsearch(pos, pattern2, size, sizeof(pattern2)) + 1;
|
||||||
|
|
||||||
|
return arm11SvcTable;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void patchSignatureChecks(u8 *pos, u32 size)
|
void patchSignatureChecks(u8 *pos, u32 size)
|
||||||
{
|
{
|
||||||
@ -166,9 +187,9 @@ void implementSvcGetCFWInfo(u8 *pos, u32 *arm11SvcTable, u32 baseK11VA, u8 **fre
|
|||||||
else isRelease = rev[4] == 0;
|
else isRelease = rev[4] == 0;
|
||||||
|
|
||||||
#ifdef DEV
|
#ifdef DEV
|
||||||
info->flags = 1 /* dev build */ | ((isRelease ? 1 : 0) << 1) /* is release */;
|
info->flags = 1 /* dev branch */ | ((isRelease ? 1 : 0) << 1) /* is release */;
|
||||||
#else
|
#else
|
||||||
info->flags = 0 /* non-dev build */ | ((isRelease ? 1 : 0) << 1) /* is release */;
|
info->flags = 0 /* master branch */ | ((isRelease ? 1 : 0) << 1) /* is release */;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
arm11SvcTable[0x2E] = baseK11VA + *freeK11Space - pos; //Stubbed svc
|
arm11SvcTable[0x2E] = baseK11VA + *freeK11Space - pos; //Stubbed svc
|
||||||
|
@ -51,11 +51,19 @@ typedef struct __attribute__((packed))
|
|||||||
u32 config;
|
u32 config;
|
||||||
} CFWInfo;
|
} CFWInfo;
|
||||||
|
|
||||||
extern bool isN3DS, isDevUnit;
|
extern bool isN3DS;
|
||||||
|
|
||||||
|
#ifdef DEV
|
||||||
|
extern bool isDevUnit;
|
||||||
|
#endif
|
||||||
|
|
||||||
u8 *getProcess9(u8 *pos, u32 size, u32 *process9Size, u32 *process9MemAddr);
|
u8 *getProcess9(u8 *pos, u32 size, u32 *process9Size, u32 *process9MemAddr);
|
||||||
|
|
||||||
|
#ifdef DEV
|
||||||
u32 *getKernel11Info(u8 *pos, u32 size, u32 *baseK11VA, u8 **freeK11Space, u32 **arm11SvcHandler, u32 **arm11ExceptionsPage);
|
u32 *getKernel11Info(u8 *pos, u32 size, u32 *baseK11VA, u8 **freeK11Space, u32 **arm11SvcHandler, u32 **arm11ExceptionsPage);
|
||||||
|
#else
|
||||||
|
u32 *getKernel11Info(u8 *pos, u32 size, u32 *baseK11VA, u8 **freeK11Space);
|
||||||
|
#endif
|
||||||
|
|
||||||
void patchSignatureChecks(u8 *pos, u32 size);
|
void patchSignatureChecks(u8 *pos, u32 size);
|
||||||
void patchTitleInstallMinVersionCheck(u8 *pos, u32 size);
|
void patchTitleInstallMinVersionCheck(u8 *pos, u32 size);
|
||||||
|
Reference in New Issue
Block a user