Skip to content

Commit

Permalink
Merge commit 'ca930623f02bcca13f3a2f1b98f41228114f34dd' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
stevemk14ebr committed Mar 13, 2016
2 parents 06ca3ef + ca93062 commit 073e49b
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
35 changes: 35 additions & 0 deletions PolyHook/PolyHook/PolyHook.cpp
Expand Up @@ -270,6 +270,11 @@ PLH::X86Detour::~X86Detour()
delete[] m_Trampoline;
}

PLH::HookType PLH::X86Detour::GetType()
{
return PLH::HookType::X86Detour;
}

bool PLH::X86Detour::Hook()
{
DWORD OldProtection;
Expand Down Expand Up @@ -362,6 +367,11 @@ PLH::X64Detour::~X64Detour()
FreeTrampoline();
}

PLH::HookType PLH::X64Detour::GetType()
{
return PLH::HookType::X64Detour;
}

bool PLH::X64Detour::Hook()
{
//Allocate Memory as close as possible to src, to minimize chance 32bit displacements will be out of range (for relative jmp type)
Expand Down Expand Up @@ -463,6 +473,11 @@ int PLH::X64Detour::GetJMPSize()
#endif

/*----------------------------------------------*/
PLH::HookType PLH::VFuncSwap::GetType()
{
return PLH::HookType::VFuncSwap;
}

bool PLH::VFuncSwap::Hook()
{
MemoryProtect Protector(&m_hkVtable[m_hkIndex], sizeof(void*), PAGE_READWRITE);
Expand Down Expand Up @@ -495,6 +510,11 @@ PLH::VFuncDetour::~VFuncDetour()

}

PLH::HookType PLH::VFuncDetour::GetType()
{
return PLH::HookType::VFuncDetour;
}

bool PLH::VFuncDetour::Hook()
{
return m_Detour->Hook();
Expand Down Expand Up @@ -530,6 +550,11 @@ PLH::VTableSwap::~VTableSwap()
FreeNewVtable();
}

PLH::HookType PLH::VTableSwap::GetType()
{
return PLH::HookType::VTableSwap;
}

bool PLH::VTableSwap::Hook()
{
MemoryProtect Protector(m_phkClass, sizeof(void*), PAGE_READWRITE);
Expand Down Expand Up @@ -579,6 +604,11 @@ void PLH::VTableSwap::FreeNewVtable()
}

/*----------------------------------------------*/
PLH::HookType PLH::IATHook::GetType()
{
return PLH::HookType::IAT;
}

bool PLH::IATHook::Hook()
{
PIMAGE_THUNK_DATA Thunk;
Expand Down Expand Up @@ -678,6 +708,11 @@ bool PLH::IATHook::FindIATFunc(const char* LibraryName,const char* FuncName, PIM
}

/*----------------------------------------------*/
PLH::HookType PLH::VEHHook::GetType()
{
return PLH::HookType::VEH;
}

std::vector<PLH::VEHHook::HookCtx> PLH::VEHHook::m_HookTargets;
std::mutex PLH::VEHHook::m_TargetMutex;
PLH::VEHHook::VEHHook()
Expand Down
34 changes: 33 additions & 1 deletion PolyHook/PolyHook/PolyHook.h
Expand Up @@ -90,6 +90,17 @@ namespace PLH {
std::string m_Message;
};

enum class HookType
{
X86Detour,
X64Detour,
VFuncSwap,
VFuncDetour,
VTableSwap,
IAT,
VEH,
UNKNOWN
};
class IHook
{
public:
Expand All @@ -102,9 +113,11 @@ namespace PLH {

virtual bool Hook() = 0;
virtual void UnHook() = 0;

virtual HookType GetType() = 0;

virtual RuntimeError GetLastError() const;
virtual void PrintError(const RuntimeError& Err) const;

protected:
virtual void PostError(const RuntimeError& Err);
RuntimeError m_LastError;
Expand All @@ -117,6 +130,7 @@ namespace PLH {
AbstractDetour(const AbstractDetour& other) = delete;
AbstractDetour& operator=(const AbstractDetour& other) = delete;
virtual ~AbstractDetour();

template<typename T>
void SetupHook(T* Src, T* Dest)
{
Expand Down Expand Up @@ -177,6 +191,7 @@ namespace PLH {
virtual ~X86Detour();

virtual bool Hook() override;
virtual HookType GetType() override;
protected:
virtual x86_reg GetIpReg() override;
virtual void FreeTrampoline();
Expand All @@ -199,7 +214,9 @@ namespace PLH {
X64Detour(const X64Detour& other) = delete; //copy
X64Detour& operator=(const X64Detour& other) = delete; //copy assignment
virtual ~X64Detour();

virtual bool Hook() override;
virtual HookType GetType() override;
protected:
virtual x86_reg GetIpReg() override;
virtual void FreeTrampoline() override;
Expand All @@ -220,8 +237,11 @@ namespace PLH {
VFuncSwap(const VFuncSwap& other) = delete;
VFuncSwap& operator=(const VFuncSwap& other) = delete;
virtual ~VFuncSwap() = default;

virtual bool Hook() override;
virtual void UnHook() override;
virtual HookType GetType() override;

void SetupHook(BYTE** Vtable, const int Index, BYTE* Dest);
template<typename T>
T GetOriginal()
Expand All @@ -245,8 +265,11 @@ namespace PLH {
VFuncDetour(const VFuncDetour& other) = delete; //copy
VFuncDetour& operator=(const VFuncDetour& other) = delete; //copy assignment
virtual ~VFuncDetour();

virtual bool Hook() override;
virtual void UnHook() override;
virtual HookType GetType() override;

void SetupHook(BYTE** Vtable, const int Index, BYTE* Dest);
template<typename T>
T GetOriginal()
Expand Down Expand Up @@ -277,7 +300,10 @@ namespace PLH {
VTableSwap(const VTableSwap& other) = delete; //copy
VTableSwap& operator=(const VTableSwap& other) = delete; //copy assignment
virtual ~VTableSwap();

virtual bool Hook() override;
virtual HookType GetType() override;

template<typename T>
T HookAdditional(const int Index, BYTE* Dest)
{
Expand Down Expand Up @@ -318,8 +344,11 @@ namespace PLH {
IATHook(const IATHook& other) = delete; //copy
IATHook& operator=(const IATHook& other) = delete; //copy assignment
virtual ~IATHook() = default;

virtual bool Hook() override;
virtual void UnHook() override;
virtual HookType GetType() override;

template<typename T>
T GetOriginal()
{
Expand Down Expand Up @@ -384,8 +413,11 @@ namespace PLH {
VEHHook(const VEHHook& other) = delete; //copy
VEHHook& operator=(const VEHHook& other) = delete; //copy assignment
virtual ~VEHHook() = default;

virtual bool Hook() override;
virtual void UnHook() override;
virtual HookType GetType() override;

template<typename T>
T GetOriginal()
{
Expand Down

0 comments on commit 073e49b

Please sign in to comment.