Advertisement
Guest User

meh

a guest
Jan 17th, 2011
770
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.62 KB | None | 0 0
  1. unsigned int hash(unsigned char* inpStr, size_t len)
  2. {
  3.     unsigned int value = 0,temp = 0;
  4.     for(size_t i=0;i<len;i++)
  5.     {
  6.         temp = inpStr[i];
  7.         temp += value;
  8.         value = temp << 10;
  9.         temp += value;
  10.         value = temp >> 6;
  11.         value ^= temp;
  12.     }
  13.     temp = value << 3;
  14.     temp += value;
  15.     unsigned int temp2 = temp >> 11;
  16.     temp = temp2 ^ temp;
  17.     temp2 = temp << 15;
  18.     value = temp2 + temp;
  19.     if(value < 2) value += 2;
  20.     return value;
  21. }
  22.  
  23. Microsoft::Win32::RegistryKey^ GetNetworkRegistryKey(String^ id) {
  24.     try
  25.     {
  26.         Microsoft::Win32::RegistryKey^ networkInterfaceKey = Microsoft::Win32::Registry::LocalMachine->OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}", false);
  27.         cli::array<String^>^ keyNames = networkInterfaceKey->GetSubKeyNames();
  28.  
  29.         for each (String^ keyName in keyNames) {
  30.             Microsoft::Win32::RegistryKey^ key = networkInterfaceKey->OpenSubKey(keyName);
  31.  
  32.             String^ value = (String^)key->GetValue("NetCfgInstanceId", "");
  33.             if (value == id) {
  34.                 return key;
  35.             }
  36.         }
  37.  
  38.         return nullptr;
  39.     }
  40.     catch (System::Security::SecurityException^)
  41.     {
  42.         return nullptr;
  43.     }
  44. }
  45.  
  46. String^ GetDeviceIDForDriverKey(String^ key)
  47. {
  48.     int index = 0;
  49.     char buffer[1024];
  50.     String^ deviceID = "";
  51.  
  52.     SP_DEVINFO_DATA data;
  53.     memset(&data, 0, sizeof(data));
  54.     data.cbSize = sizeof(data);
  55.  
  56.     HDEVINFO handle = SetupDiGetClassDevs(&GUID_DEVCLASS_NET, NULL, NULL, DIGCF_PRESENT);
  57.  
  58.     while (SetupDiEnumDeviceInfo(handle, index, &data))
  59.     {
  60.         index++;
  61.  
  62.         if (SetupDiGetDeviceRegistryPropertyA(handle, &data, SPDRP_DRIVER, NULL, (PBYTE)buffer, sizeof(buffer), NULL))
  63.         {
  64.             String^ key2 = gcnew String(buffer);
  65.  
  66.             if (key->Replace("HKEY_LOCAL_MACHINE\\", "")->ToLower() == key2->ToLower())
  67.             {
  68.                 if (SetupDiGetDeviceRegistryPropertyA(handle, &data, SPDRP_HARDWAREID, NULL, (PBYTE)buffer, sizeof(buffer), NULL))
  69.                 {
  70.                     deviceID = gcnew String(buffer);
  71.                 }
  72.             }
  73.         }
  74.     }
  75.  
  76.     int err = GetLastError();
  77.  
  78.     if (handle)
  79.     {
  80.         SetupDiDestroyDeviceInfoList(handle);
  81.     }
  82.  
  83.     return deviceID;
  84. }
  85.  
  86. bool IsValidInterface(String^ id, bool legacy) {
  87.     if (Environment::OSVersion->Platform != PlatformID::Win32Windows && Environment::OSVersion->Platform != PlatformID::Win32NT) {
  88.         return true;
  89.     }
  90.  
  91.     Microsoft::Win32::RegistryKey^ key = GetNetworkRegistryKey(id);
  92.  
  93.     if (key == nullptr) {
  94.         return false;
  95.     }
  96.  
  97.     String^ deviceID = GetDeviceIDForDriverKey(key->Name->Replace("SYSTEM\\CurrentControlSet\\Control\\Class\\", ""));//(String^)key->GetValue("MatchingDeviceId", "");
  98.     String^ deviceID2 = "";//(String^)key->GetValue("DeviceInstanceId", "");
  99.  
  100.     if (legacy)
  101.     {
  102.         deviceID = (String^)key->GetValue("DeviceInstanceId", "");
  103.  
  104.         return (deviceID->ToLower()->StartsWith("pci"));
  105.     }
  106.  
  107.     key->Close();
  108.  
  109.     return (deviceID->ToLower()->StartsWith("pci") || deviceID->ToLower()->StartsWith("usb") || deviceID->ToLower()->StartsWith("{") || deviceID2->ToLower()->StartsWith("pci"));
  110. }
  111.  
  112. String^ WhyInvalidInterface(String^ id) {
  113.     if (Environment::OSVersion->Platform != PlatformID::Win32Windows && Environment::OSVersion->Platform != PlatformID::Win32NT) {
  114.         return "BECAUSE I'M COOL";
  115.     }
  116.  
  117.     Microsoft::Win32::RegistryKey^ key = GetNetworkRegistryKey(id);
  118.  
  119.     if (key == nullptr) {
  120.         return "NULLPTR";
  121.     }
  122.  
  123.     String^ deviceID = (String^)key->GetValue("MatchingDeviceId", "");
  124.     String^ deviceID2 = (String^)key->GetValue("DeviceInstanceId", "");
  125.     String^ deviceID3 = GetDeviceIDForDriverKey(key->Name->Replace("SYSTEM\\CurrentControlSet\\Control\\Class\\", "")); // edit: this code wasn't used originally, and isn't used in currently released code ;)
  126.  
  127.     key->Close();
  128.  
  129.     return ("#1: " + deviceID->ToLower() + " #2: " + deviceID2->ToLower() + " #3 (AwesomeID): " + deviceID3->ToLower());
  130. }
  131.  
  132. char* lolololol = "ATTN: developer of that weird registry hook\r\nI'm sorry, but it seems you didn't read rule #724865. Read it, apply it, and maybe I'll give up. By the way, your actions did have some results: banning doesn't result in a ban anymore.";
  133.  
  134. bool IsConnectedInterface(String^ id) {
  135.     if (Environment::OSVersion->Platform != PlatformID::Win32Windows && Environment::OSVersion->Platform != PlatformID::Win32NT) {
  136.         return true;
  137.     }
  138.  
  139.     Microsoft::Win32::RegistryKey^ key = GetNetworkRegistryKey(id);
  140.  
  141.     if (key == nullptr) {
  142.         return false;
  143.     }
  144.  
  145.     cli::array<String^>^ values = key->GetValueNames();
  146.     String^ valueName = "";
  147.     bool hasProviderName = false;
  148.  
  149.     for each (String^ value in values) {
  150.         if (value->ToLower()->StartsWith("ne") && value->ToLower()->Contains("re")) {
  151.             valueName = value;
  152.         }
  153.  
  154.         if (value->ToLower()->StartsWith("pr") && value->ToLower()->Contains("rn")) {
  155.             hasProviderName = true;
  156.         }
  157.     }
  158.  
  159.     if (valueName == "") {
  160.         return true;
  161.     }
  162.  
  163.     String^ valueData = (String^)key->GetValue(valueName, "ne");
  164.     return (valueData == String::Empty) && hasProviderName;
  165. }
  166.  
  167. unsigned int steamID = 0;
  168. bool gotFakeSteamID = true;
  169. bool useNewAuthFunctions = true;
  170. bool connectedInterface = true;
  171. bool steamIDLegacy = false;
  172.  
  173. void SetSteamIDLegacy(bool legacy)
  174. {
  175.     steamIDLegacy = legacy;
  176.     steamID = 0;
  177. }
  178.  
  179. void ErrorWithWebLink(String^ error, String^ webLink);
  180.  
  181. unsigned int GetPlayerSteamID() {
  182.     //return 51393034;
  183.     //StreamReader^ reader = File::OpenText("steamID.txt");
  184.     //int id = int::Parse(reader->ReadToEnd()->Trim());
  185.     //reader->Close();
  186.     if (useNewAuthFunctions && Custom::Hook != nullptr) {
  187.         int id = Custom::Hook->GetSteamID();
  188.  
  189.         if (id != 0) {
  190.             return id;
  191.         }
  192.     }
  193.  
  194.     if (steamID == 0) {
  195.         String^ dbg = "";
  196.  
  197.         //steamID = Random::Next();
  198.         gotFakeSteamID = true;
  199.         Random^ random = gcnew Random();
  200.         steamID = random->Next();
  201.  
  202.         #if !DEDICATED
  203.         try {
  204.             cli::array<NetworkInformation::NetworkInterface^>^ ifaces = NetworkInformation::NetworkInterface::GetAllNetworkInterfaces();
  205.             for each (NetworkInterface^ iface in ifaces) {
  206.                 dbg += String::Format("Interface {0} (type {1})\r\n", iface->Description, iface->NetworkInterfaceType);
  207.  
  208.                 if (iface->NetworkInterfaceType != NetworkInterfaceType::Tunnel && iface->NetworkInterfaceType != NetworkInterfaceType::Loopback) {
  209.                     if (!IsValidInterface(iface->Id, steamIDLegacy)) {
  210.                         dbg += "INVALID INTERFACE\r\nWHY: " + WhyInvalidInterface(iface->Id) + "\r\n";
  211.                         continue;
  212.                     }
  213.  
  214.                     if (!IsConnectedInterface(iface->Id)) {
  215.                         connectedInterface = false;
  216.                         dbg += "NON-CONNECTED INTERFACE\r\n";
  217.                         continue;
  218.                     }
  219.  
  220.                         cli::array<unsigned char>^ address = iface->GetPhysicalAddress()->GetAddressBytes();
  221.  
  222.                         try {
  223.                             dbg += "MAC ADDRESS: ";
  224.  
  225.                             for (int i = 0; i < address->Length; i++)
  226.                             {
  227.                                 dbg += address[i].ToString("X2");
  228.                             }
  229.  
  230.                             dbg += "\r\n";
  231.  
  232.                             pin_ptr<unsigned char> addressPtr = &address[0];
  233.  
  234.                             steamID = hash(addressPtr, address->Length);
  235.  
  236.                             // check steamID for being '2', which happens if GetAddressBytes is a list of zero
  237.                             if (steamID == 2) {
  238.                                 dbg += "STEAMID IS 2, WHICH IS BAD\r\n";
  239.                                 continue;
  240.                             }
  241.  
  242.                             if (steamID == 0xE2642C56 || steamID == 0x6A9528FD || steamID == 0x57B3821C)
  243.                             {
  244.                                 dbg += "invalid steamid generated: " + steamID.ToString("X8") + "\r\n";
  245.                                 continue;
  246.                             }
  247.  
  248.                             gotFakeSteamID = false;
  249.  
  250.                             dbg += "KA-CHING\r\n";
  251.                             break;
  252.                         } catch (IndexOutOfRangeException^ exx) {
  253.                             dbg += "EXCEPTION\r\n";
  254.                             dbg += exx->ToString() + "\r\n";
  255.                         }
  256.                 }
  257.             }
  258.         } catch (Exception^ exe) {
  259.             dbg += "MAIN EXCEPTION\r\n";
  260.             dbg += exe->ToString() + "\r\n";
  261.         }
  262.         #endif
  263.  
  264.         if (gotFakeSteamID) {
  265. #if !DEDICATED
  266.             String^ filename = Environment::ExpandEnvironmentVariables("%appdata%\\steam_md4.dat");
  267. #else
  268.             String^ filename = "dedi_xuid.dat";
  269. #endif
  270.             if (!File::Exists(filename)) {
  271.                 FileStream^ stream = File::OpenWrite(filename);
  272.                 stream->Write(BitConverter::GetBytes(steamID), 0, 4);
  273.                 stream->Close();
  274.             } else {
  275.                 if (steamIDLegacy)
  276.                 {
  277.                     FileStream^ stream = File::OpenRead(filename);
  278.                     array<Byte>^ buffer = gcnew array<Byte>(5);
  279.                     stream->Read(buffer, 0, 4);
  280.                     steamID = BitConverter::ToUInt32(buffer, 0);
  281.                     stream->Close();
  282.                 }
  283.                 else
  284.                 {
  285.                     steamID = 2;
  286.  
  287.                     Windows::Forms::MessageBox::Show("WARNING #5C-DEV-IDGEN: please report on http://alteriw.net/ forums.\r\nDEBUG INFO: \r\n" + dbg + "\r\nTo copy this info, press Ctrl+C in this dialog window.", "alterCI");
  288.                 }
  289.             }
  290.  
  291.             if (!connectedInterface) {
  292.                 ErrorWithWebLink("The main\\iw_22.iwd file is incorrect. You might have used the 'Update' package while having an old version.\nClick OK to be directed to the alterIWnet download page.", "http://alteriw.net/viewtopic.php?f=3&t=24");
  293.                 return 2;
  294.             }
  295.         }
  296.  
  297.     }
  298.  
  299.     return steamID;
  300. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement