2012-08-12 21:26:24 +00:00
|
|
|
|
2012-10-13 16:57:03 +00:00
|
|
|
#include "utils.h"
|
|
|
|
#include "debug.h"
|
2012-08-12 21:26:24 +00:00
|
|
|
#include "wip.h"
|
|
|
|
|
2012-10-13 16:57:03 +00:00
|
|
|
WIP_Code *CodeList;
|
|
|
|
u32 CodesCount;
|
|
|
|
u32 ProcessedLength;
|
|
|
|
u32 Counter;
|
2012-08-12 21:26:24 +00:00
|
|
|
|
|
|
|
void do_wip_code(u8 * dst, u32 len)
|
|
|
|
{
|
|
|
|
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];
|
2012-10-13 16:57:03 +00:00
|
|
|
debug_string("Address patched:"); debug_uint(CodeList[i].offset+n); debug_string("\n");
|
2012-08-12 21:26:24 +00:00
|
|
|
//printf("WIP: %08X Address Patched.\n", CodeList[i].offset + n);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-13 16:57:03 +00:00
|
|
|
debug_string("Address NOT patched:"); debug_uint(CodeList[i].offset+n); debug_string("\n");
|
2012-08-12 21:26:24 +00:00
|
|
|
//printf("WIP: %08X Address does not match with WIP entry.\n", CodeList[i].offset+n);
|
|
|
|
//printf("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-13 16:57:03 +00:00
|
|
|
u8 set_wip_list(WIP_Code *list, int size)
|
2012-08-12 21:26:24 +00:00
|
|
|
{
|
2012-10-13 16:57:03 +00:00
|
|
|
CodeList = list;
|
|
|
|
CodesCount = size;
|
2012-08-12 21:26:24 +00:00
|
|
|
ProcessedLength = 0;
|
2012-10-13 16:57:03 +00:00
|
|
|
Counter = 0;
|
|
|
|
return 1;
|
2012-08-12 21:26:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void free_wip()
|
|
|
|
{
|
|
|
|
CodesCount = 0;
|
|
|
|
ProcessedLength = 0;
|
|
|
|
}
|