Guest User

HWID Source by frazdaz

a guest
May 10th, 2011
1,279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.41 KB | None | 0 0
  1. #pragma comment(lib, "Ws2_32.lib")
  2. #include <winsock2.h>
  3. #include <Windows.h>
  4. #include <iostream>
  5. #include <string>
  6. #define recvBuffSize 2000
  7. const std::string host = "site",
  8.                   page = "hwid.txt";
  9.  
  10. int main(void)
  11. {
  12.     HW_PROFILE_INFO hwid;
  13.     WSADATA wsData;
  14.     if (WSAStartup(MAKEWORD(2, 2), &wsData) != 0)
  15.         return 1;
  16.  
  17.     SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  18.     if (sock == INVALID_SOCKET) {
  19.         WSACleanup();
  20.         return 1;
  21.     }
  22.  
  23.     int check, i = 0;
  24.     hostent *dns;
  25.     char recieve[recvBuffSize];
  26.  
  27.     sockaddr_in sin;
  28.     sin.sin_addr.S_un.S_addr = inet_addr(host.c_str());
  29.     sin.sin_family = AF_INET;
  30.     sin.sin_port = htons(80);
  31.     std::string req;
  32.     memset(&req, 0, sizeof(req));
  33.     memset(&recieve, 0, sizeof(recieve));
  34.     req = "GET /" + page + " HTTP/1.1\r\nHOST: " + host + "\r\nUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)\r\nConnection: Close\r\n\r\n";
  35.     if (sin.sin_addr.s_addr == INADDR_NONE) {
  36.         dns = gethostbyname(host.c_str());
  37.         if (dns == NULL)
  38.             return 1;
  39.  
  40.         while (dns->h_addr_list[i]) { //loop through resolutions of hostname
  41.             sin.sin_addr.s_addr = *(unsigned int*)(dns->h_addr_list[i]);
  42.             check = connect(sock, (sockaddr*)&sin, sizeof(sin));
  43.             if (check == SOCKET_ERROR)
  44.                 i++;
  45.             else
  46.                 break;
  47.         }
  48.     } else {
  49.         check = connect(sock, (sockaddr*)&sin, sizeof(sin));
  50.         if (check == SOCKET_ERROR)
  51.             return 1;
  52.     }
  53.  
  54.     check = send(sock, req.c_str(), req.size(), NULL);
  55.     if (check == SOCKET_ERROR) {
  56.         std::cout << WSAGetLastError();
  57.         std::cin.get();
  58.         WSACleanup();
  59.         return 1;
  60.     }
  61.  
  62.     recv(sock, recieve, sizeof(recieve), NULL);
  63.     WSACleanup();
  64.  
  65.     std::string final = recieve; //convert char* to string so we can use string::erase & string::length
  66.     int x;
  67.     for (x = 0; i < final.length(); x++)
  68.         if (final.at(x) == '\r' && final.at(x + 1) == '\n' && final.at(x + 2) == '\r' && final.at(x + 3) == '\n')
  69.             break; //x is the pos where the double CRLF starts
  70.  
  71.     final.erase(0, x + 4); //remove all characters between start and the final '\n' in the CRLF
  72.  
  73.     GetCurrentHwProfile(&hwid);
  74.     if (!strcmp((char*)hwid.szHwProfileGuid, final.c_str()))
  75.         std::cout << "Passed HWID";
  76.     else
  77.         std::cout << "HWID Unsuccessful";
  78.    
  79.     std::cin.get();
  80. }
Advertisement
Add Comment
Please, Sign In to add comment