Rewrite the module copying function

This commit is contained in:
Aurora 2016-08-30 02:18:32 +02:00
parent 06fe06f9f1
commit 7f93733107
2 changed files with 19 additions and 22 deletions

View File

@ -351,33 +351,30 @@ static inline void patch2xNativeAndSafeFirm(void)
static inline void copySection0AndInjectSystemModules(void) static inline void copySection0AndInjectSystemModules(void)
{ {
u8 *arm11Section0 = (u8 *)firm + section[0].offset; u32 srcModuleSize,
dstModuleSize;
struct for(u8 *src = (u8 *)firm + section[0].offset, *srcEnd = src + section[0].size, *dst = section[0].address;
src < srcEnd; src += srcModuleSize, dst += dstModuleSize)
{ {
u32 size; srcModuleSize = *(u32 *)(src + 0x104) * 0x200;
const u8 *addr; char *moduleName = (char *)(src + 0x200);
} modules[5];
u32 n = 0, void *module;
loaderIndex;
u8 *pos = arm11Section0;
for(u8 *end = pos + section[0].size; pos < end; pos += modules[n++].size) if(memcmp(moduleName, "loader", 6) == 0)
{ {
modules[n].addr = pos; module = (void *)injector;
modules[n].size = *(u32 *)(pos + 0x104) * 0x200; dstModuleSize = injector_size;
}
if(memcmp(modules[n].addr + 0x200, "loader", 7) == 0) loaderIndex = n; else
{
module = src;
dstModuleSize = srcModuleSize;
} }
modules[loaderIndex].addr = injector; memcpy(dst, module, dstModuleSize);
modules[loaderIndex].size = injector_size; }
pos = section[0].address;
for(u32 i = 0; i < n; pos += modules[i++].size)
memcpy(pos, modules[i].addr, modules[i].size);
} }
static inline void launchFirm(FirmwareType firmType) static inline void launchFirm(FirmwareType firmType)