-
Notifications
You must be signed in to change notification settings - Fork 16
/
memory.cpp
51 lines (42 loc) · 1.4 KB
/
memory.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
46
47
48
49
50
51
#include "stdafx.hpp"
namespace memory
{
std::uintptr_t get_module_base(std::uint32_t process_id)
{
MODULEENTRY32 module_entry;
module_entry.dwSize = sizeof(module_entry);
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, process_id);
if (snapshot == INVALID_HANDLE_VALUE)
{
return 0;
}
Module32First(snapshot, &module_entry);
return reinterpret_cast<std::uintptr_t>(module_entry.modBaseAddr);
}
std::uint32_t find_process_by_id(const std::string& process_name)
{
PROCESSENTRY32 process_info;
process_info.dwSize = sizeof(process_info);
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (snapshot == INVALID_HANDLE_VALUE)
{
return 0;
}
Process32First(snapshot, &process_info);
if (!process_name.compare(process_info.szExeFile))
{
CloseHandle(snapshot);
return process_info.th32ProcessID;
}
while (Process32Next(snapshot, &process_info))
{
if (!process_name.compare(process_info.szExeFile))
{
CloseHandle(snapshot);
return process_info.th32ProcessID;
}
}
CloseHandle(snapshot);
return 0;
}
}