r5sdk/r5dev/sigscan.h
Amos 348cfee29c Implements hexdump utility and light code improvements
New hexdump utility,
New simple Origin hooks
Default back to hardcoded offsets for faster launch times
2021-05-17 07:54:13 -07:00

43 lines
1017 B
C++

#pragma once
#include <Psapi.h>
class CSigScan
{
public:
// For getting information about the executing module
MODULEINFO GetModuleInfo(const char *szModule)
{
MODULEINFO modinfo = { 0 };
HMODULE hModule = GetModuleHandle(szModule);
if (hModule == 0)
{
return modinfo;
}
GetModuleInformation(GetCurrentProcess(), hModule, &modinfo, sizeof(MODULEINFO));
return modinfo;
}
// For finding a signature/pattern in memory of the game process
LONGLONG FindPattern(const char *module, const char *pattern, const char *mask)
{
MODULEINFO mInfo = GetModuleInfo(module);
LONGLONG base = (LONGLONG)mInfo.lpBaseOfDll;
LONGLONG size = (LONGLONG)mInfo.SizeOfImage;
LONGLONG patternLength = (LONGLONG)strlen(mask);
for (LONGLONG i = 0; i < size - patternLength; i++)
{
bool found = true;
for (LONGLONG j = 0; j < patternLength; j++)
{
found &= mask[j] == '?' || pattern[j] == *(const char*)(base + i + j);
}
if (found)
{
return base + i;
}
}
return NULL;
}
};