-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmem.cpp
More file actions
74 lines (53 loc) · 1.54 KB
/
Copy pathmem.cpp
File metadata and controls
74 lines (53 loc) · 1.54 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <vector>
#include <Windows.h>
#include "pch.h"
#include <iostream>
#include <Psapi.h>
#include "proc.h"
namespace mem {//BYTE* BYTE*
void Patch(BYTE* dst, BYTE* src, unsigned int size)
{
DWORD oldprotect;
VirtualProtect( dst, size, PAGE_EXECUTE_READWRITE, &oldprotect);
memcpy( dst, src, size);
VirtualProtect( dst, size, oldprotect, &oldprotect);
}
void Nop(BYTE* dst, unsigned int size)
{
BYTE* nopArray = new BYTE[size];
memset(nopArray, 0x90, size);
Patch(dst, nopArray, size);
delete[] nopArray;
}
uintptr_t FindDMAaddy(uintptr_t ptr, std::vector<unsigned int>offsets) {
uintptr_t addr = ptr;
for (unsigned int i = 0; i < offsets.size(); ++i)
{
addr = *(uintptr_t*)addr;
addr += offsets[i];
}
return addr;
}
bool Hook(void* toHook, void* ourFunct, int len) {
if (len < 5) {
return false;
}
DWORD curProtection;
VirtualProtect(toHook, len, PAGE_EXECUTE_READWRITE, &curProtection);
memset(toHook, 0x90, len);
DWORD relativeAddress = ((DWORD)ourFunct - (DWORD)toHook) - 5;
*(BYTE*)toHook = 0xE9;
*(DWORD*)((DWORD)toHook + 1) = relativeAddress;
DWORD temp;
VirtualProtect(toHook, len, curProtection, &temp);
return true;
}
MODULEINFO GetModuleInfo(char* szModule)
{
MODULEINFO modinfo = { 0 };
HMODULE hModule = GetModuleHandle((LPCWSTR)szModule);
if (hModule == 0)
return modinfo;
GetModuleInformation(GetCurrentProcess(), hModule, &modinfo, sizeof(MODULEINFO));
return modinfo;
}