So far I have this much, it appears to be working, and saves me a bit of typing. One problem is of scope, I cannot access the DetourFunc::Hook(), Unhook calls from "main.cpp" for instance..
I have it declared in "MoneyHook.h", defined in "MoneyHook.cpp", it is simply used like..
DetourFunc MoneyHookFunc("AddMoney", Real_Function, Hook_Function);
But from main, I want to be able to go..
MoneyHookFunc.Hook();
But I can't.. ??
DetourFunc.h
- Code: Select all
#pragma once
#include "stdafx.h"
#include "Logger.h"
class DetourFunc
{
private:
string ID;
PVOID* RealFunction;
PVOID HookFunction;
public:
DetourFunc(string, PVOID*, PVOID);
~DetourFunc();
void Hook();
void Unhook();
};
DetourFunc.cpp
- Code: Select all
#include "DetourFunc.h"
// Constructor
DetourFunc::DetourFunc(string id, PVOID* real, PVOID hook)
{
ID = id;
RealFunction = real;
HookFunction = hook;
}
// Destructor
DetourFunc::~DetourFunc(void)
{
// DetourFunc::Unhook(); // Probably needs some checks.... To avoid unnecessarily calling Uhook..
}
// Hook
void DetourFunc::Hook()
{
DetourTransactionBegin();
DetourUpdateThread( GetCurrentThread() );
DetourAttach(RealFunction, HookFunction);
DetourTransactionCommit();
Log("Hooked: " + ID);
}
// Unhook
void DetourFunc::Unhook()
{
DetourTransactionBegin();
DetourUpdateThread( GetCurrentThread() );
DetourDetach(RealFunction, HookFunction);
DetourTransactionCommit();
Log("Unhooked: " + ID);
}