diff --git a/CoreNetwork.cpp b/CoreNetwork.cpp index 9af3943..73eb0d9 100644 --- a/CoreNetwork.cpp +++ b/CoreNetwork.cpp @@ -66,8 +66,8 @@ std::string Parse(const std::string& Data){ if(MPDEV)std::cout << "Core Network on start!" << std::endl; WSADATA wsaData; int iResult; - SOCKET ListenSocket = INVALID_SOCKET; - SOCKET ClientSocket = INVALID_SOCKET; + auto ListenSocket = INVALID_SOCKET; + auto ClientSocket = INVALID_SOCKET; struct addrinfo *result = nullptr; struct addrinfo hints{}; @@ -136,12 +136,10 @@ std::string Parse(const std::string& Data){ std::string data = recvbuf; data.resize(iResult); Response = Parse(data) + "\n"; - } - - else if (iResult == 0) - if(MPDEV)std::cout << "(Core) Connection closing...\n"; - else { - if(MPDEV)std::cout << "(Core) recv failed with error: " << WSAGetLastError() << std::endl; + } else if (iResult == 0){ + if (MPDEV)std::cout << "(Core) Connection closing...\n"; + }else{ + if(MPDEV)std::cout << "(Core) recv failed with error: " << WSAGetLastError() << std::endl; closesocket(ClientSocket); WSACleanup(); } diff --git a/Security.cpp b/Security.cpp index 5623faf..80951a1 100644 --- a/Security.cpp +++ b/Security.cpp @@ -1,12 +1,13 @@ /// /// Created by Anonymous275 on 3/16/2020 /// - +#include #include +#include #include #include #include -#include +#include #define MAX_KEY_LENGTH 255 #define MAX_VALUE_NAME 16383 @@ -14,7 +15,7 @@ void Exit(const std::string& Msg); int TraceBack = 0; -std::vector Data; +std::vector SData; std::string Result; std::string HTA(const std::string& hex) @@ -124,8 +125,30 @@ std::string QueryKey(HKEY hKey,int ID) delete [] buffer; return ""; } +namespace fs = std::experimental::filesystem; +void FileList(std::vector&a,const std::string& Path){ + for (const auto &entry : fs::directory_iterator(Path)) { + int pos = entry.path().filename().string().find('.'); + if (pos != std::string::npos) { + a.emplace_back(entry.path().string()); + }else FileList(a,entry.path().string()); + } +} +bool Continue = false; +void Find(const std::string& FName,const std::string& Path){ + auto *FS = new std::vector; + FileList(*FS,Path); + for(const std::string&a : *FS){ + if(a.find(FName)!=std::string::npos)Continue = true; + } + delete FS; +} +void ExitError(){ + std::string MSG2 = HTA("4572726f722120506c6561736520436f6e7461637420537570706f7274"); + Exit(MSG2 + " Code 2"); +} -std::vector Check(){ +void Check(){ /*HKEY_CLASSES_ROOT\\beamng\\DefaultIcon HKEY_USERS\.DEFAULT\Software\Classes\steam\Shell\Open\Command HKEY_CURRENT_USER\\Software\Valve\Steam\Apps\284160*/ @@ -144,29 +167,14 @@ std::vector Check(){ if(dwRegOPenKey == ERROR_SUCCESS) { Result = QueryKey(hKey, 1); if(Result.empty()){Exit(MSG1 + " Code 1");} - Data.push_back(Result); + SData.push_back(Result); Result = Result.substr(1,Result.find_last_of('\\')) + HTA("7573657264617461"); struct stat buffer{}; if(stat (Result.c_str(), &buffer) == 0){ - std::string cmd = HTA("6469722022") + Result + HTA("5c3238343136302e6a736f6e22202f73202f70"); - std::array Buffer{}; - std::string result; - std::unique_ptr pipe(_popen(cmd.c_str(), "r"), _pclose); - cmd.clear(); - if (!pipe) { - Exit(MSG2+ ". Code: 1"); - } - while (fgets(Buffer.data(), Buffer.size(), pipe.get()) != nullptr) { - result += Buffer.data(); - } - std::string File = HTA("3238343136302e6a736f6e"); - if(result.size() > 100 && result.find(File) != std::string::npos){ - int pos = int(result.find(File)) + 9; - while(pos != result.length() && !isdigit(result.at(pos))){pos++;} - if(pos - result.length() < 5)Exit(MSG2 + " Code 2"); - if((result.substr(pos,1).at(0) - 48) == 0) Exit(MSG1 + " Code 2"); - }else Exit(MSG2 + " Code 2"); - result.clear(); + auto *F = new std::thread(Find,HTA("3238343136302e6a736f6e"),Result); + F->join(); + delete F; + if(!Continue)Exit(MSG2 + " Code 2"); }else Exit(MSG2 + ". Code: 3"); Result.clear(); TraceBack++; @@ -177,7 +185,7 @@ std::vector Check(){ if(dwRegOPenKey == ERROR_SUCCESS) { Result = QueryKey(hKey, 2); if(Result.empty()){Exit(MSG1 + " Code 3");} - Data.push_back(Result); + SData.push_back(Result); TraceBack++; }else{Exit(MSG3);} K2.clear(); @@ -188,7 +196,7 @@ std::vector Check(){ if(Result.empty()){ Exit(MSG2 + ". Code: 5"); } - Data.push_back(Result); + SData.push_back(Result); TraceBack++; } //Memory Cleaning @@ -198,7 +206,6 @@ std::vector Check(){ MSG2.clear(); MSG3.clear(); RegCloseKey(hKey); - return Data; } std::string HWID(){ diff --git a/UpdateCheck.cpp b/UpdateCheck.cpp index e193480..923a2eb 100644 --- a/UpdateCheck.cpp +++ b/UpdateCheck.cpp @@ -6,21 +6,23 @@ void Download(const std::string& URL,const std::string& path); std::string HTTP_REQUEST(const std::string&url,int port); +std::string HTA(const std::string& hex); void SystemExec(const std::string& cmd); void WinExec(const std::string& cmd); void CheckForUpdates(const std::string& CV){ system ("cls"); - std::string HTTP = HTTP_REQUEST("https://beamng-mp.com/builds/launcher?version=true",443); + std::string link = "https://beamng-mp.com/builds/launcher?version=true"; + std::string HTTP = HTTP_REQUEST(link,443); HTTP = HTTP.substr(HTTP.find_last_of("ver=")+1); - + link = "https://beamng-mp.com/builds/launcher?download=true"; struct stat buffer{}; if(stat ("BeamMP-Launcher.back", &buffer) == 0)remove("BeamMP-Launcher.back"); if(HTTP > CV){ std::cout << "Update found!" << std::endl; std::cout << "Updating..." << std::endl; SystemExec("rename BeamMP-Launcher.exe BeamMP-Launcher.back>nul"); - Download("https://beamng-mp.com/builds/launcher?download=true", "BeamMP-Launcher.exe"); + Download(link, "BeamMP-Launcher.exe"); WinExec("BeamMP-Launcher.exe"); exit(1); }else{ diff --git a/http.cpp b/http.cpp index 5933468..038f015 100644 --- a/http.cpp +++ b/http.cpp @@ -24,6 +24,7 @@ std::string HTTP_REQUEST(const std::string& IP,int port){ res = curl_easy_perform(curl); curl_easy_cleanup(curl); } + curl_global_cleanup(); return readBuffer; } diff --git a/main.cpp b/main.cpp index a27a60f..c831412 100644 --- a/main.cpp +++ b/main.cpp @@ -16,17 +16,21 @@ void StartGame(const std::string&ExeDir,const std::string&Current); std::string HTTP_REQUEST(const std::string&url,int port); void CheckForUpdates(const std::string& CV); std::vector GetDiscordInfo(); +extern std::vector SData; std::vector GlobalInfo; -std::vector Check(); std::string getHardwareID(); int DEFAULT_PORT = 4444; void Discord_Main(); bool MPDEV = false; void ProxyStart(); +void ExitError(); +void Check(); + void SystemExec(const std::string& cmd){ system(cmd.c_str()); } + void WinExec(const std::string& cmd){ WinExec(cmd.c_str(), SW_HIDE); } @@ -83,8 +87,9 @@ int main(int argc, char* argv[]){ const unsigned long long NPos = std::string::npos; struct stat info{}; - std::string ver = "0.92", Path = CheckDir(argv[0],ver),HTTP_Result; - CheckForUpdates(ver); + std::string ver = "0.921", link, Path = CheckDir(argv[0],ver),HTTP_Result; + std::thread CFU(CheckForUpdates,ver); + CFU.join(); if(argc > 1){ std::string Port = argv[1]; if(Port.find_first_not_of("0123456789") == NPos){ @@ -102,7 +107,8 @@ int main(int argc, char* argv[]){ } std::cout << "Client Connected!" << std::endl; - HTTP_Result = HTTP_REQUEST("https://beamng-mp.com/entitlement?did="+GlobalInfo.at(2),443); + link = "https://beamng-mp.com/entitlement?did="+GlobalInfo.at(2); + HTTP_Result = HTTP_REQUEST(link,443); if(HTTP_Result.find("\"MDEV\"") == NPos){ if (HTTP_Result.find("\"MOD\"") == NPos && HTTP_Result.find("\"EA\"") == NPos){ if (HTTP_Result.find("\"SUPPORT\"") == NPos && HTTP_Result.find("\"YT\"") == NPos){ @@ -111,21 +117,27 @@ int main(int argc, char* argv[]){ } }else MPDEV = true; //Security - std::vector Data = Check(); - std::string GamePath = Data.at(2); + auto*Sec = new std::thread(Check); + Sec->join(); + delete Sec; + if(SData.size() != 3)ExitError(); + + std::string GamePath = SData.at(2); if(MPDEV)std::cout << "You own BeamNG on this machine!" << std::endl; std::cout << "Game Version : " << CheckVer(GamePath) << std::endl; std::string ExeDir = "\""+GamePath.substr(0,GamePath.find_last_of('\\')) + R"(\Bin64\BeamNG.drive.x64.exe")"; std::string Settings = Path + "\\settings\\uiapps-layouts.json"; if(stat(Settings.c_str(),&info)!=0){ + link = "https://beamng-mp.com/client-data"; std::cout << "Downloading default config..." << std::endl; - Download("https://beamng-mp.com/client-data",Settings); + Download(link,Settings); std::cout << "Download Complete!" << std::endl; } std::cout << "Downloading mod..." << std::endl; - Download("https://beamng-mp.com/builds/client?did="+GlobalInfo.at(2),Path + R"(\mods\BeamMP.zip)"); + link = "https://beamng-mp.com/builds/client?did="+GlobalInfo.at(2); + Download(link,Path + R"(\mods\BeamMP.zip)"); std::cout << "Download Complete!" << std::endl; - + link.clear(); if(!MPDEV){ std::thread Game(StartGame,ExeDir,(Path + "\\")); Game.detach(); diff --git a/proxy.cpp b/proxy.cpp index 2b93bb3..7ec784b 100644 --- a/proxy.cpp +++ b/proxy.cpp @@ -56,7 +56,7 @@ void RUDPSEND(const std::string&Data,bool Rel){ << " : " << Data.substr(0, 10) << Data.substr(Data.length() - 10) << std::endl; - }else if(Data.length() < 100){ + }else if(MPDEV && Data.length() < 100){ std::cout << "(Game->Launcher) : " << Data << std::endl; } } @@ -270,6 +270,8 @@ void TCPServerThread(const std::string& IP, int Port){ iResult = shutdown(Socket, SD_SEND); if (iResult == SOCKET_ERROR) { if(MPDEV)std::cout << "(Proxy) shutdown failed with error: " << WSAGetLastError() << std::endl; + TCPTerminate = true; + Terminate = true; closesocket(Socket); WSACleanup(); continue; @@ -295,8 +297,8 @@ void Reset() { void ProxyThread(const std::string& IP, int Port){ Reset(); - std::thread t1(TCPServerThread,IP,Port); - t1.detach(); + auto*t1 = new std::thread(TCPServerThread,IP,Port); + t1->detach(); /*std::thread t2(VehicleNetworkStart); t2.detach();*/ } \ No newline at end of file