Краткий гайд
Далее к коду:
вам понадобится PatternScan и MinHook
минхук сами найдёте думаю и без меня
а паттернскан дам, просто подключите заголовок там где хукать собираетесь
Pattenscan.h
Код:
#include <Windows.h>
#include <vector>
uintptr_t PatternScan(uintptr_t moduleAdress, const char* signature)
{
static auto patternToByte = [](const char* pattern)
{
auto bytes = std::vector<int>{};
const auto start = const_cast<char*>(pattern);
const auto end = const_cast<char*>(pattern) + strlen(pattern);
for (auto current = start; current < end; ++current)
{
if (*current == '?')
{
++current;
bytes.push_back(-1);
}
else { bytes.push_back(strtoul(current, ¤t, 16)); }
}
return bytes;
};
const auto dosHeader = (PIMAGE_DOS_HEADER)moduleAdress;
const auto ntHeaders = (PIMAGE_NT_HEADERS)((std::uint8_t*)moduleAdress + dosHeader->e_lfanew);
const auto sizeOfImage = ntHeaders->OptionalHeader.SizeOfImage;
auto patternBytes = patternToByte(signature);
const auto scanBytes = reinterpret_cast<std::uint8_t*>(moduleAdress);
const auto s = patternBytes.size( );
const auto d = patternBytes.data( );
for (auto i = 0ul; i < sizeOfImage - s; ++i)
{
bool found = true;
for (auto j = 0ul; j < s; ++j)
{
if (scanBytes[i + j] != d[j] && d[j] != -1)
{
found = false;
break;
}
}
if (found) { return reinterpret_cast<uintptr_t>(&scanBytes[i]); }
}
return NULL;
}
код:
C++:
void(*OGetMessageBox) = nullptr;
void GetMessageBox()
{
while (true)
{
std::cout << "\n HOOKED";
}
}
Сам хук
Он должен вызываться в DllMain при DLL_PROCESS_ATTACH там же где обычно вызывается MainThread
если у вас будет поток то его только после хука
Код хука
C++:
uintptr_t GetMBox = PatternScan((uintptr_t)GetModuleHandleA(NULL), "FF 15 ? ? ? ? EB D6");
if (!GetMBox) return FALSE;
if (MH_Initialize() != MH_STATUS::MH_OK) return FALSE;
if (MH_CreateHook(reinterpret_cast<LPVOID>(GetMBox), GetMessageBox, reinterpret_cast<LPVOID*>(&OGetMessageBox)) != MH_STATUS::MH_OK) return FALSE;
if (MH_EnableHook(reinterpret_cast<LPVOID>(GetMBox)) != MH_STATUS::MH_OK) return FALSE;
Как то так ) Я мог бы сделать отдельный тред, но мне лень