I've been browsing through the code. Some random thoughts:
line 170 in Patch.c looks wrong to me.
Code:
if( (op & 0xFC00FFFF) == 0x3C00CC00 ) // lis rX, 0xCC00
The mask that's being used here would catch lis commands as intended, but would also include addis commands.
addis/lis command format:
http://pds.twi.tudelft.nl/vakken/in101/labcourse/instruction-set/addis.html
Then on line 189 or 211 or 234, it replaces it with a lis command. One of two things should be happening here either the line should be:
Code:
if( (op & 0xFC1FFFFF) == 0x3C00CC00 ) // lis rX, 0xCC00
which would only match lis commands and not addis commands, or you can keep the current if command, but you'd need to track the src register and reuse it in the 3 replace lines.
Code:
u32 LISReg=-1;
u32 ADDISReg=-1;
u32 LISOff=-1;
for( i=0; i < Length; i+=4 )
{
u32 op = read32( (u32)dst + i );
if( (op & 0xFC00FFFF) == 0x3C00CC00 ) // addis rX,rY, 0xCC00
{
LISReg = (op & 0x3E00000) >> 21;
ADDISReg = (op & 0x1F0000) >> 16;
LISOff = (u32)dst + i;
}
...
if( src == LISReg )
{
write32( (u32)LISOff, (LISReg<<21) | (ADDISReg<<16) | 0x3C00CD00 ); // Patch to: addis rX,rY, 0xCD00
Other thoughts:
This chunk is concerning.
Code:
/*
This offset gets randomly overwritten, this workaround fixes that problem.
*/
void Patch31A0( void )
Memory locations being written to randomly are not good. The patch which copies the instructions out of the randomly overwritten area to another location and patching in a couple of branches before and after might work in some cases, but if the code being used there is jumped to from other locations this can cause problems, as it would if the data being used there is accessed as part of some kind of structure used in the code that can't be broken up. The underlying issue that is causing 31a0 to be overwritten needs to be found and fixed.
It's interesting that there are 13 DSP hashes listed, but only profiles/lengths for the first 7. Where did the hashes come from, and why weren't the profiles and lengths generated when the hashes were? It's probably possible to auto generate hashes from dol files of images that are reporting unknown DSPs, if somewhat inefficiently, with a nested for loop of starting offsets and lengths to find the missing data for the other DSPs.
The method actually used for determining a match for patching is pretty interesting. The profile for each pattern lists how many branch&links, branches, moves, loads and stores there are inside a single function. I'd be interested to know how accurate this method is. Does it generate any false positives?