-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmemory.h
43 lines (41 loc) · 1.34 KB
/
memory.h
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
#pragma once
#include "includes.h"
#include "globals.h"
namespace memory
{
template <class t>
bool write( uintptr_t address, t value )
{
return LI_FN(WriteProcessMemory).cached()( globals::_handle, ( PVOID ) address, &value, sizeof( t ), NULL );
}
template <class t>
t read( uintptr_t address )
{
t data{};
LI_FN(ReadProcessMemory).cached()( globals::_handle, ( PVOID ) address, &data, sizeof( t ), NULL );
return data;
}
uintptr_t get_module( const wchar_t* modName )
{
uintptr_t modBaseAddr = 0;
HANDLE hSnap = LI_FN(CreateToolhelp32Snapshot).cached()( TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, globals::process_id );
if( hSnap != INVALID_HANDLE_VALUE )
{
MODULEENTRY32 modEntry;
modEntry.dwSize = sizeof( modEntry );
if( Module32First( hSnap, &modEntry ) )
{
do
{
if( !_wcsicmp( modEntry.szModule, modName ) )
{
modBaseAddr = ( uintptr_t ) modEntry.modBaseAddr;
break;
}
} while( Module32Next( hSnap, &modEntry ) );
}
}
LI_FN(CloseHandle).cached()( hSnap );
return modBaseAddr;
}
}