Kawe Mazidjatari 144d5f62e1 IDetour: code refactor
Utilize the new IDetour::DetourSetup() code, IDetour::Attach and IDetour::Detach have been removed in favor of this (significantly reduces chance of user error). Since the template check happens in the idetour header, it is much more aggressive on type mismatches, such as a difference in parameter types, between the function and detour, will now raise a compile time error. As a result, some type mismatches have been fixed in this commit as well.
2024-04-05 16:41:09 +02:00

37 lines
1.0 KiB
C++

#ifndef IDETOUR_H
#define IDETOUR_H
//-----------------------------------------------------------------------------
// Interface class for context hooks
//-----------------------------------------------------------------------------
class IDetour
{
public:
virtual ~IDetour() { ; }
virtual void GetAdr(void) const = 0;
virtual void GetFun(void) const = 0;
virtual void GetVar(void) const = 0;
virtual void GetCon(void) const = 0;
virtual void Detour(const bool bAttach) const = 0;
template<
typename T,
typename std::enable_if<DetoursIsFunctionPointer<T>::value, int>::type = 0>
LONG DetourSetup(_Inout_ T* ppPointer, _In_ T pDetour, const bool bAttach) const
{
if (bAttach)
return DetourAttach(ppPointer, pDetour);
else
return DetourDetach(ppPointer, pDetour);
}
};
extern std::vector<IDetour*> g_DetourVec;
std::size_t AddDetour(IDetour* pDetour);
#define ADDDETOUR(x,y) static std::size_t dummy_reg_##y = AddDetour( new x() );
#define XREGISTER(x,y) ADDDETOUR(x, y)
#define REGISTER(x) XREGISTER(x, __COUNTER__)
#endif // IDETOUR_H