home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Binary_Bot54213292002.psc / VLBot / Connection.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-06-17  |  17.2 KB  |  596 lines

  1. #ifndef CONNECTION_H
  2. #define CONNECTION_H
  3.  
  4. #include "PacketBuffer.h"
  5. #include "dmstring.h"
  6. #include "ConsoleOutput.h"
  7. #include <process.h>
  8. #include <io.h>
  9. #include "Storm.h"
  10. #include "CDKeyDecode.h"
  11.  
  12. #define CONNECTED    1
  13. #define DISCONNECTED 0
  14.  
  15. char storm[128] = "", battle[128] = "", diablo[128] = "";
  16.  
  17. typedef unsigned long (__stdcall CheckRevisionProc)(char *diablo, char *battle, char *storm, char *hashcmd, unsigned long *pa, unsigned long *pb, char *pbuf);
  18. CheckRevisionProc *CheckRevision;
  19.  
  20. DWORD __stdcall MyGetModuleFileName(HMODULE hModule, LPTSTR lpFilename, DWORD nSize);
  21. DWORD __stdcall MyGetModuleFileName(HMODULE hModule, LPTSTR lpFilename, DWORD nSize)
  22. {
  23.     if(hModule == GetModuleHandle(0)) 
  24.     {
  25.         if(nSize > strlen(diablo)) 
  26.         {
  27.             printf("Fooled verification DLL\n");
  28.             strcpy(lpFilename, diablo);
  29.             return strlen(diablo);
  30.         } 
  31.         else
  32.             return 0;
  33.     } 
  34.     else
  35.         return GetModuleFileName(hModule, lpFilename, nSize);
  36. }
  37.  
  38. class BinaryBot
  39. {
  40. public:
  41.     BinaryBot();
  42.     ~BinaryBot();
  43.  
  44.     WSADATA wsadata;
  45.     SOCKET s;
  46.     HANDLE recvevent;
  47.     CRITICAL_SECTION critsec;
  48.     ConsoleOutput *Output;
  49.     char tmppacketid;
  50.     DWORD encryptvalue;
  51.     int pingvalue;
  52.     int state;
  53.     
  54.     char pbuf[128], errorbuf[128], mpqfile[128], cdkey[128];
  55.     DWORD a, b, passbuf, makebuf;
  56.  
  57.     char homechannel[128], password[256], username[20], statstring[256], unname[20];
  58.  
  59.     char hashcmd[64];
  60.  
  61.     struct BnetPacket
  62.     {
  63.         char packetid;
  64.         unsigned short packetlen;
  65.         char *packetdata;
  66.     };
  67.  
  68.     PacketBuffer packetbuf, sendbuf;
  69.  
  70.     BOOL CheckRevision(LPCTSTR lpszFileName1, LPCTSTR lpszFileName2, LPCTSTR lpszFileName3, LPCTSTR lpszValueString, DWORD * lpdwVersion, DWORD * lpdwChecksum, LPSTR lpExeInfoString, LPCTSTR lpszMpqFileName);
  71.     void SendCDKeyCheck(LPCTSTR lpszCDKey, DWORD dwServerHashKey, LPCTSTR lpszUserName);
  72.     void datahash(unsigned long*param);
  73.     void calchashbuf(unsigned long *hash, void *inbuf, int len);
  74.     void getvalues(const char *databuf, DWORD *ping, WORD *flags, char *name, char *txt);
  75.     
  76.     bool Connect(char *szServer);
  77.     void Disconnect();
  78.     bool Startup();
  79.     bool GetData(BnetPacket &Data);
  80.     void MsgLoop();
  81. };
  82.  
  83. BinaryBot::BinaryBot()
  84. {
  85.     InitializeCriticalSection(&critsec);
  86.     Output = new ConsoleOutput(&critsec, false, 0);
  87. }
  88.  
  89. BinaryBot::~BinaryBot() { DeleteCriticalSection(&critsec); }
  90.  
  91. bool BinaryBot::Connect(char *szServer)
  92. {
  93.     Output->WriteEx(ConsoleOutput::WHITE, "Attempting to connect to %s\n", szServer);
  94.   s = INVALID_SOCKET;
  95.   state = DISCONNECTED;
  96.   if (WSAStartup(0x101,&wsadata)) 
  97.     return false;
  98.   if (wsadata.wVersion != 0x101) 
  99.   {
  100.     WSACleanup();
  101.     return false;
  102.   }
  103.   struct sockaddr_in name;
  104.   struct hostent *hp;
  105.   memset(&name, '\0', sizeof(name));
  106.   name.sin_family = AF_INET;
  107.   name.sin_port = htons(6112);
  108.   char *p = szServer;
  109.   while (*p && (isdigit(*p) || (*p == '.')))
  110.     p++;
  111.   if (*p) 
  112.   {
  113.     hp = gethostbyname(szServer);
  114.     if (hp == 0)
  115.       return false;
  116.     memcpy(&name.sin_addr, hp->h_addr, hp->h_length);
  117.   }
  118.   else
  119.     name.sin_addr.s_addr = inet_addr(szServer);
  120.   s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  121.   if (s == INVALID_SOCKET)
  122.     return false;
  123.   if (connect(s, (struct sockaddr *)&name, sizeof(name)))
  124.     return false;
  125.   recvevent = CreateEvent(0, 0, 0, 0);
  126.   WSAResetEvent(recvevent);
  127.   WSAEventSelect(s, recvevent, 0);
  128.   WSAEventSelect(s, recvevent, FD_READ | FD_CLOSE);
  129.   state = CONNECTED;
  130.   return true;
  131. }
  132.  
  133. void BinaryBot::Disconnect()
  134. {
  135.     if (s == INVALID_SOCKET)
  136.         return;
  137.     closesocket(s);
  138.     s = INVALID_SOCKET;
  139.     state = DISCONNECTED;
  140. }
  141.  
  142. bool BinaryBot::Startup()
  143. {
  144.     send(s, "\x1", 1, 0); 
  145.     packetbuf.insert((int)0);
  146.     packetbuf.insert((int)0); 
  147.     packetbuf.insert((int)0);
  148.     packetbuf.insert((int)0);
  149.     packetbuf.insert("vLBBot");
  150.     packetbuf.insert("vLBBot");
  151.     packetbuf.sendpacket(s, 0x05);
  152.  
  153.     packetbuf.insert("68XIRHSS", 8);
  154.     packetbuf.insert((int)0xa5);
  155.     packetbuf.insert((int)0);
  156.     packetbuf.sendpacket(s, 0x06);
  157.     BnetPacket Data;
  158.     for(int i = 0; i < 4; i++)
  159.     {
  160.         if(!GetData(Data)) { Output->WriteEx(ConsoleOutput::RED, "Disconnected\n"); return false; }
  161.         Sleep(300);
  162.         switch(Data.packetid)
  163.         {
  164.         case 0x05:
  165.             //nothing, account number shit doesn't matter
  166.             break;
  167.         case 0x28:
  168.             //random pw encrypt value
  169.             encryptvalue = *(unsigned long*)Data.packetdata;
  170.             Output->WriteEx(ConsoleOutput::BLUE, "Recieved random hash encrypt value: 0x%08x\n", encryptvalue);
  171.             break;
  172.         case 0x25:
  173.             //ping packet
  174.             pingvalue = *(unsigned long*)Data.packetdata;
  175.             packetbuf.insert((int)pingvalue);
  176.             packetbuf.sendpacket(s, 0x25);
  177.             break;
  178.         case 0x06:
  179.             //mpq name and hash command
  180.             memset(mpqfile, 0, sizeof(mpqfile));
  181.             memset(hashcmd, 0, sizeof(hashcmd));
  182.             memcpy(mpqfile, Data.packetdata + 7, 12);
  183.             memcpy(hashcmd, Data.packetdata + 19, Data.packetlen - 20);
  184.             Output->WriteEx(ConsoleOutput::BLUE, "Recieved hash information.\n");
  185.             break;
  186.         }
  187.     }
  188.     if(!CheckRevision("starcraft.exe", "storm.dll", "battle.snp", hashcmd, &a, &b, pbuf, mpqfile))
  189.         return false;
  190.     Output->WriteEx(ConsoleOutput::WHITE, "Checking game version...\n");
  191.     packetbuf.insert("68XIRHSS", 8);
  192.     packetbuf.insert((int)0xa5);
  193.     packetbuf.insert(a);
  194.     packetbuf.insert(b);
  195.     packetbuf.insert(pbuf);
  196.     packetbuf.sendpacket(s, 0x07);
  197.     if(!GetData(Data)) { Output->WriteEx(ConsoleOutput::RED, "Disconnected\n"); return false; }
  198.     if(memchr(Data.packetdata, 0x02, strlen(Data.packetdata)))
  199.     {
  200.         Output->WriteEx(ConsoleOutput::RED, "Battle net rejected your hash!\n");
  201.         return false;
  202.     }
  203.     else
  204.         Output->WriteEx(ConsoleOutput::GREEN, "Battle net accepted your game version.\n");
  205.  
  206.     packetbuf.sendpacket(s, 0x2d);
  207.     //Output->WriteEx(ConsoleOutput::WHITE, "Verifying CDKey...\n");
  208.     //packetbuf.insert((int)0x1a);
  209.     //packetbuf.insert((int)0);
  210.     //packetbuf.insert("tos_USA");
  211.     //packetbuf.sendpacket(s, 0x33);
  212.     //packetbuf.insert((int)0x1b);
  213.     //packetbuf.insert((int)0);
  214.     //packetbuf.insert("bnetserver.ini");
  215.     //packetbuf.sendpacket(s, 0x33);
  216.     //SendCDKeyCheck(cdkey, encryptvalue, username);
  217.     if(!GetData(Data)) { Output->WriteEx(ConsoleOutput::RED, "Disconnected\n"); return false; }
  218.     packetbuf.insert("tenb");
  219.     packetbuf.sendpacket(s, 0x14);
  220.     DWORD passwordhash[7];
  221.     passwordhash[0] = GetTickCount();
  222.     passwordhash[1] = encryptvalue;
  223.     calchashbuf(passwordhash+2, password, strlen(password));
  224.     calchashbuf(passwordhash+2, passwordhash, 7*4);
  225.     packetbuf.insert(passwordhash, 7*4);
  226.     packetbuf.insert(username);
  227.     packetbuf.sendpacket(s, 0x29);
  228.     if(!GetData(Data)) { Output->WriteEx(ConsoleOutput::RED, "Disconnected\n"); return false; }
  229.     if(memchr(Data.packetdata, 0x01, strlen(Data.packetdata)))
  230.     {
  231.         Output->WriteEx(ConsoleOutput::RED, "Login failed!\n");
  232.         return false;
  233.     }
  234.     Output->WriteEx(ConsoleOutput::GREEN, "Logon accepted!\n");
  235.     packetbuf.insert(username);
  236.     packetbuf.insert(statstring);
  237.     packetbuf.sendpacket(s, 0x0a);
  238.     packetbuf.insert("RHSS");
  239.     packetbuf.sendpacket(s, 0x0b);
  240.     packetbuf.insert((int)2);
  241.     packetbuf.insert(homechannel);
  242.     packetbuf.sendpacket(s, 0x0c);
  243.     if(!GetData(Data)) { Output->WriteEx(ConsoleOutput::RED, "Disconnected\n"); return false; } //channel list
  244.     if(!GetData(Data)) { Output->WriteEx(ConsoleOutput::RED, "Disconnected\n"); return false; } //server list
  245.     if(!GetData(Data)) { Output->WriteEx(ConsoleOutput::RED, "Disconnected\n"); return false; }
  246.     packetbuf.insert(Data.packetdata);
  247.     packetbuf.extract(unname);
  248.     packetbuf.clear();
  249.     Output->WriteEx(ConsoleOutput::YELLOW, "Base name: %s\nLogged on as %s\n", username, unname);
  250.     return true;
  251. }
  252.  
  253. void BinaryBot::MsgLoop()
  254. {
  255.     BnetPacket Data;
  256.     DWORD ping;
  257.     WORD flags;
  258.     char name[128], txt[512];
  259.     while(GetData(Data))
  260.     {
  261.         if(Data.packetid == 0x0F)
  262.         {
  263.             switch(Data.packetdata[0])
  264.             {
  265.             case 0x01:
  266.                 getvalues(Data.packetdata, &ping, &flags, name, txt);
  267.                 Output->WriteEx(ConsoleOutput::WHITE, "In channel: %s:%d:%d: %s\n", name, ping, flags, txt);
  268.                 break;
  269.             }
  270.         }
  271.     }
  272. }
  273.  
  274. void BinaryBot::getvalues(const char *databuf, DWORD *ping, WORD *flags, char *name, char *txt)
  275. {
  276.     PacketBuffer Data;
  277.     *ping = *(unsigned long *)databuf + 8;
  278.     *flags = *(unsigned short *)databuf + 4;
  279.     Data.insert(databuf);
  280.     Data += 24;
  281.     Data.extract(name);
  282.     Data += strlen(name);
  283.     Data.extract(txt);
  284. }
  285.  
  286. bool BinaryBot::GetData(BnetPacket &Data)
  287. {
  288.     char databuf[6000] = "";
  289.     char header[4] = "";
  290.     int recvlen = 0, buflen = 0;
  291.     DWORD wait = WaitForSingleObject(recvevent, 10000);
  292.     if(wait == WAIT_TIMEOUT)
  293.         return false;
  294.     recv(s, (char *)header, 4, 0);
  295.     Data.packetid = header[1];
  296.     Data.packetlen = *(unsigned short *)&header[2];
  297.     Data.packetdata = new char[Data.packetlen];
  298.     ZeroMemory(Data.packetdata, Data.packetlen);
  299.     wait = WaitForSingleObject(recvevent, 10000);
  300.     if(wait == WAIT_TIMEOUT)
  301.         return false;
  302.     while(buflen < (int)(Data.packetlen - 4))
  303.     {
  304.         recvlen = recv(s, (char *)databuf + buflen, 1, 0);
  305.         sprintf(Data.packetdata, "%s%c", Data.packetdata, databuf[buflen]);
  306.         buflen += recvlen;
  307.     }
  308.     return true;
  309. }
  310.  
  311. void BinaryBot::datahash(unsigned long*param)
  312. {
  313.     unsigned long buf[0x50];
  314.     unsigned long dw, a, b, c, d, e, *p;
  315.     int i;
  316.     memcpy(buf, param+5, 0x40);
  317.     for(i=0x10; i<0x50; i++) 
  318.     {
  319.         dw = buf[i-0x10]^buf[i-0x8]^buf[i-0xe]^buf[i-0x3];
  320.         buf[i] = (1>>(0x20-(unsigned char)dw)) | (1<<(unsigned char)dw);        
  321.     }
  322.     a = param[0];    // edi
  323.     b = param[1];    // eax
  324.     c = param[2];    // esi
  325.     d = param[3];    // edx
  326.     e = param[4];    // [+18], ebx
  327.     p = buf;        // [+14]
  328.     i = 0x14;        // [+10]
  329.     do 
  330.     {
  331.         dw = ((a<<5) | (a>>0x1b)) + ((~b & d) | (c & b)) + e + *p++ + 0x5A827999; // ecx
  332.         e = d;
  333.         d = c;
  334.         c = (b>>2)  | (b<<0x1e);
  335.         b = a;
  336.         a = dw;
  337.     } while(--i);
  338.     i = 0x14;        // [+14]
  339.     do 
  340.     {
  341.         dw = (d ^ c ^ b) + e + ((a<<5) | (a>>0x1b)) + *p++ + 0x6ED9EBA1; // ecx
  342.         e = d;
  343.         d = c;
  344.         c = (b>>2) | (b<<0x1e);
  345.         b = a;
  346.         a = dw;
  347.     } while(--i);
  348.     i = 0x14;
  349.     do 
  350.     {
  351.         dw = ((c & b) | (d & c) | (d & b)) + e + ((a<<5) | (a>>0x1b)) + *p++ - 0x70E44324; // ecx
  352.         e = d;
  353.         d = c;
  354.         c = (b>>2) | (b<<0x1e);
  355.         b = a;
  356.         a = dw;
  357.     } while(--i);
  358.  
  359.     i = 0x14;
  360.     do 
  361.     {
  362.         dw = ((a<<5) | (a>>0x1b)) + e + (d ^ c ^ b) + *p++ - 0x359D3E2A; // ecx
  363.         e = d;
  364.         d = c;
  365.         c = (b>>2) | (b<<0x1e);
  366.         b = a;
  367.         a = dw;
  368.     } while(--i);
  369.     param[0] += a;
  370.     param[1] += b;
  371.     param[2] += c;
  372.     param[3] += d;
  373.     param[4] += e;
  374.  
  375. }
  376.  
  377. void BinaryBot::calchashbuf(unsigned long *hash, void *inbuf, int len)
  378. {
  379.     char *buf = (char*)inbuf;
  380.     int pos;
  381.     int sublen;
  382.     unsigned long hashbuf[0x10 + 5];
  383.     hashbuf[0] = 0x67452301;
  384.     hashbuf[1] = 0xEFCDAB89;
  385.     hashbuf[2] = 0x98BADCFE;
  386.     hashbuf[3] = 0x10325476;
  387.     hashbuf[4] = 0xC3D2E1F0;
  388.     for(pos=0; pos<len; pos+=0x40) {
  389.         sublen = len - pos;
  390.         if(sublen > 0x40)
  391.             sublen = 0x40;
  392.         memcpy(hashbuf+5, buf+pos, sublen);
  393.         if(sublen<0x40)
  394.             ZeroMemory((char*)(hashbuf+5)+sublen, 0x40-sublen);
  395.         datahash(hashbuf);
  396.     }
  397.     memcpy(hash, hashbuf, 5*4);
  398. }
  399.  
  400. BOOL BinaryBot::CheckRevision(LPCTSTR lpszFileName1, LPCTSTR lpszFileName2, LPCTSTR lpszFileName3, LPCTSTR lpszValueString, DWORD * lpdwVersion, DWORD * lpdwChecksum, LPSTR lpExeInfoString, LPCTSTR lpszMpqFileName)
  401. {
  402.    DWORD dwMpqChecksumKeys[] = {0xE7F4CB62lu, 0xF6A14FFClu, 0xAA5504AFlu, 0x871FCDC2lu, 0x11BF6A18lu, 0xC57292E6lu, 0x7927D27Elu, 0x2FEC8733lu};
  403.    HANDLE hFile, hFileMapping;
  404.    char * s, lpszFileName[256], cOperations[16];
  405.    int nHashFile, nVariable1[16], nVariable2[16], nVariable3[16], nVariable,
  406.        i, k, nHashOperations;
  407.    DWORD dwTotalSize, dwSize, j, dwBytesRead, dwVariables[4], dwMpqKey,
  408.          * lpdwBuffer;
  409.    LPSTR lpszFileNames[3];
  410.    FILETIME ft;
  411.    SYSTEMTIME st;
  412.    LPBYTE lpbBuffer;
  413.    VS_FIXEDFILEINFO * ffi;
  414.  
  415.    s = strchr((char *) lpszMpqFileName, '.');
  416.    if (s == NULL)
  417.       return FALSE;
  418.    nHashFile = (int) (*(s - 1) - '0');
  419.    if (nHashFile > 7 || nHashFile < 0)
  420.       return FALSE;
  421.    dwMpqKey = dwMpqChecksumKeys[nHashFile];
  422.    lpszFileNames[0] = (LPSTR) lpszFileName1;
  423.    lpszFileNames[1] = (LPSTR) lpszFileName2;
  424.    lpszFileNames[2] = (LPSTR) lpszFileName3;
  425.    s = (char *) lpszValueString;
  426.    while (*s != '\0')
  427.    {
  428.       if (isalpha(*s))
  429.          nVariable = (int) (toupper(*s) - 'A');
  430.       else
  431.       {
  432.          nHashOperations = (int) (*s - '0');
  433.          s = strchr(s, ' ');
  434.          if (s == NULL)
  435.             return FALSE;
  436.          s++;
  437.          break;
  438.       }
  439.       if (*(++s) == '=')
  440.          s++;
  441.       dwVariables[nVariable] = atol(s);
  442.       s = strchr(s, ' ');
  443.       if (s == NULL)
  444.          return FALSE;
  445.       s++;
  446.    }
  447.    for (i = 0; i < nHashOperations; i++)
  448.    {
  449.       if (!isalpha(*s))
  450.          return FALSE;
  451.       nVariable1[i] = (int) (toupper(*s) - 'A');
  452.       if (*(++s) == '=')
  453.          s++;
  454.       if (toupper(*s) == 'S')
  455.          nVariable2[i] = 3;
  456.       else
  457.          nVariable2[i] = (int) (toupper(*s) - 'A');
  458.       cOperations[i] = *(++s);
  459.       s++;
  460.       if (toupper(*s) == 'S')
  461.          nVariable3[i] = 3;
  462.       else
  463.          nVariable3[i] = (int) (toupper(*s) - 'A');
  464.       s = strchr(s, ' ');
  465.       if (s == NULL)
  466.          break;
  467.       s++;
  468.    }
  469.    dwVariables[0] ^= dwMpqKey;
  470.    for (i = 0; i < 3; i++)
  471.    {
  472.       if (lpszFileNames[i][0] == '\0')
  473.          continue;
  474.       hFile = CreateFile(lpszFileNames[i],
  475.                          GENERIC_READ,
  476.                          FILE_SHARE_READ,
  477.                          NULL,
  478.                          OPEN_EXISTING,
  479.                          FILE_ATTRIBUTE_NORMAL,
  480.                          NULL);
  481.       if (hFile == (HANDLE) INVALID_HANDLE_VALUE)
  482.          return FALSE;
  483.       hFileMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
  484.       if (hFileMapping == NULL)
  485.       {
  486.          CloseHandle(hFile);
  487.          return FALSE;
  488.       }
  489.       lpdwBuffer = (LPDWORD) MapViewOfFile(hFileMapping, FILE_MAP_READ, 0, 0, 0);
  490.       if (lpdwBuffer == NULL)
  491.       {
  492.          CloseHandle(hFileMapping);
  493.          CloseHandle(hFile);
  494.          return FALSE;
  495.       }
  496.       if (i == 0)
  497.       {
  498.          GetFileTime(hFile, NULL, NULL, &ft);
  499.          FileTimeToSystemTime(&ft, &st);
  500.          dwTotalSize = GetFileSize(hFile, NULL);
  501.       }
  502.       dwSize = (GetFileSize(hFile, NULL) / 1024lu) * 1024lu;
  503.       for (j = 0; j < (dwSize / 4lu); j++)
  504.       {
  505.          dwVariables[3] = lpdwBuffer[j];
  506.          for (k = 0; k < nHashOperations; k++)
  507.          {
  508.             switch (cOperations[k])
  509.             {
  510.                case '+':
  511.                   dwVariables[nVariable1[k]] = dwVariables[nVariable2[k]] +
  512.                                                dwVariables[nVariable3[k]];
  513.                   break;
  514.                case '-':
  515.                   dwVariables[nVariable1[k]] = dwVariables[nVariable2[k]] -
  516.                                                dwVariables[nVariable3[k]];
  517.                   break;
  518.                case '^':
  519.                   dwVariables[nVariable1[k]] = dwVariables[nVariable2[k]] ^
  520.                                                dwVariables[nVariable3[k]];
  521.                   break;
  522.                default:
  523.                   return FALSE;
  524.             }
  525.          }
  526.       }
  527.       UnmapViewOfFile(lpdwBuffer);
  528.       CloseHandle(hFileMapping);
  529.       CloseHandle(hFile);
  530.    }
  531.    strcpy(lpszFileName, lpszFileName1);
  532.    dwSize = GetFileVersionInfoSize(lpszFileName, &dwBytesRead);
  533.    lpbBuffer = (LPBYTE) VirtualAlloc(NULL, dwSize, MEM_COMMIT,
  534.                                      PAGE_READWRITE);
  535.    if (lpbBuffer == NULL)
  536.       return FALSE;
  537.    if (GetFileVersionInfo(lpszFileName, NULL, dwSize, lpbBuffer) == FALSE)
  538.       return FALSE;
  539.    if (VerQueryValue(lpbBuffer, "\\", (LPVOID *) &ffi, (PUINT) &dwSize) == FALSE)
  540.       return FALSE;
  541.    *lpdwVersion = ((HIWORD(ffi->dwProductVersionMS) & 0xFF) << 24) |
  542.                   ((LOWORD(ffi->dwProductVersionMS) & 0xFF) << 16) |
  543.                   ((HIWORD(ffi->dwProductVersionLS) & 0xFF) << 8) |
  544.                   (LOWORD(ffi->dwProductVersionLS) & 0xFF);
  545.    VirtualFree(lpbBuffer, 0lu, MEM_RELEASE);
  546.    s = (char *) &lpszFileName[strlen(lpszFileName)-1];
  547.    while (*s != '\\' && s > (char *) lpszFileName)
  548.       s--;
  549.    s++;
  550.    sprintf(lpExeInfoString,
  551.            "%s %02u/%02u/%02u %02u:%02u:%02u %lu",
  552.            lpszFileName,
  553.            st.wMonth,
  554.            st.wDay,
  555.            st.wYear % 100,
  556.            st.wHour,
  557.            st.wMinute,
  558.            st.wSecond,
  559.            dwTotalSize);
  560.    *lpdwChecksum = dwVariables[2];
  561.    return TRUE;
  562. }
  563.  
  564. void BinaryBot::SendCDKeyCheck(LPCTSTR lpszCDKey, DWORD dwServerHashKey, LPCTSTR lpszUserName)
  565. {
  566.     DWORD * lpdwBuffer;
  567.     BYTE bBuffer[1024];
  568.     DWORD dwHashBuffer[256], dwProductId, dwValue1, dwValue2, dwHashKey;
  569.     WORD wLength;
  570.  
  571.     bBuffer[0] = 0xFF;
  572.     bBuffer[1] = 0x36;
  573.     lpdwBuffer = (DWORD *) &bBuffer[4];
  574.     if (DecodeCDKey(lpszCDKey, &dwProductId, &dwValue1, &dwValue2) == FALSE)
  575.         return;
  576.     dwHashKey = GetTickCount();
  577.     dwHashBuffer[0] = dwServerHashKey;
  578.     dwHashBuffer[1] = dwHashKey;
  579.     dwHashBuffer[2] = dwProductId;
  580.     dwHashBuffer[3] = dwValue1;
  581.     dwHashBuffer[4] = dwValue2;
  582.     HashData(dwHashBuffer, 20, &lpdwBuffer[6]);
  583.     lpdwBuffer[0] = 0;
  584.     lpdwBuffer[1] = strlen(lpszCDKey);
  585.     lpdwBuffer[2] = dwProductId;
  586.     lpdwBuffer[3] = dwValue1;
  587.     lpdwBuffer[4] = dwServerHashKey;
  588.     lpdwBuffer[5] = dwHashKey;
  589.     strcpy((char *) &lpdwBuffer[11], lpszUserName);
  590.     wLength = 48 + strlen(lpszUserName) + 1;
  591.     *(WORD *) &bBuffer[2] = wLength;
  592.     send(s, (const char *)bBuffer, wLength, 0);
  593.     return;
  594. }
  595.  
  596. #endif