HollowsHunter
Scans all running processes. Recognizes and dumps a variety of potentially malicious implants (replaced/implanted PEs, shellcodes, hooks, in-memory patches).
Loading...
Searching...
No Matches
process_util.h
Go to the documentation of this file.
1#pragma once
2
3#include <windows.h>
4#include <psapi.h>
5#include <iostream>
6#include "suspend.h"
7
8namespace process_util {
9
10 inline bool is_wow_64(HANDLE process)
11 {
12 HMODULE kernel32 = GetModuleHandleA("kernel32");
13 if (!kernel32) return false; // should not happen
14
15 FARPROC procPtr = GetProcAddress(kernel32, "IsWow64Process");
16 if (!procPtr) {
17 //this system does not have a function IsWow64Process
18 return false;
19 }
20 BOOL(WINAPI * is_process_wow64)(IN HANDLE, OUT PBOOL)
21 = (BOOL(WINAPI*)(IN HANDLE, OUT PBOOL))procPtr;
22
23 BOOL isCurrWow64 = FALSE;
24 if (!is_process_wow64(process, &isCurrWow64)) {
25 return false;
26 }
27 return isCurrWow64 ? true : false;
28 }
29
30
31 inline bool is_wow_64_by_pid(DWORD processID)
32 {
33 HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, processID);
34 if (!hProcess) {
35 hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processID);
36 if (!hProcess) return false;
37 }
38 return is_wow_64(hProcess);
39 }
40
41
42 inline bool get_process_path(DWORD processID, WCHAR* szProcessName, size_t processNameSize)
43 {
44 if (!szProcessName || !processNameSize) return false;
45
46 HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, processID);
47 if (!hProcess) {
48 hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processID);
49 if (!hProcess) return false;
50 }
51 DWORD exeNameSize = processNameSize;
52 BOOL isOK = QueryFullProcessImageNameW(hProcess, 0, szProcessName, &exeNameSize);
53 CloseHandle(hProcess);
54
55 if (!isOK || !exeNameSize) {
56 return false;
57 }
58 return true;
59 }
60
61 inline size_t suspend_suspicious(std::vector<DWORD>& suspicious_pids)
62 {
63 size_t done = 0;
64 std::vector<DWORD>::iterator itr;
65 for (itr = suspicious_pids.begin(); itr != suspicious_pids.end(); ++itr) {
66 DWORD pid = *itr;
67 if (!suspend_process(pid)) {
68 std::cerr << "Could not suspend the process. PID = " << pid << std::endl;
69 }
70 }
71 return done;
72 }
73
74 inline size_t kill_suspicious(std::vector<DWORD>& suspicious_pids)
75 {
76 size_t killed = 0;
77 std::vector<DWORD>::iterator itr;
78 for (itr = suspicious_pids.begin(); itr != suspicious_pids.end(); ++itr) {
79 DWORD pid = *itr;
80 HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
81 if (!hProcess) {
82 continue;
83 }
84 if (TerminateProcess(hProcess, 0)) {
85 killed++;
86 }
87 else {
88 std::cerr << "Could not terminate the process. PID = " << pid << std::endl;
89 }
90 CloseHandle(hProcess);
91 }
92 return killed;
93 }
94
95}; // namespace process_util
96
bool is_wow_64(HANDLE process)
bool get_process_path(DWORD processID, WCHAR *szProcessName, size_t processNameSize)
size_t suspend_suspicious(std::vector< DWORD > &suspicious_pids)
size_t kill_suspicious(std::vector< DWORD > &suspicious_pids)
bool is_wow_64_by_pid(DWORD processID)
bool suspend_process(DWORD processId)
Definition suspend.cpp:7