I have reverse engineered the follow algorithm for generating random numbers;
int __cdecl sub_40BB60()
{
char v0; // si@1
int v1; // edx@1
int v2; // ecx@1
unsigned int v3; // eax@1
int v4; // edi@1
int v5; // esi@1
int result; // eax@1
v0 = random_state;
v1 = dword_685440[((_BYTE)random_state - 3) & 0xF];
v2 = dword_685440[random_state] ^ v1 ^ ((v1 ^ 2 * dword_685440[random_state]) << 15);
v3 = ((unsigned int)dword_685440[((_BYTE)random_state - 7) & 0xF] >> 11) ^ dword_685440[((_BYTE)random_state - 7) & 0xF];
v4 = v3 ^ dword_685440[random_state] ^ v1 ^ ((v1 ^ 2 * dword_685440[random_state]) << 15);
dword_685440[random_state] = v4;
v5 = (v0 - 1) & 0xF;
result = dword_685440[v5] ^ v2 ^ v4 ^ 32 * (v4 & 0xFED22169) ^ 4 * (dword_685440[v5] ^ ((v2 ^ (v3 << 10)) << 16));
random_state = v5;
dword_685440[v5] = result;
return result;
}
dword_685440
is an int[16]
, and random_state
is mutated as you can see.
I was thinking it may be a twister. Does anyone recognize this algorithm?
Looks like it could be a linear feedback shift register algorithm. Those can be implemented at the word level by a combination of bit shifting and XOR operations, which is what this seems to be up to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With