MCPcopy Create free account
hub / github.com/NoMercy-ac/NoMercy / ParentCheck

Method ParentCheck

Source/Client/NM_Engine/ParentCheck.cpp:110–284  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108
109
110bool CAntiDebug::ParentCheck(const char* c_szPatcherName)
111{
112 std::string szLowerPatcherName(c_szPatcherName, strnlen(c_szPatcherName, MAX_PATH));
113 std::transform(szLowerPatcherName.begin(), szLowerPatcherName.end(), szLowerPatcherName.begin(), tolower);
114 DEBUG_LOG(LL_SYS, "Patcher Name: %s", szLowerPatcherName.c_str());
115
116 // Process informations
117 STARTUPINFOA si = { 0 };
118 si.cb = sizeof(si);;
119 g_winapiApiTable->GetStartupInfoA(&si);
120
121 auto dwCurrentPID = g_winapiApiTable->GetCurrentProcessId();
122 auto dwParentPID = CProcessFunctions::GetProcessParentProcessId(dwCurrentPID);
123 auto dwParentPIDFromPEB = CProcessFunctions::GetParentProcessIdNative(NtCurrentProcess);
124 DEBUG_LOG(LL_SYS, "Current PID: %u Parent PID: %u/%u", dwCurrentPID, dwParentPID, dwParentPIDFromPEB);
125
126 if (dwParentPID != dwParentPIDFromPEB) { /* Anti Parent pid manipulation */
127 DEBUG_LOG(LL_ERR, "Parent PID manipulation detected! IsVista/+: %d Parent pid: %u Parent pid PEB: %u", IsWindowsVistaOrGreater(), dwParentPID, dwParentPIDFromPEB);
128 return false;
129 }
130
131 auto processEnumerator = std::make_unique<CSafeProcessHandle>();
132 if (!processEnumerator || !processEnumerator.get()) {
133 DEBUG_LOG(LL_ERR, "processEnumerator allocation failed! Last error: %u", g_winapiApiTable->GetLastError());
134 return false;
135 }
136
137 auto hProcess = processEnumerator->FindProcessFromPID(dwParentPID);
138 if (!IS_VALID_HANDLE(hProcess))
139 {
140 DEBUG_LOG(LL_ERR, "Parent process not found on process list! PID: %u", dwParentPID);
141 return true;
142#if 0
143 hProcess = g_winapiApiTable->OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, dwParentPID);
144 if (!IS_VALID_HANDLE(hProcess)) {
145 auto bIsAlive = CProcessFunctions::ProcessIsItAlive(dwParentPID);
146 DEBUG_LOG(LL_ERR, "Parent process can not open! Last error: %u IsAlive: %d", g_winapiApiTable->GetLastError(), bIsAlive);
147 return false;
148 }
149#endif
150 }
151
152 auto szParentName = CProcessFunctions::GetProcessName(hProcess);
153 if (szParentName.empty()) {
154 DEBUG_LOG(LL_ERR, "Parent process name not found!");
155 g_nmApp->DynamicWinapiInstance()->SafeCloseHandle(hProcess);
156 return false;
157 }
158 auto szLowerParentName = g_nmApp->FunctionsInstance()->szLower(szParentName);
159 auto szParentProcessPath = g_nmApp->DirFunctionsInstance()->GetPathFromProcessName(szLowerParentName);
160 auto szParentProcessName = g_nmApp->DirFunctionsInstance()->GetNameFromPath(szLowerParentName);
161 g_nmApp->DynamicWinapiInstance()->SafeCloseHandle(hProcess);
162
163 DEBUG_LOG(LL_SYS, "Parent process: %s(%u)", szLowerParentName.c_str(), dwParentPID);
164
165 // Windows informations
166 auto szWindowsPath = g_nmApp->DirFunctionsInstance()->WinPath();
167 auto szLowerWindowsPath = g_nmApp->FunctionsInstance()->szLower(szWindowsPath);

Callers

nothing calls this directly

Calls 15

IsWindowsVistaOrGreaterFunction · 0.85
ParentOfParentPIDIsLegitFunction · 0.85
beginMethod · 0.80
endMethod · 0.80
FindProcessFromPIDMethod · 0.80
OpenProcessMethod · 0.80
SafeCloseHandleMethod · 0.80
DynamicWinapiInstanceMethod · 0.80
szLowerMethod · 0.80
FunctionsInstanceMethod · 0.80

Tested by

no test coverage detected