-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindPatternFunctions.h
More file actions
39 lines (30 loc) · 1010 Bytes
/
FindPatternFunctions.h
File metadata and controls
39 lines (30 loc) · 1010 Bytes
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
typedef PIMAGE_NT_HEADERS(WINAPI* _RtlImageNtHeader)(PVOID ModuleAddress);
_RtlImageNtHeader oRtlImageNtHeader = nullptr;
bool Compare(const BYTE* pData, const BYTE* bMask, const char* szMask)
{
for (; *szMask; ++szMask, ++pData, ++bMask)
if (*szMask == 'x' && *pData != *bMask)
return false;
return *szMask == NULL;
}
DWORD FindPattern(DWORD ImageBase, DWORD SizeOfImage, const BYTE* Pattern, const char* szMask)
{
for (DWORD i = 0; i < SizeOfImage; i++)
if (Compare((BYTE*)(ImageBase + i), Pattern, szMask))
return ImageBase + i;
return 0;
}
BOOL WriteToMemory(DWORD MemoryAddress, const void* PatchBytes, int byteNum)
{
if (MemoryAddress == 0 || byteNum == 0)
return FALSE;
DWORD dwProtect = 0;
BOOL VP = VirtualProtect((LPVOID)(MemoryAddress), byteNum, PAGE_READWRITE, &dwProtect);
if (VP == TRUE)
{
memcpy((LPVOID)MemoryAddress, (const void*)PatchBytes, byteNum);
VirtualProtect((LPVOID)(MemoryAddress), byteNum, dwProtect, &dwProtect);
return TRUE;
}
return FALSE;
}