Log in

View Full Version : Recognize any of these functions?


FrankRizzo
April 25th, 2007, 18:26
Hey guys, I'm working on a target, and have ripped enough of their code from the install routine to make a keygen, but it was so simple and unsatisfying that I have endeavored to learn what it actually DOES. I've rewritten most of the ASM in C, and it still works, (Always a good sign!), But I'm wondering if any of you guys can tell me what these functions are. (For instance if they are part of a larger encryption routine, if they are mini-TEA, a bastardized SHA-1, or a horrible hack of DES). Mods relax, I've removed the identifying things, and I'm posting only functions, not the glue that holds them together, and makes them work.

OK, here's the first one:
Code:

unsigned long MultPkgNSerial(void)
{
short len, count;
unsigned long serialProduct, packageProduct;

serialProduct = toupper((unsigned char)serial[0]);
len = strlen(serial);

for (count = 1; count < len; count++)
{
serialProduct *= toupper(serial[count]);
}

packageProduct = toupper((unsigned char)package[0]);
len = strlen(package);

for (count = 1; count < len; count++)
{
packageProduct *= toupper(package[count]);
}

return ( (serialProduct * packageProduct * PRODUCT_VERSION) ^ (0xFB4978E - PRODUCT_VERSION) ) + 0xFFFFFFFF;
}


Does that ring anyone's bell?

OK, here's the 2nd one:

Code:
void ProcessChecksum(char *checksum, unsigned long previous)
{
unsigned long dividend, quotient;

dividend = WeirdFactorial( atoi(checksum), previous );

quotient = dividend / 9;
results[5] = dividend - (quotient * 9);

dividend = quotient;
quotient = dividend / 3;
results[4] = dividend - (quotient * 3);

dividend = quotient;
quotient = dividend / 20;
results[3] = dividend - (quotient * 20);

dividend = quotient;
quotient = dividend / 10000;
results[2] = dividend - (quotient * 10000);

dividend = quotient;
quotient = dividend / 27;
results[1] = dividend - (quotient * 27);
results[0] = quotient;
}


The ASM output for that function was quite impressive. I learned about how to divide by multiplying by magic numbers. Quite interesting!

Now, the next function, I have yet to fully convert from ASM, any help in that avenue is also welcome. (Along with any identification type things).

Code:
unsigned long WeirdFactorial(unsigned long arg0, unsigned long arg4)
{
unsigned long EAX, EBX, ECX, EDX, ESI, EDI;
// Init our values
EAX = EBX = ECX = EDX = ESI = EDI = 0;

ECX = 1;
EAX = arg4;
ECX -= EAX;

if (EAX & 0x02)
{
return (EDX);
}

EDX = ECX;
EAX = 1;
do
{
EAX += EDX;
EDX *= ECX;
}
while (EDX != 0);

EDX = arg0;
EDX *= EAX;

return (EDX);
}


OK, and lastly, a relatively simple function, but I figured someone might know it:

Code:
unsigned long ModSumPlus1(char * string, unsigned long value)
{
short len, count;
unsigned long sum = 0;

len = strlen(string);

for (count = 0; count < len; count++)
{
sum += toupper(string[count]);
}
sum %= --value;
sum += 1;

return (sum);
}

I believe this to be some kind of hashing function, but I'm not really sure. The value passed in is 0x1B when it's used.


So, there you have it, do these look familiar to anyone?

LLXX
April 26th, 2007, 00:34
Nothing already invented before.

Just some crazy maths the authors thought of.

The first two are just products followed by a complicated-looking expression.

Second block of code does some modulo operations.

For the third one I'd rather you post the actual Asm, reading a mix of Asm and C is rather confusing.

The last one looks like a bad pseudorandom number generator of the linear congruential type.

(one more thing, using the Asm code verbatim is usually better than trying to reinvent it, since the compiler's output will (unless you have managed to get EXACTLY the original code and use the same compiler the original author used) certainly be different and at most times more lengthy and verbose, in addition to possibly neglecting some aspect of the code that an HLL cannot describe, such as certain idioms)

JMI
April 26th, 2007, 00:53
I'm nearly always "relaxed."

Regards,

FrankRizzo
April 26th, 2007, 18:46
Quote:
[Originally Posted by LLXX;65201]

For the third one I'd rather you post the actual Asm, reading a mix of Asm and C is rather confusing.



OK, here it is:

Code:
.text:080888D0 ; ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ S U B R O U T I N E ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
.text:080888D0
.text:080888D0 ; Attributes: bp-based frame
.text:080888D0
.text:080888D0 sub_80888D0 proc near ; CODE XREF: sub_8088630+65p
.text:080888D0 ; sub_8088720+65p ...
.text:080888D0
.text:080888D0 arg_0 = dword ptr 8
.text:080888D0 arg_4 = dword ptr 0Ch
.text:080888D0
.text:080888D0 push ebp
.text:080888D1 mov ecx, 1
.text:080888D6 mov ebp, esp
.text:080888D8 xor edx, edx
.text:080888DA mov eax, [ebp+arg_4]
.text:080888DD sub ecx, eax
.text:080888DF test al, 1
.text:080888E1 jz short loc_80888FF
.text:080888E3 mov edx, ecx
.text:080888E5 mov eax, 1
.text:080888EA lea esi, [esi+0]
.text:080888F0
.text:080888F0 loc_80888F0: ; CODE XREF: sub_80888D0+27j
.text:080888F0 add eax, edx
.text:080888F2 imul edx, ecx
.text:080888F5 test edx, edx
.text:080888F7 jnz short loc_80888F0
.text:080888F9 mov edx, [ebp+arg_0]
.text:080888FC imul edx, eax
.text:080888FF
.text:080888FF loc_80888FF: ; CODE XREF: sub_80888D0+11j
.text:080888FF pop ebp
.text:08088900 mov eax, edx
.text:08088902 retn
.text:08088902 sub_80888D0 endp


I had kinda figured that this might be a "homebrew" but I wanted to make sure, as I'm not the most well versed in cryptography.