-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathGameSearch.h
94 lines (89 loc) · 2.47 KB
/
GameSearch.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#pragma once
#include <Psapi.h>
#define INRANGE(x,a,b) (x >= a && x <= b)
#define getBits( x ) (INRANGE((x&(~0x20)),'A','F') ? ((x&(~0x20)) - 'A' + 0xa) : (INRANGE(x,'0','9') ? x - '0' : 0))
#define getByte( x ) (getBits(x[0]) << 4 | getBits(x[1]))
class CGameSearch
{
public:
DWORD signature(const char* szModule, const char* szSignature)
{
MODULEINFO modInfo;
GetModuleInformation(GetCurrentProcess(), GetModuleHandleA(szModule), &modInfo, sizeof(MODULEINFO));
DWORD startAddress = (DWORD)modInfo.lpBaseOfDll;
DWORD endAddress = startAddress + modInfo.SizeOfImage;
const char* pat = szSignature;
DWORD firstMatch = 0;
for (DWORD pCur = startAddress; pCur < endAddress; pCur++) {
if (!*pat) return firstMatch;
if (*(PBYTE)pat == '\?' || *(BYTE*)pCur == getByte(pat)) {
if (!firstMatch) firstMatch = pCur;
if (!pat[2]) return firstMatch;
if (*(PWORD)pat == '\?\?' || *(PBYTE)pat != '\?') pat += 3;
else pat += 2;
}
else {
pat = szSignature;
firstMatch = 0;
}
}
return NULL;
}
DWORD wait_on_mod_handle(std::string moduleName)
{
DWORD ModuleHandle = NULL;
while (!ModuleHandle)
{
ModuleHandle = (DWORD)GetModuleHandle(moduleName.c_str());
if (!ModuleHandle)
Sleep(50);
}
return ModuleHandle;
}
bool bCompare(const BYTE* Data, const BYTE* Mask, const char* szMask)
{
for (; *szMask; ++szMask, ++Mask, ++Data)
{
if (*szMask == 'x' && *Mask != *Data)
{
return false;
}
}
return (*szMask) == 0;
}
DWORD pattern(std::string moduleName, BYTE* Mask, char* szMask)
{
DWORD Address = wait_on_mod_handle(moduleName.c_str());
MODULEINFO ModInfo; GetModuleInformation(GetCurrentProcess(), (HMODULE)Address, &ModInfo, sizeof(MODULEINFO));
DWORD Length = ModInfo.SizeOfImage;
for (DWORD c = 0; c < Length; c += 1)
{
if (bCompare((BYTE*)(Address + c), Mask, szMask))
{
return (DWORD)(Address + c);
}
}
return 0;
}
DWORD text_pattern(std::string moduleName, char* string)
{
DWORD Address = wait_on_mod_handle(moduleName.c_str());
MODULEINFO ModInfo; GetModuleInformation(GetCurrentProcess(), (HMODULE)Address, &ModInfo, sizeof(MODULEINFO));
DWORD Length = ModInfo.SizeOfImage;
int len = strlen(string);
char* szMask = new char[len + 1];
for (int i = 0; i < len; i++)
{
szMask[i] = 'x';
}
szMask[len] = '\0';
for (DWORD c = 0; c < Length; c += 1)
{
if (bCompare((BYTE*)(Address + c), (BYTE*)string, szMask))
{
return (DWORD)(Address + c);
}
}
return 0;
}
};