| 108 | |
| 109 | |
| 110 | bool 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); |
nothing calls this directly
no test coverage detected