From 8b81f41e52b55835aaaa7e4962af23a00188cbdc Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Mon, 27 Feb 2023 12:32:38 +0000 Subject: Plugin System (#1590) --------- Co-authored-by: Mihai Fufezan --- src/plugins/HookSystem.hpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/plugins/HookSystem.hpp (limited to 'src/plugins/HookSystem.hpp') 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 +#include +#include + +#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> m_vHooks; +}; + +inline std::unique_ptr g_pFunctionHookSystem; \ No newline at end of file -- cgit v1.2.3