Valhalla Legends Archive

Programming => Battle.net Bot Development => Topic started by: Eibro on November 17, 2004, 10:02 PM

Title: [C++] War3 key algorithms
Post by: Eibro on November 17, 2004, 10:02 PM
C++ implementation of war3 key algorithms reversed from install.exe. This was an independant effort; it has nothing to do with the other war3 key code floating around. Email questions/comments to [email protected]

Get it at http://cs.smu.ca/~e_brooks/war3/
Future updates (if any) will be posted there.

The IDB is there for IDA 4.5 if anyone is interested in looking at the reversal. Also, an idc script (maketable.idc) is there that was used to format the key tables into an array.

Title: Re: [C++] War3 key algorithms
Post by: Skywing on November 17, 2004, 10:04 PM
It's not really a C++ implementation if it's mostly inline assembler :p
Title: Re: [C++] War3 key algorithms
Post by: Eibro on November 17, 2004, 10:06 PM
Quote from: Skywing on November 17, 2004, 10:04 PM
It's not really a C++ implementation if it's mostly inline assembler :p
Figured someone would say that. If I get some time (and interest) i'll convert the remaining parts (see the readme).
Title: Re: [C++] War3 key algorithms
Post by: Skywing on November 17, 2004, 11:52 PM
Quote from: Eibro[yL] on November 17, 2004, 10:06 PM
Quote from: Skywing on November 17, 2004, 10:04 PM
It's not really a C++ implementation if it's mostly inline assembler :p
Figured someone would say that. If I get some time (and interest) i'll convert the remaining parts (see the readme).
BTW, there are C++ equivalents for what you call multPass -- it's 64-bit math, though.
Title: Re: [C++] War3 key algorithms
Post by: Eibro on November 18, 2004, 06:11 AM
Quote from: Skywing on November 17, 2004, 11:52 PM
Quote from: Eibro[yL] on November 17, 2004, 10:06 PM
Quote from: Skywing on November 17, 2004, 10:04 PM
It's not really a C++ implementation if it's mostly inline assembler :p
Figured someone would say that. If I get some time (and interest) i'll convert the remaining parts (see the readme).
BTW, there are C++ equivalents for what you call multPass -- it's 64-bit math, though.
Yeah, I figured as much. Though I couldn't get the compiler to emit the correct instructons (see post in the assembly forum)
Title: Re: [C++] War3 key algorithms
Post by: iago on November 18, 2004, 11:55 AM
when we did it, Maddox was stuck on that line for quite awhile.  __int64 or long long works in C++ (VS and gcc respectively), and long works in Java.
Title: Re: [C++] War3 key algorithms
Post by: Arta on November 18, 2004, 02:45 PM
I used LARGE_INTEGER, which works quite nicely. Translates easily from the assembly. That is, if we're talking about the same bit :)
Title: Re: [C++] War3 key algorithms
Post by: Eibro on November 18, 2004, 04:32 PM
Ah, that is how I did it the first time through, but it wasn't generating the correct instructions so I scrapped it. I guess now that that problem is solved I should roll back to my previous code.union LargeInt {
struct {
unsigned long low;
unsigned long high;
};
int64 val;
};   */

BTW, we're talking about the code inside what I called 'tableMult' (.text:0041D050)
Title: Re: [C++] War3 key algorithms
Post by: Arta on November 18, 2004, 05:01 PM
I can't find anything there in my notes, I may have used TFT though.
Title: Re: [C++] War3 key algorithms
Post by: Maddox on November 18, 2004, 07:49 PM
Quote from: Skywing on November 17, 2004, 10:04 PM
It's not really a C++ implementation if it's mostly inline assembler :p

Looks more like a C implementation.

This is the way I ended up doing that specific function.


#ifdef WIN32
typedef unsigned __int64 ULONGLONG;
#else
typedef unsigned long long ULONGLONG;
#endif

DWORD Mult(DWORD Rounds, DWORD Mul, DWORD* BufA, DWORD* BufB, DWORD DecodedByte)
{
while(Rounds--)
{
ULONGLONG edxeax = (ULONGLONG)BufA[Rounds] * (ULONGLONG)Mul;
BufB[Rounds] = DecodedByte + (DWORD)edxeax;
DecodedByte = (DWORD)(edxeax >> 32);
}

return DecodedByte;
}
Title: Re: [C++] War3 key algorithms
Post by: Skywing on November 18, 2004, 10:46 PM
Recommend looking at the UInt32x32To64 macro, and the code it generates (for future reference).
Title: Re: [C++] War3 key algorithms
Post by: Maddox on November 19, 2004, 12:06 AM
Quote from: Skywing on November 18, 2004, 10:46 PM
Recommend looking at the UInt32x32To64 macro, and the code it generates (for future reference).

Except that is native only to Windows.
Title: Re: [C++] War3 key algorithms
Post by: Skywing on November 19, 2004, 12:20 AM
Yes.  However, you were reverse engineering a Windows program.
Title: Re: [C++] War3 key algorithms
Post by: Zakath on November 19, 2004, 12:34 AM
Haha...this is what I wound up with when I did my port back to C++ of the code that iago released:

void Mult( int nRounds, int nMulX, LPDWORD lpdwBufferA, LPDWORD lpdwBufferB, DWORD dwDecodedByte ) {
while ( nRounds ) {
unsigned __int64 edxeax = (unsigned __int64)((unsigned __int64)lpdwBufferA[ nRounds - 1 ] * (DWORD)nMulX);
lpdwBufferB[ --nRounds ] = dwDecodedByte + (DWORD)edxeax;
dwDecodedByte = (DWORD)(edxeax >> 32);
}
}


