No need to search for the Process9 .code, calculate it (one memsearch less)

This commit is contained in:
Aurora 2016-03-21 20:24:12 +01:00
parent c542bc5cf3
commit d01d9b53f2
2 changed files with 6 additions and 3 deletions

View File

@ -55,6 +55,6 @@ void *getMPU(void *pos, u32 size){
u8 *getEmuCode(void *pos, u32 size, u8 *proc9Offset){ u8 *getEmuCode(void *pos, u32 size, u8 *proc9Offset){
const unsigned char pattern[] = {0x00, 0xFF, 0xFF, 0xFF}; const unsigned char pattern[] = {0x00, 0xFF, 0xFF, 0xFF};
//Looking for the last spot before Process9 //Looking for the last free space before Process9
return (u8 *)memsearch(pos, pattern, size - (size - (u32)(proc9Offset - (u8 *)pos)), 4) + 0xD; return (u8 *)memsearch(pos, pattern, size - (size - (u32)(proc9Offset - (u8 *)pos)), 4) + 0xD;
} }

View File

@ -50,9 +50,12 @@ u8 *getReboot(void *pos, u32 size){
} }
u32 getfOpen(void *pos, u32 size, u8 *proc9Offset){ u32 getfOpen(void *pos, u32 size, u8 *proc9Offset){
//Calculate fOpen //Offset Process9 code gets loaded to in memory (defined in ExHeader)
u32 p9MemAddr = *(u32 *)(proc9Offset + 0xC); u32 p9MemAddr = *(u32 *)(proc9Offset + 0xC);
u32 p9CodeOff = (u32)memsearch(pos, "code", size, 4) + 0x1FF; //Start of Process9 .code section (start of NCCH + ExeFS offset + ExeFS header size)
u32 p9CodeOff = (u32)(proc9Offset - 0x204) + (*(u32 *)(proc9Offset - 0x64) * 0x200) + 0x200;
//Calculate fOpen
const unsigned char pattern[] = {0xB0, 0x04, 0x98, 0x0D}; const unsigned char pattern[] = {0xB0, 0x04, 0x98, 0x0D};
return (u32)memsearch(pos, pattern, size, 4) - 2 - p9CodeOff + p9MemAddr; return (u32)memsearch(pos, pattern, size, 4) - 2 - p9CodeOff + p9MemAddr;