mirror of
https://gitlab.com/Mr_Goldberg/goldberg_emulator.git
synced 2025-12-06 12:14:54 +01:00
Linux hooks
This commit is contained in:
parent
8a6db1c401
commit
86f94bc337
5 changed files with 514 additions and 18 deletions
|
|
@ -1,20 +1,13 @@
|
|||
#include "Base_Hook.h"
|
||||
#include "Hook_Manager.h"
|
||||
|
||||
#ifndef NO_OVERLAY
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#ifndef NO_OVERLAY
|
||||
#ifdef STEAM_WIN32
|
||||
|
||||
#include "../detours/detours.h"
|
||||
|
||||
Base_Hook::Base_Hook():
|
||||
_library(nullptr)
|
||||
{}
|
||||
|
||||
Base_Hook::~Base_Hook()
|
||||
{
|
||||
UnhookAll();
|
||||
}
|
||||
|
||||
void Base_Hook::BeginHook()
|
||||
{
|
||||
DetourTransactionBegin();
|
||||
|
|
@ -26,6 +19,12 @@ void Base_Hook::EndHook()
|
|||
DetourTransactionCommit();
|
||||
}
|
||||
|
||||
void Base_Hook::HookFunc(std::pair<void**, void*> hook)
|
||||
{
|
||||
if( DetourAttach(hook.first, hook.second) == 0 )
|
||||
_hooked_funcs.emplace_back(hook);
|
||||
}
|
||||
|
||||
void Base_Hook::UnhookAll()
|
||||
{
|
||||
if (_hooked_funcs.size())
|
||||
|
|
@ -39,15 +38,53 @@ void Base_Hook::UnhookAll()
|
|||
}
|
||||
}
|
||||
|
||||
#else
|
||||
#include "Linux_Detour.h"
|
||||
|
||||
void Base_Hook::BeginHook()
|
||||
{
|
||||
Linux_Detour::transaction_begin();
|
||||
Linux_Detour::update_thread(pthread_self());
|
||||
}
|
||||
|
||||
void Base_Hook::EndHook()
|
||||
{
|
||||
Linux_Detour::transaction_commit();
|
||||
}
|
||||
|
||||
void Base_Hook::HookFunc(std::pair<void**, void*> hook)
|
||||
{
|
||||
if( Linux_Detour::hook_func(hook.first, hook.second) == 0 )
|
||||
_hooked_funcs.emplace_back(hook);
|
||||
}
|
||||
|
||||
void Base_Hook::UnhookAll()
|
||||
{
|
||||
if (_hooked_funcs.size())
|
||||
{
|
||||
BeginHook();
|
||||
std::for_each(_hooked_funcs.begin(), _hooked_funcs.end(), [](std::pair<void**, void*>& hook) {
|
||||
Linux_Detour::unhook_func(hook.first, hook.second);
|
||||
});
|
||||
EndHook();
|
||||
_hooked_funcs.clear();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Base_Hook::Base_Hook():
|
||||
_library(nullptr)
|
||||
{}
|
||||
|
||||
Base_Hook::~Base_Hook()
|
||||
{
|
||||
UnhookAll();
|
||||
}
|
||||
|
||||
const char* Base_Hook::get_lib_name() const
|
||||
{
|
||||
return "<no_name>";
|
||||
}
|
||||
|
||||
void Base_Hook::HookFunc(std::pair<void**, void*> hook)
|
||||
{
|
||||
if( DetourAttach(hook.first, hook.second) == 0 )
|
||||
_hooked_funcs.emplace_back(hook);
|
||||
}
|
||||
|
||||
#endif//NO_OVERLAY
|
||||
#endif//NO_OVERLAY
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue