NorthstarLauncher/NorthstarDLL/hookutils.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

44 lines
1.1 KiB
C++
Raw Normal View History

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)
{
// 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
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
spdlog::error("MH_EnableHook failed for unknown function");
2021-07-08 16:33:31 +02:00
}
else
spdlog::info("Enabling hook {}", hook->targetName);
2021-07-08 16:33:31 +02:00
}
}