-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmemhack.cpp
42 lines (36 loc) · 1.14 KB
/
memhack.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
#include "memhack.h"
//internal patch
void Patch(char* dst, char* src, unsigned int size)
{
DWORD oldprotect;
VirtualProtect(dst, size, PAGE_READWRITE, &oldprotect);
memcpy(dst, src, size);
VirtualProtect(dst, size, oldprotect, &oldprotect);
}
//external
void PatchEx(char* dst, char* src, unsigned int size, HANDLE hProcess)
{
DWORD oldprotect;
VirtualProtectEx(hProcess, dst, size, PAGE_READWRITE, &oldprotect);
WriteProcessMemory(hProcess, dst, src, size, NULL);
VirtualProtectEx(hProcess, dst, size, oldprotect, &oldprotect);
}
//Internal Nop
void Nop(char* dst, unsigned int size)
{
DWORD oldprotect;
VirtualProtect(dst, size, PAGE_READWRITE, &oldprotect);
memset(dst, 0x90, size);
VirtualProtect(dst, size, oldprotect, &oldprotect);
}
//External
void NopEx(char* dst, unsigned int size, HANDLE hProcess)
{
byte* nopArray = new byte[size];
memset(nopArray, 0x90, size);
DWORD oldprotect;
VirtualProtectEx(hProcess, dst, size, PAGE_READWRITE, &oldprotect);
WriteProcessMemory(hProcess, dst, nopArray, size, NULL);
VirtualProtectEx(hProcess, dst, size, oldprotect, &oldprotect);
delete[] nopArray;
}