Add support for loading /luma/TwlBg.cxi (on dev branch this will take precedence)

This commit is contained in:
TuxSH 2016-08-21 22:09:27 +02:00
parent b87dadbb72
commit 253e031f83
4 changed files with 59 additions and 29 deletions

View File

@ -332,25 +332,73 @@ static inline void patchSafeFirm(void)
else patchFirmWriteSafe(arm9Section, section[2].size);
}
static inline void copySection0AndInjectLoader(void)
static inline void copySection0AndInjectSystemModules(FirmwareType firmType)
{
u8 *arm11Section0 = (u8 *)firm + section[0].offset;
u32 loaderSize;
u32 loaderOffset = getLoader(arm11Section0, &loaderSize);
struct
{
u32 size;
char name[8];
const u8 *addr;
} modules[5] = {{0}};
memcpy(section[0].address, arm11Section0, loaderOffset);
memcpy(section[0].address + loaderOffset, injector, injector_size);
memcpy(section[0].address + loaderOffset + injector_size, arm11Section0 + loaderOffset + loaderSize, section[0].size - (loaderOffset + loaderSize));
u8 *pos = arm11Section0, *end = pos + section[0].size;
u32 n = 0;
u32 loaderIndex = 0, twlBgIndex = 0;
while(pos < end)
{
modules[n].addr = pos;
modules[n].size = *(u32 *)(pos + 0x104) * 0x200;
memcpy(modules[n].name, pos + 0x200, 8);
pos += modules[n].size;
if(firmType == NATIVE_FIRM && memcmp(modules[n].name, "loader", 7) == 0) loaderIndex = n;
else if(firmType == TWL_FIRM && memcmp(modules[n].name, "TwlBg", 6) == 0) twlBgIndex = n;
n++;
}
u32 twlBgSize = 0;
if(firmType == NATIVE_FIRM)
{
modules[loaderIndex].size = injector_size;
modules[loaderIndex].addr = injector;
}
else if(firmType == TWL_FIRM)
{
twlBgSize = getFileSize("/luma/TwlBg.cxi");
if(twlBgSize != 0)
{
modules[twlBgIndex].size = twlBgSize;
modules[twlBgIndex].addr = NULL;
}
}
pos = section[0].address;
for(u32 i = 0; i < n; i++)
{
if(firmType == TWL_FIRM && i == twlBgIndex && twlBgSize != 0)
fileRead(pos, "/luma/TwlBg.cxi");
else if(modules[i].addr != NULL)
memcpy(pos, modules[i].addr, modules[i].size);
pos += modules[i].size;
}
}
static inline void launchFirm(FirmwareType firmType, bool isFirmlaunch)
{
//If we're booting NATIVE_FIRM, section0 needs to be copied separately to inject 3ds_injector
u32 sectionNum;
if(firmType == NATIVE_FIRM)
if(firmType != SAFE_FIRM)
{
copySection0AndInjectLoader();
copySection0AndInjectSystemModules(firmType);
sectionNum = 1;
}
else sectionNum = 0;

View File

@ -58,5 +58,5 @@ static inline u32 loadFirm(FirmwareType firmType);
static inline void patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32 emuHeader, bool isA9lh);
static inline void patchLegacyFirm(FirmwareType firmType);
static inline void patchSafeFirm(void);
static inline void copySection0AndInjectLoader(void);
static inline void copySection0AndInjectSystemModules(FirmwareType firmType);
static inline void launchFirm(FirmwareType firmType, bool isFirmlaunch);

View File

@ -260,21 +260,4 @@ void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType)
break;
}
}
}
u32 getLoader(u8 *pos, u32 *loaderSize)
{
u8 *off = pos;
u32 size;
while(true)
{
size = *(u32 *)(off + 0x104) * 0x200;
if(*(u32 *)(off + 0x200) == 0x64616F6C) break;
off += size;
}
*loaderSize = size;
return (u32)(off - pos);
}
}

View File

@ -43,5 +43,4 @@ void patchFirmWrites(u8 *pos, u32 size);
void patchFirmWriteSafe(u8 *pos, u32 size);
void reimplementSvcBackdoor(u8 *pos, u32 size);
void implementSvcGetCFWInfo(u8 *pos, u32 size);
void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType);
u32 getLoader(u8 *pos, u32 *loaderSize);
void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType);