-
Notifications
You must be signed in to change notification settings - Fork 11
/
helpers.cpp
45 lines (39 loc) · 1.04 KB
/
helpers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "stdafx.h"
const char* ProtectionString(DWORD Protection) {
switch (Protection) {
case PAGE_NOACCESS:
return "---";
case PAGE_READONLY:
return "R--";
case PAGE_READWRITE:
return "RW-";
case PAGE_WRITECOPY:
return "RC-";
case PAGE_EXECUTE:
return "--X";
case PAGE_EXECUTE_READ:
return "R-X";
case PAGE_EXECUTE_READWRITE:
return "RWX";
case PAGE_EXECUTE_WRITECOPY:
return "RCX";
}
return "???";
}
std::wstring ProcessName(DWORD processId) {
std::wstring buffer;
buffer.resize(32768);
HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processId);
if (hProcess) {
DWORD dwSize = (DWORD)buffer.size();
if (QueryFullProcessImageNameW(hProcess, 0, &buffer[0], &dwSize))
{
buffer = std::filesystem::path(buffer).filename();
}
CloseHandle(hProcess);
}
if (buffer.empty()) {
wsprintf(&buffer[0], L"pid:%d", processId);
}
return buffer;
}