//scan_pattern
//.cpp
void* utils::scan_pattern(const char* szModule, const char* szPattern, int iOffset) {
const char* pattern = szPattern;
DWORD firstMatch = 0;
DWORD rangeStart = (DWORD)GetModuleHandleA(szModule);
MODULEINFO miModInfo; GetModuleInformation(GetCurrentProcess(), (HMODULE)rangeStart, &miModInfo, sizeof(MODULEINFO));
DWORD rangeEnd = rangeStart + miModInfo.SizeOfImage;
for (DWORD pCur = rangeStart; pCur < rangeEnd; pCur++)
{
if (!*pattern)
return (void*)(firstMatch + iOffset);
if (*(PBYTE)pattern == '\?' || *(BYTE*)pCur == getByte(pattern))
{
if (!firstMatch)
firstMatch = pCur;
if (!pattern[2])
return (void*)(firstMatch + iOffset);
if (*(PWORD)pattern == '\?\?' || *(PBYTE)pattern != '\?')
pattern += 3;
else
pattern += 2; //one ?
}
else
{
pattern = szPattern;
firstMatch = 0;
}
}
return nullptr;
}
//.h
namespace utils {
void* scan_pattern(const char* szModule, const char* szPattern, int iOffset = 0x0);
}