So i decided to rewrite a bit my detour class using some C++11 stuff.
And that's what i have for now:
- Detouring __cdecl, __stdcall, __thiscall functions (__fastcall can be detoured too, but not with generic method)
- x64 support
- Free functions and class member functions as hooks (static and non-static)
- Function splicing and HWBP as detour methods
- Clean user callbacks
Things i'm aware of and don't have yet:
- No check for detours already present in function when using splice
- HWBP's are applied only to threads that exist at the moment of detour application
Quick usage example (you can find more in Test file in sources):
PHP Code:
#include "DSDetour.h"
using namespace ds_detour;
class TestClass1
{
public:
TestClass1(): junk(5) { }
~TestClass1() { }
int TestMsgBox( HWND& a1, LPCSTR& a2, LPCSTR& a3, UINT& a4 )
{
a2 = "NewMessage";
a4 = MB_ICONQUESTION;
return 100500;
}
private:
int junk;
};
int _tmain(int argc, _TCHAR* argv[])
{
TestClass1 mclass;
CDSDetour< int ( HWND, LPCSTR, LPCSTR, UINT ) > detourMsgBox(DetourType::HWBP, ReturnType::New, CallOrder::BeforeOriginal);
detourMsgBox.DetourFunction(&MessageBoxA, &TestClass1::TestMsgBox, &mclass);
int retval = MessageBoxA(0, "Test", "Caption", MB_ICONEXCLAMATION);
return 0;
}
To compile it you need VS2012 + VC CTP Nov 2012 (for variadic templates) . Or you can do lots of tweaks and make it with GCC or Clang
Repository: https://www.assembla.com/code/darkde...bversion/nodes