-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathHookObject.h
More file actions
134 lines (118 loc) · 3.34 KB
/
HookObject.h
File metadata and controls
134 lines (118 loc) · 3.34 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#pragma once
#include "REX/BASE.h"
namespace REL
{
using HOOK_HANDLE = std::uint32_t;
enum class HOOK_TYPE : std::uint32_t
{
NONE = 0,
CALL5 = 2,
CALL6 = 3,
JMP5 = 4,
JMP6 = 5,
VFT = 6,
};
enum class HOOK_STEP : std::uint32_t
{
NONE = 0,
PRELOAD = 1,
LOAD = 2,
};
class HookObject
{
public:
HookObject(const std::uintptr_t a_address);
HookObject(const std::uintptr_t a_address, const char* a_name);
HookObject(const std::uintptr_t a_address, const HOOK_TYPE a_type);
HookObject(const std::uintptr_t a_address, const HOOK_TYPE a_type, const HOOK_STEP a_step);
HookObject(const std::uintptr_t a_address, const HOOK_STEP a_step);
HookObject(const std::uintptr_t a_address, const char* a_name, const HOOK_STEP a_step);
HookObject(const std::uintptr_t a_address, const char* a_name, const HOOK_TYPE a_type);
HookObject(const std::uintptr_t a_address, const char* a_name, const HOOK_TYPE a_type, const HOOK_STEP a_step);
virtual ~HookObject();
virtual bool Init();
virtual HOOK_HANDLE GetHandle() const;
virtual const char* GetName() const;
virtual HOOK_TYPE GetType() const;
virtual HOOK_STEP GetStep() const;
virtual std::size_t GetSize() const;
virtual std::size_t GetSizeTrampoline() const;
virtual bool GetEnabled() const;
virtual bool Enable() = 0;
virtual bool Disable() = 0;
protected:
std::uintptr_t m_address{ 0 };
std::string m_name;
HOOK_HANDLE m_handle;
HOOK_TYPE m_type{ HOOK_TYPE::NONE };
HOOK_STEP m_step{ HOOK_STEP::LOAD };
std::size_t m_size{ 8 };
std::size_t m_sizeTrampoline{ 0 };
bool m_enabled{ false };
};
}
template <class T>
requires(std::is_base_of_v<REL::HookObject, T>)
struct std::formatter<T>
{
template <class ParseContext>
constexpr auto parse(ParseContext& a_ctx)
{
return a_ctx.begin();
}
template <class FormatContext>
constexpr auto format(const T& a_hook, FormatContext& a_ctx) const
{
return format_to(a_ctx.out(), "Hook [{}]", a_hook.GetName());
}
};
template <>
struct std::formatter<REL::HOOK_TYPE>
{
template <class ParseContext>
constexpr auto parse(ParseContext& a_ctx)
{
return a_ctx.begin();
}
template <class FormatContext>
constexpr auto format(const REL::HOOK_TYPE& a_type, FormatContext& a_ctx) const
{
switch (a_type) {
case REL::HOOK_TYPE::NONE:
return format_to(a_ctx.out(), "NONE");
case REL::HOOK_TYPE::CALL5:
return format_to(a_ctx.out(), "CALL5");
case REL::HOOK_TYPE::CALL6:
return format_to(a_ctx.out(), "CALL6");
case REL::HOOK_TYPE::JMP5:
return format_to(a_ctx.out(), "JMP5");
case REL::HOOK_TYPE::JMP6:
return format_to(a_ctx.out(), "JMP6");
case REL::HOOK_TYPE::VFT:
return format_to(a_ctx.out(), "VFT");
}
return format_to(a_ctx.out(), "UNKNOWN");
}
};
template <>
struct std::formatter<REL::HOOK_STEP>
{
template <class ParseContext>
constexpr auto parse(ParseContext& a_ctx)
{
return a_ctx.begin();
}
template <class FormatContext>
constexpr auto format(const REL::HOOK_STEP& a_step, FormatContext& a_ctx) const
{
switch (a_step) {
case REL::HOOK_STEP::NONE:
return format_to(a_ctx.out(), "NONE");
case REL::HOOK_STEP::PRELOAD:
return format_to(a_ctx.out(), "PRELOAD");
case REL::HOOK_STEP::LOAD:
return format_to(a_ctx.out(), "LOAD");
}
return format_to(a_ctx.out(), "UNKNOWN");
}
};