forked from danielkrupinski/Osiris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VmtSwap.h
32 lines (26 loc) · 770 Bytes
/
VmtSwap.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
#pragma once
#include <cstddef>
#include <cstdint>
#include <memory>
#include <Platform/Macros/CallingConventions.h>
#include <Platform/Macros/PlatformSpecific.h>
class VmtSwap {
public:
void init(void* base) noexcept;
void restore() noexcept
{
*reinterpret_cast<std::uintptr_t**>(base) = oldVmt;
}
template <typename T>
std::uintptr_t hookAt(std::size_t index, T fun) const noexcept
{
newVmt[index + dynamicCastInfoLength] = reinterpret_cast<std::uintptr_t>(fun);
return oldVmt[index];
}
private:
static constexpr auto dynamicCastInfoLength = WIN32_LINUX(1, 2);
void* base = nullptr;
std::uintptr_t* oldVmt = nullptr;
std::unique_ptr<std::uintptr_t[]> newVmt;
std::size_t length = 0;
};