forked from TheIndra55/TRLAU-menu-hook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.cpp
36 lines (30 loc) · 1.09 KB
/
util.cpp
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
#include <Windows.h>
#include <psapi.h>
#include "Hooking.hpp"
// taken from sunbeam906
uint8_t __declspec(noinline)* GetAddress(uint8_t* ptr, uint8_t offset, uint8_t instr_size)
{
return (ptr + *(int32_t*)(ptr + offset) + instr_size);
}
bool __declspec(noinline) bDataCompare(const BYTE* pData, const BYTE* bMask, const char* szMask)
{
for (; *szMask; ++szMask, ++pData, ++bMask)
{
if (*szMask == 'x' && *pData != *bMask)
return FALSE;
}
return (*szMask) == NULL;
}
uint8_t __declspec(noinline)* FindPattern(BYTE* bMask, char* szMask)
{
MODULEINFO moduleInfo = { 0 };
GetModuleInformation(GetCurrentProcess(), GetModuleHandle(NULL), &moduleInfo, sizeof(MODULEINFO));
uint8_t* dwBaseAddress = (uint8_t*)moduleInfo.lpBaseOfDll + 0x1000; // start from first section
int dwModuleSize = (int)moduleInfo.SizeOfImage - 0x1000; // scan size - 0x1000, due to the above
for (int i = 0; i < dwModuleSize; i++)
{
if (bDataCompare((BYTE*)(dwBaseAddress + i), bMask, szMask))
return (uint8_t*)(dwBaseAddress + i);
}
return 0;
}