2021-07-08 16:33:31 +02:00
|
|
|
#include "pch.h"
|
|
|
|
#include "hookutils.h"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
void HookEnabler::CreateHook(LPVOID ppTarget, LPVOID ppDetour, LPVOID* ppOriginal, const char* targetName)
|
|
|
|
{
|
2021-07-17 23:33:00 +02:00
|
|
|
// the macro for this uses ppTarget's name as targetName, and this typically starts with &
|
|
|
|
// targetname is used for debug stuff and debug output is nicer if we don't have this
|
|
|
|
if (*targetName == '&')
|
|
|
|
targetName++;
|
2022-02-04 02:09:08 +01:00
|
|
|
|
2021-07-08 16:33:31 +02:00
|
|
|
if (MH_CreateHook(ppTarget, ppDetour, ppOriginal) == MH_OK)
|
|
|
|
{
|
|
|
|
HookTarget* target = new HookTarget;
|
|
|
|
target->targetAddress = ppTarget;
|
|
|
|
target->targetName = (char*)targetName;
|
2022-02-04 02:09:08 +01:00
|
|
|
|
2021-07-08 16:33:31 +02:00
|
|
|
m_hookTargets.push_back(target);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (targetName != nullptr)
|
2021-12-31 13:41:53 +01:00
|
|
|
spdlog::error("MH_CreateHook failed for function {}", targetName);
|
2021-07-08 16:33:31 +02:00
|
|
|
else
|
2021-12-02 01:29:12 +01:00
|
|
|
spdlog::error("MH_CreateHook failed for unknown function");
|
2021-07-08 16:33:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HookEnabler::~HookEnabler()
|
|
|
|
{
|
|
|
|
for (auto& hook : m_hookTargets)
|
|
|
|
{
|
|
|
|
if (MH_EnableHook(hook->targetAddress) != MH_OK)
|
|
|
|
{
|
|
|
|
if (hook->targetName != nullptr)
|
2021-12-31 13:41:53 +01:00
|
|
|
spdlog::error("MH_EnableHook failed for function {}", hook->targetName);
|
2021-07-08 16:33:31 +02:00
|
|
|
else
|
2021-12-02 01:29:12 +01:00
|
|
|
spdlog::error("MH_EnableHook failed for unknown function");
|
2021-07-08 16:33:31 +02:00
|
|
|
}
|
|
|
|
else
|
2021-07-18 18:02:39 +02:00
|
|
|
spdlog::info("Enabling hook {}", hook->targetName);
|
2021-07-08 16:33:31 +02:00
|
|
|
}
|
|
|
|
}
|