aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/plugins/HookSystem.hpp
diff options
context:
space:
mode:
authorVaxry <[email protected]>2023-02-27 12:32:38 +0000
committerGitHub <[email protected]>2023-02-27 12:32:38 +0000
commit8b81f41e52b55835aaaa7e4962af23a00188cbdc (patch)
treebca65923843ea931c0e0222f29d4e2901cfa8637 /src/plugins/HookSystem.hpp
parent74a10f26a469de54968e584525f6507928f615f0 (diff)
downloadHyprland-8b81f41e52b55835aaaa7e4962af23a00188cbdc.tar.gz
Hyprland-8b81f41e52b55835aaaa7e4962af23a00188cbdc.zip
Plugin System (#1590)
--------- Co-authored-by: Mihai Fufezan <[email protected]>
Diffstat (limited to 'src/plugins/HookSystem.hpp')
-rw-r--r--src/plugins/HookSystem.hpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/plugins/HookSystem.hpp b/src/plugins/HookSystem.hpp
new file mode 100644
index 00000000..56227449
--- /dev/null
+++ b/src/plugins/HookSystem.hpp
@@ -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; \ No newline at end of file