-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemMan.cpp
More file actions
50 lines (50 loc) · 1.24 KB
/
MemMan.cpp
File metadata and controls
50 lines (50 loc) · 1.24 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
#include "MemMan.h"
#include <TlHelp32.h>
#include <iostream>
#include <iomanip>
MemMan::MemMan(){handle = NULL;}
MemMan::~MemMan()
{
CloseHandle(handle);
}
uintptr_t MemMan::getProcess(const wchar_t* proc)
{
HANDLE hProcessId = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
uintptr_t process;
PROCESSENTRY32 pEntry;
pEntry.dwSize = sizeof(pEntry);
do
{
if (!_wcsicmp(pEntry.szExeFile, proc))
{
process = pEntry.th32ProcessID;
CloseHandle(hProcessId);
handle = OpenProcess(PROCESS_ALL_ACCESS, false, process);
}
} while (Process32Next(hProcessId, &pEntry));
return process;
}
uintptr_t MemMan::getModule(uintptr_t procId, const wchar_t* modName)
{
HANDLE hModule = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, procId);
MODULEENTRY32 mEntry;
mEntry.dwSize = sizeof(mEntry);
do
{
if (!_wcsicmp(mEntry.szModule, modName))
{
CloseHandle(hModule);
return (uintptr_t)mEntry.hModule;
}
} while (Module32Next(hModule, &mEntry));
return 0;
}
uintptr_t MemMan::getAddress(uintptr_t addr, std::vector<uintptr_t> vect)
{
for (int i = 0; i < vect.size(); i++)
{
ReadProcessMemory(handle, (BYTE*)addr, &addr, sizeof(addr), 0);
addr += vect[i];
}
return addr;
}