-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatternScan.cpp
More file actions
25 lines (23 loc) · 865 Bytes
/
PatternScan.cpp
File metadata and controls
25 lines (23 loc) · 865 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
#include "PatternScan.h"
LPVOID FindPattern(const BYTE* lpPattern, LPCSTR szMask)
{
HMODULE hModule = GetModuleHandle(NULL);
DWORD image_base = (DWORD)hModule; // Default location
DWORD image_size = 0;
MODULEINFO moduleInfo;
if (GetModuleInformation(GetCurrentProcess(), hModule, &moduleInfo, sizeof(moduleInfo)))
{
image_size = moduleInfo.SizeOfImage;
}
DWORD dwLength = strlen(szMask);
DWORD dwImageEnd = image_base + image_size - dwLength; // End of location
DWORD_PTR i, j;
// Scan the whole image for the pattern
for (j = image_base; j < dwImageEnd; ++j)
{
// If the pattern is found, return the address at which it begins
for (i = 0; i < dwLength && (szMask[i] == '?' || *(BYTE*)(j + i) == lpPattern[i]); ++i);
if (i == dwLength) return (LPVOID)j;
}
return NULL;
}