-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProcessManager.cpp
More file actions
92 lines (59 loc) · 1.41 KB
/
Copy pathProcessManager.cpp
File metadata and controls
92 lines (59 loc) · 1.41 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "pch.h"
#include "ProcessManager.h"
ProcessManager::ProcessManager(const wchar_t* processName , const wchar_t* moduleName)
{
this->processName = processName;
this->moduleName = processName;
}
DWORD ProcessManager::getProcId()
{
DWORD pId = 0;
BOOL hResult;
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (INVALID_HANDLE_VALUE == hSnapshot) return pId;
PROCESSENTRY32 pe;
pe.dwSize = sizeof(PROCESSENTRY32);
hResult = Process32First(hSnapshot, &pe);
while (hResult)
{
if (!wcscmp(this->processName, pe.szExeFile))
{
pId = pe.th32ProcessID;
break;
}
hResult = Process32Next(hSnapshot, &pe);
}
CloseHandle(hSnapshot);
return pId;
}
uintptr_t ProcessManager::getModuleBaseAddress()
{
if (baseAddress)
return baseAddress;
DWORD procID = getProcId();
BOOL res;
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, procID);
if (INVALID_HANDLE_VALUE == hSnapshot) return baseAddress;
MODULEENTRY32 me;
me.dwSize = sizeof(me);
res = Module32First(hSnapshot, &me);
while (res)
{
if (!wcscmp(me.szModule, moduleName))
{
baseAddress = (uintptr_t)me.modBaseAddr;
break;
}
res = Module32Next(hSnapshot, &me);
}
CloseHandle(hSnapshot);
return baseAddress;
}
const wchar_t* ProcessManager::getProcessName()
{
return processName;
}
const wchar_t* ProcessManager::getModuleName()
{
return moduleName;
}