diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e0b48e..f4a5221 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,4 +4,4 @@ project(BeamNG-MP-Launcher) set(CMAKE_CXX_STANDARD 14) -add_executable(BeamNG-MP-Launcher main.cpp enet.h proxy.cpp) +add_executable(BeamNG-MP-Launcher main.cpp enet.h proxy.cpp Security.cpp) diff --git a/Security.cpp b/Security.cpp new file mode 100644 index 0000000..c4812b9 --- /dev/null +++ b/Security.cpp @@ -0,0 +1,175 @@ +/// +/// Created by Anonymous275 on 3/16/2020 +/// + +#include +#include +#include + +#define MAX_KEY_LENGTH 255 +#define MAX_VALUE_NAME 16383 +void Exit(const std::string& Msg); +int TraceBack = 0; + +std::vector Data; +std::string Result; + +std::string HTA(std::string hex) +{ + std::string ascii; + for (size_t i = 0; i < hex.length(); i += 2) + { + std::string part = hex.substr(i, 2); + char ch = stoul(part, nullptr, 16); + ascii += ch; + } + return ascii; +} +LONG OpenKey(HKEY root,const char* path,PHKEY hKey){ + return RegOpenKeyEx(root, reinterpret_cast(path), 0, KEY_READ, hKey); +} + + + +std::string QueryKey(HKEY hKey,int ID) +{ + TCHAR achKey[MAX_KEY_LENGTH]; // buffer for subkey name + DWORD cbName; // size of name string + TCHAR achClass[MAX_PATH] = TEXT(""); // buffer for class name + DWORD cchClassName = MAX_PATH; // size of class string + DWORD cSubKeys=0; // number of subkeys + DWORD cbMaxSubKey; // longest subkey size + DWORD cchMaxClass; // longest class string + DWORD cValues; // number of values for key + DWORD cchMaxValue; // longest value name + DWORD cbMaxValueData; // longest value data + DWORD cbSecurityDescriptor; // size of security descriptor + FILETIME ftLastWriteTime; // last write time + + DWORD i, retCode; + + TCHAR achValue[MAX_VALUE_NAME]; + DWORD cchValue = MAX_VALUE_NAME; + + retCode = RegQueryInfoKey( + hKey, // key handle + achClass, // buffer for class name + &cchClassName, // size of class string + NULL, // reserved + &cSubKeys, // number of subkeys + &cbMaxSubKey, // longest subkey size + &cchMaxClass, // longest class string + &cValues, // number of values for this key + &cchMaxValue, // longest value name + &cbMaxValueData, // longest value data + &cbSecurityDescriptor, // security descriptor + &ftLastWriteTime); // last write time + + + + BYTE* buffer = new BYTE[cbMaxValueData]; + ZeroMemory(buffer, cbMaxValueData); + if (cSubKeys) + { + for (i=0; i(buffer); + std::string key = achValue; + switch (ID){ + case 1: if(key == "InstallLocation" && (data.find("BeamNG") != std::string::npos)) {return data;} break; + case 2: if(key == "Name" && data == "BeamNG.drive") {return data;} break; + case 3: return data.substr(0,data.length()-2); break; + default: break; + } + /*if(data.find(':') != std::string::npos){ + return data.substr(0,data.length()-2); + }*/ + } + } + } + delete [] buffer; + return ""; +} + +std::vector Check(){ + std::string K1 = R"(SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\)"; + std::string K2 = R"(Software\Valve\Steam\Apps\284160)"; + std::string K3 = R"(beamng\DefaultIcon)"; + HKEY hKey; + LONG dwRegOPenKey = OpenKey(HKEY_LOCAL_MACHINE, K1.c_str(), &hKey); + if(dwRegOPenKey == ERROR_SUCCESS) { + Result = QueryKey(hKey, 0); + if(Result.empty()){Exit("Error! you do not own BeamNG!");} + Data.push_back(Result); + K1 += Result; + TraceBack++; + }else{Exit("Error! Please Contact Support");} + + RegCloseKey(hKey); + dwRegOPenKey = OpenKey(HKEY_LOCAL_MACHINE, K1.c_str(), &hKey); + if(dwRegOPenKey == ERROR_SUCCESS) { + Result = QueryKey(hKey, 1); + if(Result.empty()){Exit("Error! you do not own BeamNG!");} + Data.push_back(Result); + TraceBack++; + }else{Exit("You do not own the game on this machine!");} + K1.clear(); + RegCloseKey(hKey); + dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K2.c_str(), &hKey); + if(dwRegOPenKey == ERROR_SUCCESS) { + Result = QueryKey(hKey, 2); + if(Result.empty()){Exit("Error! you do not own BeamNG!");} + Data.push_back(Result); + TraceBack++; + }else{Exit("You do not own the game on this machine!");} + K2.clear(); + RegCloseKey(hKey); + dwRegOPenKey = OpenKey(HKEY_CLASSES_ROOT, K3.c_str(), &hKey); + if(dwRegOPenKey == ERROR_SUCCESS) { + Result = QueryKey(hKey, 3); + if(Result.empty()){ + Exit("Error! Please Contact Support"); + }else if(Result.find(Data.at(1)) != 0){ + Exit("Warning! you own the game but a cracked game was found on your machine!"); + } + TraceBack++; + } + K3.clear(); + RegCloseKey(hKey); + return Data; +} diff --git a/main.cpp b/main.cpp index 32ccd91..bacd621 100644 --- a/main.cpp +++ b/main.cpp @@ -2,145 +2,31 @@ //// Created by Anonymous275 on 3/3/2020. //// -#include #include #include -#include +#include -#define MAX_KEY_LENGTH 255 -#define MAX_VALUE_NAME 16383 -std::string keyName; -std::string HTA(std::string hex) -{ - std::string ascii; - for (size_t i = 0; i < hex.length(); i += 2) - { - std::string part = hex.substr(i, 2); - char ch = stoul(part, nullptr, 16); - ascii += ch; - } - return ascii; +std::vector Check(); + +void Exit(const std::string& Msg){ + std::cout << Msg << std::endl; + std::cout << "Press Enter to Continue..."; + std::cin.ignore(); + exit(-1); } - -std::string QueryKey(HKEY hKey) -{ - TCHAR achKey[MAX_KEY_LENGTH]; // buffer for subkey name - DWORD cbName; // size of name string - TCHAR achClass[MAX_PATH] = TEXT(""); // buffer for class name - DWORD cchClassName = MAX_PATH; // size of class string - DWORD cSubKeys=0; // number of subkeys - DWORD cbMaxSubKey; // longest subkey size - DWORD cchMaxClass; // longest class string - DWORD cValues; // number of values for key - DWORD cchMaxValue; // longest value name - DWORD cbMaxValueData; // longest value data - DWORD cbSecurityDescriptor; // size of security descriptor - FILETIME ftLastWriteTime; // last write time - - DWORD i, retCode; - - TCHAR achValue[MAX_VALUE_NAME]; - DWORD cchValue = MAX_VALUE_NAME; - - retCode = RegQueryInfoKey( - hKey, // key handle - achClass, // buffer for class name - &cchClassName, // size of class string - NULL, // reserved - &cSubKeys, // number of subkeys - &cbMaxSubKey, // longest subkey size - &cchMaxClass, // longest class string - &cValues, // number of values for this key - &cchMaxValue, // longest value name - &cbMaxValueData, // longest value data - &cbSecurityDescriptor, // security descriptor - &ftLastWriteTime); // last write time - - - - BYTE* buffer = new BYTE[cbMaxValueData]; - ZeroMemory(buffer, cbMaxValueData); - - if (cValues) - { - for (i=0, retCode = ERROR_SUCCESS; i(buffer); - std::string key = achValue; - if(data.find(':') != std::string::npos){ - return data.substr(0,data.length()-2); - } - if(key == "Name" && data == "BeamNG.drive"){ - return "check"; - } - } - } - }else{ - std::cout << "Error Failed to Find Beamng\n"; - } - delete [] buffer; - return ""; -} -void start(); - -void getPath(){ - HKEY hKey; - LONG dwRegOPenKey = RegOpenKeyEx(HKEY_CLASSES_ROOT, HTA("6265616d6e675c44656661756c7449636f6e").c_str()/*"beamng\\DefaultIcon"*/, 0, KEY_READ, &hKey); - if(dwRegOPenKey != ERROR_SUCCESS){ - std::cout << "Error #1\n"; - }else{ - keyName = QueryKey(hKey); - std::cout << "full path : " << keyName << std::endl; - } - RegCloseKey(hKey); -} - +void ProxyStart(); int main() { //Security - HKEY hKey; - LONG dwRegOPenKey = RegOpenKeyEx(HKEY_CURRENT_USER, HTA("536f6674776172655c56616c7665").c_str(), 0, KEY_READ, &hKey); - if(dwRegOPenKey != ERROR_SUCCESS){ - std::cout << HTA("4572726f7220506c6561736520436f6e7461637420537570706f7274210a"); - }else { - dwRegOPenKey = RegOpenKeyEx(HKEY_CURRENT_USER, - HTA("536f6674776172655c56616c76655c537465616d5c417070735c323834313630").c_str(), 0, - KEY_READ, &hKey); - if (dwRegOPenKey != ERROR_SUCCESS) { - std::cout << HTA("796f7520646f206e6f74206f776e207468652067616d65206f6e2074686973206d616368696e65210a"); - } else { - keyName = QueryKey(hKey); - if (!keyName.empty()) { - std::cout << HTA("796f75206f776e207468652067616d65206f6e2074686973206d616368696e65210a"); - getPath(); - } else { - std::cout << HTA("796f7520646f206e6f74206f776e207468652067616d65206f6e2074686973206d616368696e65210a"); - } - } - //Software\Classes\beamng\DefaultIcon - RegCloseKey(hKey); - } + std::vector Data = Check(); + + std::cout << Data.at(1) << std::endl; /// Update, Mods ect... //Start(); //Proxy main start - system("pause"); + Exit(""); return 0; } \ No newline at end of file diff --git a/proxy.cpp b/proxy.cpp index 5bbe680..9c9ace4 100644 --- a/proxy.cpp +++ b/proxy.cpp @@ -199,7 +199,7 @@ void RUDPClientThread(){ } -void Start(){ +void ProxyStart(){ std::thread t1(TCPServerThread); std::thread t2(RUDPClientThread); t2.join();