2015-08-21 20:11:23 +02:00
|
|
|
/*
|
|
|
|
* patches.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "patches.h"
|
2016-02-08 03:37:03 +01:00
|
|
|
#include "memory.h"
|
2015-08-21 20:11:23 +02:00
|
|
|
|
|
|
|
/**************************************************
|
|
|
|
* Patches
|
|
|
|
**************************************************/
|
|
|
|
|
2016-03-26 17:24:16 +01:00
|
|
|
const u32 mpuPatch[3] = {0x00360003, 0x00200603, 0x001C0603};
|
2016-02-08 03:37:03 +01:00
|
|
|
|
2016-04-26 20:06:31 +02:00
|
|
|
const u16 nandRedir[2] = {0x4C00, 0x47A0},
|
|
|
|
sigPatch[2] = {0x2000, 0x4770},
|
|
|
|
writeBlock[2] = {0x2000, 0x46C0};
|
2016-03-06 16:24:42 +01:00
|
|
|
|
2015-08-21 20:11:23 +02:00
|
|
|
/**************************************************
|
|
|
|
* Functions
|
|
|
|
**************************************************/
|
|
|
|
|
2016-04-02 17:58:06 +02:00
|
|
|
u8 *getProc9(u8 *pos, u32 size)
|
|
|
|
{
|
2016-03-29 17:43:53 +02:00
|
|
|
return memsearch(pos, "ess9", size, 4);
|
2016-03-21 18:56:41 +01:00
|
|
|
}
|
|
|
|
|
2016-04-02 17:58:06 +02:00
|
|
|
void getSigChecks(u8 *pos, u32 size, u32 *off, u32 *off2)
|
|
|
|
{
|
2016-02-08 03:37:03 +01:00
|
|
|
//Look for signature checks
|
2016-03-29 17:43:53 +02:00
|
|
|
const u8 pattern[] = {0xC0, 0x1C, 0x76, 0xE7},
|
|
|
|
pattern2[] = {0xB5, 0x22, 0x4D, 0x0C};
|
2015-08-21 20:11:23 +02:00
|
|
|
|
2016-02-11 00:45:24 +01:00
|
|
|
*off = (u32)memsearch(pos, pattern, size, 4);
|
2016-02-20 15:29:32 +01:00
|
|
|
*off2 = (u32)memsearch(pos, pattern2, size, 4) - 1;
|
2015-08-21 20:11:23 +02:00
|
|
|
}
|
|
|
|
|
2016-04-02 17:58:06 +02:00
|
|
|
void *getReboot(u8 *pos, u32 size)
|
|
|
|
{
|
2016-02-08 03:37:03 +01:00
|
|
|
//Look for FIRM reboot code
|
2016-03-26 19:21:17 +01:00
|
|
|
const u8 pattern[] = {0xDE, 0x1F, 0x8D, 0xE2};
|
2015-08-21 20:11:23 +02:00
|
|
|
|
2016-03-29 17:43:53 +02:00
|
|
|
return memsearch(pos, pattern, size, 4) - 0x10;
|
2016-02-25 20:19:20 +01:00
|
|
|
}
|
|
|
|
|
2016-04-02 17:58:06 +02:00
|
|
|
u32 getfOpen(u8 *proc9Offset, void *rebootOffset)
|
|
|
|
{
|
2016-03-21 20:24:12 +01:00
|
|
|
//Offset Process9 code gets loaded to in memory (defined in ExHeader)
|
2016-03-21 18:56:41 +01:00
|
|
|
u32 p9MemAddr = *(u32 *)(proc9Offset + 0xC);
|
2016-04-02 17:58:06 +02:00
|
|
|
|
2016-03-26 17:24:16 +01:00
|
|
|
//Process9 code offset (start of NCCH + ExeFS offset + ExeFS header size)
|
2016-03-21 20:24:12 +01:00
|
|
|
u32 p9CodeOff = (u32)(proc9Offset - 0x204) + (*(u32 *)(proc9Offset - 0x64) * 0x200) + 0x200;
|
|
|
|
|
2016-03-26 17:24:16 +01:00
|
|
|
//Firmlaunch function offset - offset in BLX opcode (A4-16 - ARM DDI 0100E) + 1
|
|
|
|
return (u32)rebootOffset + 9 - (-((*(u32 *)rebootOffset & 0x00FFFFFF) << 2) & 0xFFFFF) - p9CodeOff + p9MemAddr;
|
2016-02-19 21:32:07 +01:00
|
|
|
}
|
|
|
|
|
2016-04-02 17:58:06 +02:00
|
|
|
u16 *getFirmWrite(u8 *pos, u32 size)
|
|
|
|
{
|
2016-02-19 21:32:07 +01:00
|
|
|
//Look for FIRM writing code
|
2016-03-29 17:43:53 +02:00
|
|
|
u8 *const off = memsearch(pos, "exe:", size, 4);
|
2016-03-26 19:21:17 +01:00
|
|
|
const u8 pattern[] = {0x00, 0x28, 0x01, 0xDA};
|
2016-02-19 21:32:07 +01:00
|
|
|
|
2016-03-26 17:24:16 +01:00
|
|
|
return (u16 *)memsearch(off - 0x100, pattern, 0x100, 4);
|
2016-03-29 17:43:53 +02:00
|
|
|
}
|
|
|
|
|
2016-04-13 14:23:08 +02:00
|
|
|
void *getLoader(u8 *pos, u32 size, u32 *loaderSize)
|
2016-04-11 21:14:51 +02:00
|
|
|
{
|
2016-04-12 14:32:38 +02:00
|
|
|
u8 *const off = memsearch(pos, "loade", size, 5);
|
2016-04-11 21:14:51 +02:00
|
|
|
|
2016-04-12 14:32:38 +02:00
|
|
|
*loaderSize = *(u32 *)(off - 0xFC) * 0x200;
|
2016-04-13 14:23:08 +02:00
|
|
|
|
|
|
|
return off - 0x200;
|
2016-04-11 22:16:51 +02:00
|
|
|
}
|