I would guess he called the function slightly differently than you do, since he's using different offsets into the buffers.
Title: Re: [C++] War3 key algorithms
Post by: Eibro on November 19, 2004, 08:38 AM
Quote from: Maddox on November 18, 2004, 07:49 PM
Quote from: Skywing on November 17, 2004, 10:04 PM
It's not really a C++ implementation if it's mostly inline assembler :p

Looks more like a C implementation.

This is the way I ended up doing that specific function.


#ifdef WIN32
typedef unsigned __int64 ULONGLONG;
#else
typedef unsigned long long ULONGLONG;
#endif

DWORD Mult(DWORD Rounds, DWORD Mul, DWORD* BufA, DWORD* BufB, DWORD DecodedByte)
{
while(Rounds--)
{
ULONGLONG edxeax = (ULONGLONG)BufA[Rounds] * (ULONGLONG)Mul;
BufB[Rounds] = DecodedByte + (DWORD)edxeax;
DecodedByte = (DWORD)(edxeax >> 32);
}

return DecodedByte;
}

I tried to make it easy for C programmers to use.

QuoteI would guess he called the function slightly differently than you do, since he's using different offsets into the buffers.
No, look closer. He indexes the buffer by rounds - 1 (rounds--) while I index as buflen - i - 1 (i++)
Title: Re: [C++] War3 key algorithms
Post by: Maddox on November 19, 2004, 04:46 PM
Quote from: Skywing on November 19, 2004, 12:20 AM
Yes.  However, you were reverse engineering a Windows program.

And?
Title: Re: [C++] War3 key algorithms
Post by: Skywing on November 19, 2004, 05:47 PM
Quote from: Maddox on November 19, 2004, 04:46 PM
Quote from: Skywing on November 19, 2004, 12:20 AM
Yes.  However, you were reverse engineering a Windows program.

And?
And it might be good to be familiar with the kinds of constructs that might appear in a Windows program if you're reversing Windows programs.
Title: Re: [C++] War3 key algorithms
Post by: Maddox on November 19, 2004, 10:10 PM
Quote from: Skywing on November 19, 2004, 05:47 PM
Quote from: Maddox on November 19, 2004, 04:46 PM
Quote from: Skywing on November 19, 2004, 12:20 AM
Yes.  However, you were reverse engineering a Windows program.

And?
And it might be good to be familiar with the kinds of constructs that might appear in a Windows program if you're reversing Windows programs.

Wouldn't it be better to learn what those constructs actually do, rather than just blindly using them because they're native to windows?
Title: Re: [C++] War3 key algorithms
Post by: Skywing on November 19, 2004, 11:06 PM
Quote from: Maddox on November 19, 2004, 10:10 PM
Wouldn't it be better to learn what those constructs actually do, rather than just blindly using them because they're native to windows?
Just to clarify, that was intended to be implied by "Recommend looking at the UInt32x32To64 macro, and the code it generates (for future reference)."
Title: Re: [C++] War3 key algorithms
Post by: EpicOfTimeWasted on December 02, 2004, 02:33 PM
Am I to assume it's too much to ask why my post was deleted?  It's a topic regarding C++ Warcraft 3 cdkey algorithms, and I posted my C++ implementation.  You don't like my contribution, fine, it's your forum so I'm not going to argue.  Can I at least be told why the post was deleted though?
Title: Re: [C++] War3 key algorithms
Post by: UserLoser. on December 02, 2004, 05:39 PM
Quote from: EpicOfTimeWasted on December 02, 2004, 02:33 PM
Am I to assume it's too much to ask why my post was deleted?  It's a topic regarding C++ Warcraft 3 cdkey algorithms, and I posted my C++ implementation.  You don't like my contribution, fine, it's your forum so I'm not going to argue.  Can I at least be told why the post was deleted though?

I'm not a moderator, but I'm pretty sure nobody here wants the so-called "new logon system" account-related things to be posted, or have posts which contain links to websites which have them.
Title: Re: [C++] War3 key algorithms
Post by: Adron on December 03, 2004, 01:20 PM
Quote from: UserLoser on December 02, 2004, 05:39 PM
I'm not a moderator, but I'm pretty sure nobody here wants the so-called "new logon system" account-related things to be posted, or have posts which contain links to websites which have them.

I thought others had posted links to their codes for emulating it?
Title: Re: [C++] War3 key algorithms
Post by: UserLoser. on December 03, 2004, 01:57 PM
Quote from: Adron on December 03, 2004, 01:20 PM
Quote from: UserLoser on December 02, 2004, 05:39 PM
I'm not a moderator, but I'm pretty sure nobody here wants the so-called "new logon system" account-related things to be posted, or have posts which contain links to websites which have them.

I thought others had posted links to their codes for emulating it?

As far as I know, they were removed.
Title: Re: [C++] War3 key algorithms
Post by: Eibro on December 03, 2004, 04:07 PM
Quote from: EpicOfTimeWasted on December 02, 2004, 02:33 PM
Am I to assume it's too much to ask why my post was deleted?  It's a topic regarding C++ Warcraft 3 cdkey algorithms, and I posted my C++ implementation.  You don't like my contribution, fine, it's your forum so I'm not going to argue.  Can I at least be told why the post was deleted though?
That is interesting. I didn't see anything wrong with your post either. Oh well.
Title: Re: [C++] War3 key algorithms
Post by: Adron on December 03, 2004, 04:41 PM
Quote from: UserLoser on December 03, 2004, 01:57 PM
As far as I know, they were removed.

Even iago's?
Title: Re: [C++] War3 key algorithms
Post by: UserLoser. on December 03, 2004, 04:47 PM
Quote from: Adron on December 03, 2004, 04:41 PM
Quote from: UserLoser on December 03, 2004, 01:57 PM
As far as I know, they were removed.

Even iago's?

No, pretty sure he only posted that in his forum, where he's the only moderator.