w
w
This commit is contained in:
commit
7bd33ca73b
98 files changed
+56670
No files matched your search
@@ -0,0 +1,47 @@
|
||||
#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_;
|
||||
};
|
||||
Reference in new issue
Block a user