-
Notifications
You must be signed in to change notification settings - Fork 49
/
MidHook.hpp
46 lines (35 loc) · 1006 Bytes
/
MidHook.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#pragma once
#include <memory>
namespace safetyhook {
class Factory;
class InlineHook;
struct Context64 {
uintptr_t rflags, r15, r14, r13, r12, r11, r10, r9, r8, rdi, rsi, rdx, rcx, rbx, rax, rbp, rsp;
};
struct Context32 {
uintptr_t eflags, edi, esi, edx, ecx, ebx, eax, ebp, esp;
};
#ifdef _M_X64
using Context = Context64;
#else
using Context = Context32;
#endif
using MidHookFn = void (*)(Context& ctx);
class MidHook final {
public:
MidHook() = delete;
MidHook(const MidHook&) = delete;
MidHook(MidHook&&) = delete;
~MidHook();
[[nodiscard]] auto target() const { return m_target; }
[[nodiscard]] auto destination() const { return m_destination; }
private:
friend Factory;
std::shared_ptr<Factory> m_factory{};
std::unique_ptr<InlineHook> m_hook{};
uintptr_t m_target{};
uintptr_t m_stub{};
MidHookFn m_destination{};
MidHook(std::shared_ptr<Factory> factory, uintptr_t target, MidHookFn destination);
};
} // namespace safetyhook