Skip to content

Instantly share code, notes, and snippets.

@x1nixmzeng
Created July 3, 2012 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save x1nixmzeng/3040921 to your computer and use it in GitHub Desktop.
Save x1nixmzeng/3040921 to your computer and use it in GitHub Desktop.
The XOR function used in Z3Ex.dll
void rs3Unscramble( char *srcBuffer, DWORD srcSize, DWORD xorkey )
{
// Unscramble the 32-bit blocks
DWORD dBlocks = srcSize >> 2;
while( dBlocks )
{
DWORD tmp;
tmp = *(DWORD *)srcBuffer; // read 32-bit value
xorkey += tmp;
tmp ^= xorkey;
*(DWORD *)srcBuffer = tmp; // write 32-bit value
srcBuffer += 4;
--dBlocks;
}
// Unscramble the remaining data (1-3 bytes)
BYTE bAlign = (BYTE)(srcSize & 3);
if( bAlign )
{
DWORD lastBlock;
int i;
lastBlock = 0;
i = 0;
// read remaining 8/16/24-bit value
while( i < bAlign )
{
DWORD tmp;
tmp = *(BYTE *)(srcBuffer + i);
tmp <<= i << 3;
lastBlock |= tmp;
++i;
}
xorkey += lastBlock;
lastBlock ^= xorkey;
// write remaining 8/16/24-bit value
i = 0;
while( i < bAlign )
{
*(BYTE *)(srcBuffer + i) = (BYTE)lastBlock;
lastBlock >>= 8;
++i;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment