Inject multiple images Injection context Error code
| 420 | /// <param name="pCtx">Injection context</param> |
| 421 | /// <returns>Error code</returns> |
| 422 | NTSTATUS InjectionCore::InjectMultiple( InjectContext* pContext ) |
| 423 | { |
| 424 | NTSTATUS status = ERROR_SUCCESS; |
| 425 | PROCESS_INFORMATION pi = { 0 }; |
| 426 | |
| 427 | // Update PID |
| 428 | if(pContext->cfg.injectMode == Existing && pContext->pid == 0) |
| 429 | pContext->pid = pContext->cfg.pid; |
| 430 | |
| 431 | // Log some info |
| 432 | xlog::Critical( |
| 433 | "Injection initiated. Mode: %d, process type: %d, pid: %d, mmap flags: 0x%X, " |
| 434 | "erasePE: %d, unlink: %d, thread hijack: %d, init routine: '%s', init arg: '%ls'", |
| 435 | pContext->cfg.injectMode, |
| 436 | pContext->cfg.processMode, |
| 437 | pContext->pid, |
| 438 | pContext->cfg.mmapFlags, |
| 439 | pContext->cfg.erasePE, |
| 440 | pContext->cfg.unlink, |
| 441 | pContext->cfg.hijack, |
| 442 | pContext->cfg.initRoutine.c_str(), |
| 443 | pContext->cfg.initArgs.c_str() |
| 444 | ); |
| 445 | |
| 446 | // Get process for injection |
| 447 | status = GetTargetProcess( *pContext, pi ); |
| 448 | if (status != STATUS_SUCCESS) |
| 449 | return status; |
| 450 | |
| 451 | if (pContext->cfg.delay) |
| 452 | Sleep( pContext->cfg.delay ); |
| 453 | |
| 454 | // Inject all images |
| 455 | for (auto& img : pContext->images) |
| 456 | { |
| 457 | status |= InjectSingle( *pContext, *img ); |
| 458 | if (pContext->cfg.period) |
| 459 | Sleep( pContext->cfg.period ); |
| 460 | } |
| 461 | |
| 462 | // |
| 463 | // Cleanup after injection |
| 464 | // |
| 465 | if (pi.hThread) |
| 466 | { |
| 467 | if (status == STATUS_SUCCESS) |
| 468 | ResumeThread( pi.hThread ); |
| 469 | |
| 470 | CloseHandle( pi.hThread ); |
| 471 | } |
| 472 | |
| 473 | if (pi.hProcess) |
| 474 | { |
| 475 | // TODO: Decide if process should be terminated if at least one module failed to inject |
| 476 | /*if (errCode != ERROR_SUCCESS) |
| 477 | TerminateProcess( pi.hProcess, 0 );*/ |
| 478 | |
| 479 | CloseHandle( pi.hProcess ); |
no test coverage detected