-
Notifications
You must be signed in to change notification settings - Fork 3
/
Common.cpp
57 lines (48 loc) · 1.04 KB
/
Common.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
52
53
54
55
56
57
#include "pch.h"
#include "Common.h"
#include <tlhelp32.h>
#include <psapi.h>
ULONG_PTR GetModuleBaseByPid(DWORD Pid, PCHAR ModuleName)
{
HANDLE hModuleSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, Pid);
MODULEENTRY32 Module = { sizeof(MODULEENTRY32) };
if (!Module32First(hModuleSnap, &Module))
{
return 0;
}
do
{
if (_stricmp(ModuleName, Module.szModule) == 0)
{
return (ULONG_PTR)Module.modBaseAddr;
}
} while (Module32Next(hModuleSnap, &Module));
return 0;
}
BOOL ReadProcMemByOffset(HANDLE hProc, ULONG_PTR Offset[], DWORD OffsetCount, PVOID Result, DWORD Size)
{
BYTE Buffer[256] = { 0 };
ULONG_PTR Temp = 0;
for (UINT i = 0; i <= OffsetCount; ++i)
{
Temp = *(PULONG_PTR)Buffer;
Temp += Offset[i];
memset(Buffer, 0, 256);
if (i == OffsetCount)
{
if (!ReadProcessMemory(hProc, (PVOID)Temp, Buffer, Size, 0))
{
return FALSE;
}
}
else
{
if (!ReadProcessMemory(hProc, (PVOID)Temp, Buffer, sizeof(ULONG_PTR), 0))
{
return FALSE;
}
}
}
memcpy(Result, Buffer, Size);
return TRUE;
}