2012-10-14 19:18:13 +02:00
|
|
|
|
|
|
|
#include <gccore.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include "wip.h"
|
|
|
|
#include "gecko.h"
|
|
|
|
|
2012-10-20 00:01:30 +02:00
|
|
|
static WIP_Code *CodeList = NULL;
|
2012-10-14 19:18:13 +02:00
|
|
|
static u32 CodesCount = 0;
|
|
|
|
static u32 ProcessedLength = 0;
|
|
|
|
static u32 Counter = 0;
|
|
|
|
|
|
|
|
void do_wip_code(u8 * dst, u32 len)
|
|
|
|
{
|
|
|
|
if(!CodeList)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(Counter < 3)
|
|
|
|
{
|
|
|
|
Counter++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 i = 0;
|
|
|
|
s32 n = 0;
|
|
|
|
s32 offset = 0;
|
|
|
|
|
|
|
|
for(i = 0; i < CodesCount; i++)
|
|
|
|
{
|
|
|
|
for(n = 0; n < 4; n++)
|
|
|
|
{
|
|
|
|
offset = CodeList[i].offset+n-ProcessedLength;
|
|
|
|
|
|
|
|
if(offset < 0 || (u32)offset >= len)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(dst[offset] == ((u8 *)&CodeList[i].srcaddress)[n])
|
|
|
|
{
|
|
|
|
dst[offset] = ((u8 *)&CodeList[i].dstaddress)[n];
|
|
|
|
gprintf("WIP: %08X Address Patched.\n", CodeList[i].offset + n);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gprintf("WIP: %08X Address does not match with WIP entry.\n", CodeList[i].offset+n);
|
|
|
|
gprintf("Destination: %02X | Should be: %02X.\n", dst[offset], ((u8 *)&CodeList[i].srcaddress)[n]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ProcessedLength += len;
|
|
|
|
Counter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! for internal patches only
|
|
|
|
//! .wip files override internal patches
|
|
|
|
//! the codelist has to be freed if the set fails
|
|
|
|
//! if set was successful the codelist will be freed when it's done
|
2012-10-20 00:01:30 +02:00
|
|
|
bool set_wip_list(WIP_Code *list, int size)
|
2012-10-14 19:18:13 +02:00
|
|
|
{
|
2012-10-20 00:01:30 +02:00
|
|
|
if(CodeList == NULL && size > 0)
|
2012-10-14 19:18:13 +02:00
|
|
|
{
|
2014-03-23 18:40:31 +01:00
|
|
|
WIP_Code *newlist = malloc(size * sizeof(WIP_Code)); //internal copy
|
2012-10-20 00:01:30 +02:00
|
|
|
memcpy(newlist, list, size * sizeof(WIP_Code));
|
|
|
|
DCFlushRange(newlist, size * sizeof(WIP_Code));
|
|
|
|
CodeList = newlist;
|
2012-10-14 19:18:13 +02:00
|
|
|
CodesCount = size;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wip_reset_counter()
|
|
|
|
{
|
|
|
|
ProcessedLength = 0;
|
|
|
|
//alternative dols don't need a skip. only main.dol.
|
|
|
|
Counter = 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
void free_wip()
|
|
|
|
{
|
2012-10-20 00:01:30 +02:00
|
|
|
if(CodeList != NULL)
|
2012-10-14 19:18:13 +02:00
|
|
|
free(CodeList);
|
|
|
|
CodesCount = 0;
|
|
|
|
ProcessedLength = 0;
|
|
|
|
}
|