diff --git a/include/Security/Init.h b/include/Security/Init.h index 4fae3cd..bbb7727 100644 --- a/include/Security/Init.h +++ b/include/Security/Init.h @@ -7,5 +7,6 @@ void PreGame(int argc, char* argv[],const std::string& GamePath); void InitGame(const std::string& Dir,const std::string&Current); std::string CheckVer(const std::string &path); void SecurityCheck(char* argv[]); +void FindDLL(char* args[]); std::string GetGameDir(); -void LegitimacyCheck(); \ No newline at end of file +void LegitimacyCheck(); diff --git a/src/Network/Core.cpp b/src/Network/Core.cpp index 256858f..b0b83a5 100644 --- a/src/Network/Core.cpp +++ b/src/Network/Core.cpp @@ -2,6 +2,7 @@ /// Created by Anonymous275 on 7/20/2020 /// #include "Network/network.h" +#include "Security/Init.h" #include "Security/Enc.h" #include "Curl/http.h" #include @@ -9,9 +10,9 @@ #include "Startup.h" #include "Memory.h" #include "Logger.h" +#include #include #include -#include extern int TraceBack; std::set* ConfList = nullptr; @@ -25,6 +26,7 @@ bool ModLoaded; long long ping = -1; void StartSync(const std::string &Data){ + FindDLL(nullptr); std::string IP = GetAddr(Data.substr(1,Data.find(':')-1)); if(IP.find('.') == -1){ if(IP == "DNS")UlStatus = Sec("UlConnection Failed! (DNS Lookup Failed)"); diff --git a/src/Network/DNS.cpp b/src/Network/DNS.cpp index eb85569..c2f1387 100644 --- a/src/Network/DNS.cpp +++ b/src/Network/DNS.cpp @@ -5,18 +5,19 @@ #include #include #include "Logger.h" +#include "Security/Enc.h" std::string GetAddr(const std::string&IP){ if(IP.find_first_not_of("0123456789.") == -1)return IP; WSADATA wsaData; hostent *host; if(WSAStartup(514, &wsaData) != 0){ - error("WSA Startup Failed!"); + error(Sec("WSA Startup Failed!")); WSACleanup(); return ""; } host = gethostbyname(IP.c_str()); if(!host){ - error("DNS lookup failed! on " + IP); + error(Sec("DNS lookup failed! on ") + IP); WSACleanup(); return "DNS"; } diff --git a/src/Network/GlobalHandler.cpp b/src/Network/GlobalHandler.cpp index b30bbef..d6f3248 100644 --- a/src/Network/GlobalHandler.cpp +++ b/src/Network/GlobalHandler.cpp @@ -96,17 +96,17 @@ void NetReset(){ UlStatus = Sec("Ulstart"); MStatus = " "; if(UDPSock != (SOCKET)(-1)){ - debug("Terminating UDP Socket : " + std::to_string(TCPSock)); + debug(Sec("Terminating UDP Socket : ") + std::to_string(TCPSock)); KillSocket(UDPSock); } UDPSock = -1; if(TCPSock != (SOCKET)(-1)){ - debug("Terminating TCP Socket : " + std::to_string(TCPSock)); + debug(Sec("Terminating TCP Socket : ") + std::to_string(TCPSock)); KillSocket(TCPSock); } TCPSock = -1; if(GSocket != (SOCKET)(-1)){ - debug("Terminating GTCP Socket : " + std::to_string(GSocket)); + debug(Sec("Terminating GTCP Socket : ") + std::to_string(GSocket)); KillSocket(GSocket); } GSocket = -1; @@ -202,7 +202,7 @@ void NetMain(const std::string& IP, int Port){ void TCPGameServer(const std::string& IP, int Port){ GSocket = SetupListener(); while (!TCPTerminate && GSocket != -1){ - debug("MAIN LOOP OF GAME SERVER"); + debug(Sec("MAIN LOOP OF GAME SERVER")); GConnected = false; if(!CServer){ warn(Sec("Connection still alive terminating")); @@ -262,5 +262,5 @@ void TCPGameServer(const std::string& IP, int Port){ GConnected = false; Terminate = true; if(CSocket != SOCKET_ERROR)KillSocket(CSocket); - debug("END OF GAME SERVER"); + debug(Sec("END OF GAME SERVER")); } \ No newline at end of file diff --git a/src/Security/DLL.cpp b/src/Security/DLL.cpp new file mode 100644 index 0000000..1272a08 --- /dev/null +++ b/src/Security/DLL.cpp @@ -0,0 +1,55 @@ +/// +/// Created by Anonymous275 on 11/13/2020 +/// +#include "Network/network.h" +#include "Security/Enc.h" +#include +#include "Logger.h" +#include +#include +#include + + +DWORD getParentPID(DWORD pid); +HANDLE getProcess(DWORD pid, LPSTR fname, DWORD sz); + +void Kill(){ + static bool Run = false; + if(!Run)Run = true; + else return; + while(Run){ + std::this_thread::sleep_for(std::chrono::seconds(2)); + NetReset(); + #ifdef DEBUG + debug(Sec("Attention! NetReset Check!")); + #endif + } +} + +void FindDLL(char* args[]){ + static auto argv = args; + HANDLE hProcess = GetCurrentProcess(); + std::string Parent(MAX_PATH,0); + DWORD ppid = getParentPID(GetCurrentProcessId()); + HANDLE Process = getProcess(ppid, &Parent[0], MAX_PATH); + if(Process == nullptr){ + HMODULE hMods[1024]; + DWORD cbNeeded; + unsigned int i; + if(K32EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded)){ + for ( i = 1; i < (cbNeeded / sizeof(HMODULE)); i++ ){ + TCHAR szModName[MAX_PATH]; + if (K32GetModuleFileNameExA(hProcess, hMods[i], szModName, sizeof(szModName) / sizeof(TCHAR))){ + std::string Name(szModName),PName(argv[0]); + Name = Name.substr(0,Name.rfind(Sec("\\"))); + PName = PName.substr(0,PName.rfind(Sec("\\"))); + if(Name == PName){ + std::thread t1(Kill); + t1.detach(); + } + } + } + } + } + CloseHandle(hProcess); +} \ No newline at end of file diff --git a/src/Startup.cpp b/src/Startup.cpp index cf6b28e..aaff9d1 100644 --- a/src/Startup.cpp +++ b/src/Startup.cpp @@ -16,16 +16,13 @@ extern int TraceBack; bool Dev = false; namespace fs = std::experimental::filesystem; std::string GetEN(){ - static std::string r = Sec("BeamMP-Launcher.exe"); - return r; + return std::string(Sec("BeamMP-Launcher.exe")); } std::string GetVer(){ - static std::string r = Sec("1.70"); - return r; + return std::string(Sec("1.70")); } std::string GetPatch(){ - static std::string r = Sec(""); - return r; + return std::string(Sec("")); } void ReLaunch(int argc,char*args[]){ std::string Arg; @@ -184,6 +181,7 @@ void InitLauncher(int argc, char* argv[]) { SetConsoleTitleA((Sec("BeamMP Launcher v") + std::string(GetVer()) + GetPatch()).c_str()); InitLog(); CheckName(argc, argv); + FindDLL(argv); SecurityCheck(argv); Discord_Main(); RequestRole(); diff --git a/src/main.cpp b/src/main.cpp index 9caa7e6..6e17c0e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,8 +7,6 @@ #include #include - - [[noreturn]] void aa(){ while(true){ std::cout.flush();