Valhalla Legends Forums Archive | Battle.net Bot Development | [C++] CDKeyHashing

AuthorMessageTime
LoRd
I'm somewhat new to the C++ world, but I've been trying to write a CDKeyHashing function, and I can't seem to get it to return the proper hashed value.

[code]
BOOL _stdcall CDKeyHash(char *OutBuf, DWORD dwServerHashKey, DWORD dwProductId, DWORD dwValue1, DWORD dwValue2, DWORD dwHashKey) {
   DWORD dwHashBuffer[5];
   dwHashBuffer[0] = dwHashKey;
   dwHashBuffer[1] = dwServerHashKey;
   dwHashBuffer[2] = dwProductId;
   dwHashBuffer[3] = dwValue1;
   dwHashBuffer[4] = dwValue2;
   CalcHashBuf(dwHashBuffer, dwHashBuffer, 20);
   memcpy(OutBuf, dwHashBuffer, 20);
   return TRUE;
}

void _stdcall CalcHashBuf(unsigned long *hash, void *inbuf, int len) {
   char *buf = (char*)inbuf;
   int pos;
   int sublen;
   unsigned long hashbuf[0x10 + 5];
   hashbuf[0] = 0x67452301;
   hashbuf[1] = 0xEFCDAB89;
   hashbuf[2] = 0x98BADCFE;
   hashbuf[3] = 0x10325476;
   hashbuf[4] = 0xC3D2E1F0;
   for(pos=0; pos<len; pos+=0x40) {
      sublen = len - pos;
      if(sublen > 0x40)
         sublen = 0x40;
      memcpy(hashbuf+5, buf+pos, sublen);
      if(sublen<0x40)
         ZeroMemory((char*)(hashbuf+5)+sublen, 0x40-sublen);
      DataHash(hashbuf);
   }
   memcpy(hash, hashbuf, 5*4);
}

void _stdcall DataHash(unsigned long*param) {
   unsigned long buf[0x50];
   unsigned long dw, a, b, c, d, e, *p;
   int i;
   memcpy(buf, param+5, 0x40);
   for(i=0x10; i<0x50; i++) {
      dw = buf[i-0x10]^buf[i-0x8]^buf[i-0xe]^buf[i-0x3];
      buf[i] = (1>>(0x20-(unsigned char)dw)) | (1<<(unsigned char)dw);      
   }
   a = param[0];
   b = param[1];
   c = param[2];
   d = param[3];
   e = param[4];
   p = buf;
   i = 0x14;
   do {
      dw = ((a<<5) | (a>>0x1b)) + ((~b & d) | (c & b)) + e + *p++ + 0x5A827999;
      e = d;
      d = c;
      c = (b>>2) | (b<<0x1e);
      b = a;
      a = dw;
   } while(--i);
   i = 0x14;
   do {
      dw = (d ^ c ^ b) + e + ((a<<5) | (a>>0x1b)) + *p++ + 0x6ED9EBA1;
      e = d;
      d = c;
      c = (b>>2) | (b<<0x1e);
      b = a;
      a = dw;
   } while(--i);
   i = 0x14;
   do {
      dw = ((c & b) | (d & c) | (d & b)) + e + ((a<<5) | (a>>0x1b)) + *p++ - 0x70E44324;
      e = d;
      d = c;
      c = (b>>2) | (b<<0x1e);
      b = a;
      a = dw;
   } while(--i);

   i = 0x14;
   do {
      dw = ((a<<5) | (a>>0x1b)) + e + (d ^ c ^ b) + *p++ - 0x359D3E2A;
      e = d;
      d = c;
      c = (b>>2) | (b<<0x1e);
      b = a;
      a = dw;
   } while(--i);
   param[0] += a;
   param[1] += b;
   param[2] += c;
   param[3] += d;
   param[4] += e;
}
[/code]
Any help would be appreciated.
March 8, 2004, 12:09 AM
UserLoser.
Try:
[code]
dwHashBuffer[0] = dwHashKey;
dwHashBuffer[1] = dwServerHashKey;
dwHashBuffer[2] = dwProductId;
dwHashBuffer[3] = dwValue1;
dwHashBuffer[4] = 0;
dwHashBuffer[5] = dwValue2;
CalcHashBuf(dwHashBuffer, dwHashBuffer, 24);
[/code]
March 8, 2004, 12:16 AM
LoRd
That worked, thanks.
March 8, 2004, 12:33 AM

Search