| 169 | } |
| 170 | |
| 171 | void IScanner::OnScanTerminatedProcess(HANDLE hProcess) |
| 172 | { |
| 173 | std::lock_guard <std::recursive_mutex> __lock(m_Mutex); |
| 174 | |
| 175 | SCANNER_LOG(LL_SYS, "Terminated process scanner has been started!"); |
| 176 | |
| 177 | if (!IS_VALID_HANDLE(hProcess) || !g_nmApp->DynamicWinapiInstance()->IsValidHandle(hProcess)) |
| 178 | return; |
| 179 | |
| 180 | auto dwProcessId = g_winapiApiTable->GetProcessId(hProcess); |
| 181 | if (!dwProcessId) |
| 182 | return; |
| 183 | |
| 184 | SCANNER_LOG(LL_SYS, "Target process id: %u", dwProcessId); |
| 185 | |
| 186 | if (IsScannedProcess(dwProcessId)) |
| 187 | { |
| 188 | SCANNER_LOG(LL_SYS, "Process already scanned!"); |
| 189 | return; |
| 190 | } |
| 191 | |
| 192 | // Add to checked list |
| 193 | m_vScannedProcessIDs.push_back(dwProcessId); |
| 194 | |
| 195 | // Quick filter for system process |
| 196 | if (dwProcessId <= 4) |
| 197 | { |
| 198 | SCANNER_LOG(LL_SYS, "System process scan passed!"); |
| 199 | return; |
| 200 | } |
| 201 | |
| 202 | // Check target pid is it our pid |
| 203 | if (g_winapiApiTable->GetCurrentProcessId() == dwProcessId) |
| 204 | { |
| 205 | SCANNER_LOG(LL_SYS, "Itself scan passed!"); |
| 206 | return; |
| 207 | } |
| 208 | |
| 209 | // Check target pid is protected from ourself |
| 210 | auto vLauncherProcesses = g_nmApp->InitMgrInstance()->m_vLaunchedProcesses; |
| 211 | if (vLauncherProcesses.empty() == false) |
| 212 | { |
| 213 | for (const auto & pCurrProc : vLauncherProcesses) |
| 214 | { |
| 215 | if (IS_VALID_SMART_PTR(pCurrProc)) |
| 216 | { |
| 217 | if (pCurrProc->dwProcessId == dwProcessId) |
| 218 | { |
| 219 | SCANNER_LOG(LL_SYS, "Target process is protected by ourself!"); |
| 220 | return; |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | // Scan routine |
| 227 | |
| 228 | /// 1 |
nothing calls this directly
no test coverage detected