-
Notifications
You must be signed in to change notification settings - Fork 8
/
VMT.h
50 lines (38 loc) · 1.1 KB
/
VMT.h
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
class VMT
{
private:
uintptr_t* vmt;
public:
// New virtual method table
uintptr_t** interface = nullptr;
uintptr_t* original_vmt = nullptr;
unsigned int methodCount = 0;
VMT(void* interface)
{
this->interface = reinterpret_cast<uintptr_t**>(interface);
size_t method_count = 0;
while (reinterpret_cast<uintptr_t*>(*this->interface)[method_count])
method_count++;
original_vmt = *this->interface;
vmt = new uintptr_t[sizeof(uintptr_t) * method_count];
memcpy(vmt, original_vmt, sizeof(uintptr_t) * method_count);
}
// Hook virtual method
void HookVM(void* method, size_t methodIndex)
{
vmt[methodIndex] = reinterpret_cast<uintptr_t>(method);
}
template<typename Fn>
Fn GetOriginalMethod(size_t methodIndex)
{
return reinterpret_cast<Fn>(original_vmt[methodIndex]);
}
void ApplyVMT()
{
*this->interface = vmt;
}
void ReleaseVMT()
{
*this->interface = original_vmt;
}
};