mirror of
https://github.com/hyprwm/Hyprland.git
synced 2025-08-16 04:23:49 -07:00
Plugin System (#1590)
--------- Co-authored-by: Mihai Fufezan <fufexan@protonmail.com>
This commit is contained in:
48
src/plugins/HookSystem.hpp
Normal file
48
src/plugins/HookSystem.hpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#define HANDLE void*
|
||||
|
||||
class CFunctionHook {
|
||||
public:
|
||||
CFunctionHook(HANDLE owner, void* source, void* destination);
|
||||
~CFunctionHook();
|
||||
|
||||
bool hook();
|
||||
bool unhook();
|
||||
|
||||
CFunctionHook(const CFunctionHook&) = delete;
|
||||
CFunctionHook(CFunctionHook&&) = delete;
|
||||
CFunctionHook& operator=(const CFunctionHook&) = delete;
|
||||
CFunctionHook& operator=(CFunctionHook&&) = delete;
|
||||
|
||||
void* m_pOriginal = nullptr;
|
||||
|
||||
private:
|
||||
void* m_pSource = nullptr;
|
||||
void* m_pFunctionAddr = nullptr;
|
||||
void* m_pTrampolineAddr = nullptr;
|
||||
void* m_pDestination = nullptr;
|
||||
size_t m_iHookLen = 0;
|
||||
size_t m_iTrampoLen = 0;
|
||||
HANDLE m_pOwner = nullptr;
|
||||
bool m_bActive = false;
|
||||
|
||||
friend class CHookSystem;
|
||||
};
|
||||
|
||||
class CHookSystem {
|
||||
public:
|
||||
CFunctionHook* initHook(HANDLE handle, void* source, void* destination);
|
||||
bool removeHook(CFunctionHook* hook);
|
||||
|
||||
void removeAllHooksFrom(HANDLE handle);
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<CFunctionHook>> m_vHooks;
|
||||
};
|
||||
|
||||
inline std::unique_ptr<CHookSystem> g_pFunctionHookSystem;
|
Reference in New Issue
Block a user