-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathMemory.h
67 lines (59 loc) · 1.99 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#pragma once
#include <assert.h>
#include <mhyprotrose.h>
namespace Memory
{
template <typename Type, typename Base, typename Offset>
static inline Type Ptr(Base pBase, Offset pOffset)
{
static_assert(std::is_pointer<Type>::value || std::is_integral<Type>::value, "[MEMASSERT] Type must be a pointer or address");
static_assert(std::is_pointer<Base>::value || std::is_integral<Base>::value, "[MEMASSERT] Base must be a pointer or address");
static_assert(std::is_pointer<Offset>::value || std::is_integral<Offset>::value, "[MEMASSERT] Offset must be a pointer or address");
return pBase ? reinterpret_cast<Type>((reinterpret_cast<uint64_t>(pBase) + static_cast<uint64_t>(pOffset))) : nullptr;
}
template <typename Type>
static bool IsValidPtr(Type* ptr)
{
return (ptr && sizeof(ptr)) ? true : false;
}
static bool IsValidPtr(void* ptr)
{
return (ptr && sizeof(ptr)) ? true : false;
}
static bool ReadProcessMemory(DWORD dwProcessId, uint64_t pAddress, void* pBuffer, size_t szBufferSize)
{
if (IsValidPtr((void*)pAddress) && pAddress != 0)
{
return mhyprotrose::MhyReadProcessMemory(dwProcessId, pAddress, pBuffer, szBufferSize);
}
return false;
}
template <typename Type>
static Type ReadProcessMemory(DWORD dwProcessId, uint64_t pAddress)
{
Type tBuffer{};
if (IsValidPtr((void*)pAddress) && pAddress != 0)
{
tBuffer = mhyprotrose::MhyReadProcessMemory<Type>(dwProcessId, pAddress);
}
return tBuffer;
}
static bool ReadVirtualMemory(uint64_t pAddress, uint8_t* pBuffer, size_t szSize)
{
return mhyprotrose::MhyReadKernelMemory(pAddress, pBuffer, szSize);
}
template <typename Type>
Type ReadVirtualMemory(uint64_t pAddress)
{
Type tBuffer;
ReadVirtualMemory(pAddress, (uint8_t*)&tBuffer, sizeof(Type));
return tBuffer;
}
template <typename Type>
static bool WriteProcessMemory(DWORD dwProcessId, uintptr_t pAddress, Type tBuffer)
{
if (pAddress != 0)
return mhyprotrose::MhyWriteProcessMemory(dwProcessId, pAddress, tBuffer);
else return false;
}
}