diff --git a/include/Network/network.h b/include/Network/network.h index 7481771..bc64566 100644 --- a/include/Network/network.h +++ b/include/Network/network.h @@ -17,7 +17,6 @@ extern std::string UlStatus; extern std::string ListOfMods; void UDPSend(std::string Data); int KillSocket(uint64_t Dead); -void ClosePublic(); void CoreNetwork(); void GameSend(std::string Data); void SendLarge(std::string Data); diff --git a/include/Security/Init.h b/include/Security/Init.h index 1ab979e..bbb7727 100644 --- a/include/Security/Init.h +++ b/include/Security/Init.h @@ -6,8 +6,7 @@ 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 FindDLL(const std::string& Name); void SecurityCheck(char* argv[]); +void FindDLL(char* args[]); std::string GetGameDir(); void LegitimacyCheck(); -void DASM(); diff --git a/src/Logger.cpp b/src/Logger.cpp index 0aff62e..c403928 100644 --- a/src/Logger.cpp +++ b/src/Logger.cpp @@ -66,9 +66,12 @@ void warn(const std::string& toPrint){ addToLog(Print); } void error(const std::string& toPrint) { + static int ECounter = 0; std::string Print = getDate() + Sec("[ERROR] ") + toPrint + "\n"; std::cout << Print; addToLog(Print); + if(ECounter > 10)exit(7); + ECounter++; } void except(const std::string& toPrint) { std::string Print = getDate() + Sec("[EXCEP] ") + toPrint + "\n"; diff --git a/src/Network/Core.cpp b/src/Network/Core.cpp index d7b9416..589ee77 100644 --- a/src/Network/Core.cpp +++ b/src/Network/Core.cpp @@ -227,7 +227,7 @@ void CoreMain() { int Handle(EXCEPTION_POINTERS *ep){ char* hex = new char[100]; sprintf_s(hex,100, "%lX", ep->ExceptionRecord->ExceptionCode); - except(Sec("(Core) ") + std::string(hex)); + except(Sec("(Core) Code : ") + std::string(hex)); delete [] hex; return 1; } diff --git a/src/Network/GlobalHandler.cpp b/src/Network/GlobalHandler.cpp index bb13fbb..c9b9145 100644 --- a/src/Network/GlobalHandler.cpp +++ b/src/Network/GlobalHandler.cpp @@ -90,7 +90,12 @@ void ServerSend(std::string Data, bool Rel){ } } -void ClosePublic(){ +void NetReset(){ + TCPTerminate = false; + GConnected = false; + Terminate = false; + UlStatus = Sec("Ulstart"); + MStatus = " "; if(UDPSock != (SOCKET)(-1)){ debug(Sec("Terminating UDP Socket : ") + std::to_string(TCPSock)); KillSocket(UDPSock); @@ -101,15 +106,6 @@ void ClosePublic(){ KillSocket(TCPSock); } TCPSock = -1; -} - -void NetReset(){ - TCPTerminate = false; - GConnected = false; - Terminate = false; - UlStatus = Sec("Ulstart"); - MStatus = " "; - ClosePublic(); if(GSocket != (SOCKET)(-1)){ debug(Sec("Terminating GTCP Socket : ") + std::to_string(GSocket)); KillSocket(GSocket); diff --git a/src/Security/Checker.cpp b/src/Security/Checker.cpp index 4479d14..5ff63c3 100644 --- a/src/Security/Checker.cpp +++ b/src/Security/Checker.cpp @@ -23,20 +23,6 @@ void DAS(){ f.close(); #endif } -void DASM(){ -#ifndef DEBUG - int i = 0; - std::ifstream f(GetEN(), std::ios::binary); - f.seekg(0, std::ios_base::end); - std::streampos fileSize = f.tellg(); - if(IsDebuggerPresent() || fileSize > 0x4C4B40){ - i++; - DAboard(); - } - if(i)DAboard(); - f.close(); -#endif -} DWORD getParentPID(DWORD pid){ HANDLE h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); PROCESSENTRY32 pe = {0}; diff --git a/src/Security/DLL.cpp b/src/Security/DLL.cpp index eca5f30..cb7dd6b 100644 --- a/src/Security/DLL.cpp +++ b/src/Security/DLL.cpp @@ -4,44 +4,52 @@ #include "Network/network.h" #include "Security/Enc.h" #include -#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::milliseconds(200)); - ClosePublic(); + std::this_thread::sleep_for(std::chrono::seconds(2)); + NetReset(); #ifdef DEBUG - debug("NetReset Check!"); + debug(Sec("Attention! NetReset Check!")); #endif } } -void FindDLL(const std::string& Name) { - static std::string PName = LocalEnc(Name.substr(0,Name.rfind(Sec("\\")))); - static bool Running = false; - if(Running)return; +void FindDLL(char* args[]){ + static auto argv = args; HANDLE hProcess = GetCurrentProcess(); - HMODULE hMods[1024]; - DWORD cbNeeded; - unsigned int i; - TCHAR szModName[MAX_PATH]; - if (K32EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded)) { - for (i = 1; i < (cbNeeded / sizeof(HMODULE)); i++) { - if (K32GetModuleFileNameExA(hProcess, hMods[i], szModName, sizeof(szModName) / sizeof(TCHAR))) { - std::string MName(szModName); - MName = MName.substr(0, MName.rfind(Sec("\\"))); - if (MName == LocalDec(PName)) { - Running = true; - std::thread t1(Kill); - t1.detach(); + 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(); + } } + ZeroMemory(szModName,MAX_PATH); } - ZeroMemory(szModName, MAX_PATH); } } CloseHandle(hProcess); diff --git a/src/Startup.cpp b/src/Startup.cpp index cd7b74a..1c258cc 100644 --- a/src/Startup.cpp +++ b/src/Startup.cpp @@ -181,7 +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[0]); + FindDLL(argv); SecurityCheck(argv); Discord_Main(); RequestRole(); diff --git a/src/main.cpp b/src/main.cpp index 11f4314..6e17c0e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,7 +19,6 @@ int main(int argc, char* argv[]) { std::thread gb(aa); gb.detach(); #endif - DASM(); InitLauncher(argc,argv); CheckDir(argc,argv); LegitimacyCheck();