48 lines
1.0 KiB
C++
48 lines
1.0 KiB
C++
#pragma once
|
|
|
|
#include "Common.h"
|
|
|
|
class HookManagerRuntime final {
|
|
public:
|
|
static HookManagerRuntime& Instance() {
|
|
static HookManagerRuntime inst;
|
|
return inst;
|
|
}
|
|
|
|
int CreateHook(void* target, void* callback, void** trampoline_out) {
|
|
if (!target || !callback || !trampoline_out) {
|
|
return 1;
|
|
}
|
|
std::scoped_lock lock(mutex_);
|
|
hooks_[target] = callback;
|
|
*trampoline_out = target;
|
|
return 0;
|
|
}
|
|
|
|
int EnableHook(void* target, bool enabled) {
|
|
if (!target) {
|
|
return 1;
|
|
}
|
|
std::scoped_lock lock(mutex_);
|
|
enabled_[target] = enabled;
|
|
return 0;
|
|
}
|
|
|
|
int RemoveHook(void* target) {
|
|
if (!target) {
|
|
return 1;
|
|
}
|
|
std::scoped_lock lock(mutex_);
|
|
hooks_.erase(target);
|
|
enabled_.erase(target);
|
|
return 0;
|
|
}
|
|
|
|
private:
|
|
HookManagerRuntime() = default;
|
|
|
|
std::mutex mutex_;
|
|
std::unordered_map<void*, void*> hooks_;
|
|
std::unordered_map<void*, bool> enabled_;
|
|
};
|