Valhalla Legends Forums Archive | Battle.net Bot Development References | [C/C++]CalcHashBuf

AuthorMessageTime
TheMinistered
Before being flamed, I aquired this source from a website were it was publicly released. Knowing that it's publicly released, and there is no extra information provided by the author of the source; i'm going to post it here.

[code]
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]

Now... all you visual basic user's have fun converting it from c++ :D It shouldn't be too hard. The first thing you want to do is implement some of the unsupported bitwise operators (examples being the L/R shift operators)

[edit] I didn't look @ the source too long. If there is any other function(s) called by any of the above that aren't provided tell me. I will post them also.
May 2, 2003, 1:08 AM
Kp
[quote author=TheMinistered link=board=17;threadid=1208;start=0#msg8970 date=1051837705]
If there is any other function(s) called by any of the above that aren't provided tell me. I will post them also.[/quote]memcpy and ZeroMemory ;)
May 2, 2003, 3:56 AM
Camel
heck, i may as well give people a head start on the vb version ;)

[code]Public Function CalcHashBuf(ByVal buf As String) As String
Dim pos As Long, sublen As Long
Dim hashbuf(&H10 + 5) As Long
hashbuf(0) = &H67452301
hashbuf(1) = &HEFCDAB89
hashbuf(2) = &H98BADCFE
hashbuf(3) = &H10325476
hashbuf(4) = &HC3D2E1F0
For pos = 0 To Len(buf) Step &H40
sublen = Len(buf) - pos
If sublen > &H40 Then sublen = &H40

Dim t As String
t = Mid(buf, pos + 1, sublen) & String(&H40 - sublen, Chr(0))
Dim i As Long
For i = 0 To 15
hashbuf(5 + i) = CVL(Mid(t, i * 4 + 1, 4))
Next
datahash hashbuf
Next
CalcHashBuf = MKL(hashbuf(0)) & MKL(hashbuf(1)) & MKL(hashbuf(2)) & MKL(hashbuf(3)) & MKL(hashbuf(4))
End Function[/code]

you can port hashdata yourself ;)
May 4, 2003, 1:47 AM
Camel
[quote author=Maddox link=board=17;threadid=1208;start=0#msg8975 date=1051854291]
Or...

[code]
void HashData(void* lpSource, int nLength, void* lpResult)
{
...
}
[/code]
[/quote]
isn't that totally defunct by now?
May 4, 2003, 1:52 AM
TheMinistered
Aww... camel you take all the fun out of it :) well not really the newbies will never port it because they don't have enough math skills to implement the missing bitwise functions, gg :)
May 4, 2003, 1:52 AM
TheMinistered
[code]
if(sublen<0x40)
ZeroMemory((char*)(hashbuf+5)+sublen, 0x40-sublen);
[/code]

where did you implement that in your version? you might have... i just scanned your code a little bit.

[edit] I missed the very end of the code line where you move data into variable t
May 4, 2003, 1:58 AM
Camel
[quote author=TheMinistered link=board=17;threadid=1208;start=0#msg9102 date=1052013151]
Aww... camel you take all the fun out of it :) well not really the newbies will never port it because they don't have enough math skills to implement the missing bitwise functions, gg :)
[/quote]

it requires writing an lshift(), rshift(), and add() function (need add because vb refuses to stop checking for overflows unless you compile, and then it'll just crash if you overflow)

[code] G = buf(i)
G = Add(G, Rol(A, 5))
G = Add(G, E)
G = Add(G, ((B And C) Or ((Not B) And D)))
G = Add(G, &H5A827999)[/code]
May 4, 2003, 2:06 AM
TheMinistered
[code]
Rol(A, 5)
[/code]

You forgot to mention you need bitwise rotations too?
May 4, 2003, 2:26 AM
Camel
[quote author=TheMinistered link=board=17;threadid=1208;start=0#msg9111 date=1052015174]
[code]
Rol(A, 5)
[/code]

You forgot to mention you need bitwise rotations too?
[/quote]

_asm shl [TheMinistered], SizeOf(forum)*8

[edit] forgot it shifts bits not bytes >.<
May 4, 2003, 2:43 AM
Yoni
shl isn't a bitwise rotation, it's a bitwise shift left.
rol is a bitwise rotate left, and ror is a bitwise rotate right.

Also, rcl and rcr extend the operand by 1 bit by using CF (the Carry Flag) as the 33rd bit (assuming the operand is 32 bits), and perform the bitwise rotation.

The above sentences assume x86.
May 4, 2003, 3:04 AM
TheMinistered
Yoni, where are you getting that? I don't see anyone here saying that shl is a bitwise rotation..
May 4, 2003, 3:02 PM
Arta
TheMinistered:

[quote author=Camel link=board=17;threadid=1208;start=0#msg9116 date=1052016185]
[quote author=TheMinistered link=board=17;threadid=1208;start=0#msg9111 date=1052015174]
[code]
Rol(A, 5)
[/code]
[/quote]
...
_asm shl [TheMinistered], SizeOf(forum)*8
[/quote]
May 5, 2003, 6:42 PM
Camel
[quote author=Arta[vL] link=board=17;threadid=1208;start=0#msg9201 date=1052160137]
TheMinistered:

[quote author=Camel link=board=17;threadid=1208;start=0#msg9116 date=1052016185]
[quote author=TheMinistered link=board=17;threadid=1208;start=0#msg9111 date=1052015174]
[code]
Rol(A, 5)
[/code]
[/quote]
...
_asm shl [TheMinistered], SizeOf(forum)*8
[/quote]
[/quote]

that doesn't answer the question
nobody said or even implied that shl rotates; the whole idea was that i was pushing the data at [TheMinistered] left by the number of bits in the forum. he wasn't supposed to pop back up on the other end.
May 5, 2003, 10:09 PM
TheMinistered
call createbird
push storm
push shit
call birdexcrete
May 8, 2003, 1:23 AM

Search