-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
47 lines (36 loc) · 1000 Bytes
/
Copy pathutils.cpp
File metadata and controls
47 lines (36 loc) · 1000 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
40
41
42
43
44
45
46
47
#include "utils.h"
BOOL Utils::dataCompare(BYTE* data, BYTE* pattern, BYTE* mask)
{
for(; *mask; ++mask, ++data, ++pattern)
{
if(*mask == 'x' && *data != *pattern)
return FALSE;
}
return (*pattern == NULL);
}
DWORD Utils::findPattern(DWORD address, DWORD len, BYTE* pattern, BYTE *mask)
{
for(DWORD i = 0; i < len; i++)
{
if(Utils::dataCompare((BYTE*)(address + i), pattern, mask))
return (DWORD)(address + i);
}
return 0;
}
bool Utils::patchCode(LPVOID address, char* code, int length, char* oldCode)
{
DWORD oldProtect;
if(!VirtualProtect(address, length, PAGE_EXECUTE_READWRITE, &oldProtect))
return false;
if(oldCode && memcpy_s(oldCode, length, address, length))
return false;
if(memcpy_s(address, length, code, length))
return false;
if(!VirtualProtect(address, length, oldProtect, NULL))
return false;
return true;
}
VOID Utils::crash()
{
RaiseException(0xBAADC0DE, EXCEPTION_NONCONTINUABLE, 0, NULL);
}