Created
July 3, 2012 16:44
-
-
Save x1nixmzeng/3040921 to your computer and use it in GitHub Desktop.
The XOR function used in Z3Ex.dll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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