forked from danielkrupinski/Osiris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
416b4f9
commit 7dc9cd3
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "MinHook.h" | ||
#include "../MinHook/MinHook.h" | ||
|
||
void MinHook::init(void* base) noexcept | ||
{ | ||
this->base = base; | ||
} | ||
|
||
void MinHook::hookAt(std::size_t index, void* fun) noexcept | ||
{ | ||
void* orig; | ||
MH_CreateHook((*reinterpret_cast<void***>(base))[index], fun, &orig); | ||
originals[index] = uintptr_t(orig); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,35 @@ | ||
#pragma once | ||
|
||
#include <cassert> | ||
#include <cstddef> | ||
#include <unordered_map> | ||
|
||
class MinHook { | ||
public: | ||
void init(void* base) noexcept; | ||
void restore() noexcept {} | ||
void hookAt(std::size_t index, void* fun) noexcept; | ||
|
||
template <typename T, std::size_t Idx, typename ...Args> | ||
auto callOriginal(Args... args) const noexcept | ||
{ | ||
const auto it = originals.find(Idx); | ||
if (it != originals.cend()) | ||
return reinterpret_cast<T(__thiscall*)(void*, Args...)>(it->second)(base, args...); | ||
assert(false); | ||
std::exit(1); | ||
} | ||
|
||
template <typename T, typename ...Args> | ||
auto getOriginal(std::size_t index, Args... args) const noexcept | ||
{ | ||
const auto it = originals.find(index); | ||
if (it != originals.cend()) | ||
return reinterpret_cast<T(__thiscall*)(void*, Args...)>(it->second); | ||
assert(false); | ||
std::exit(1); | ||
} | ||
private: | ||
void* base; | ||
std::unordered_map<std::size_t, uintptr_t> originals; | ||
}; |