View Single Post
  #14  
Old 05-11-2016, 09:32
IChooseYou
 
Posts: n/a
I have only used to Detours 1.5 before, and the documentation for 3.0 isn't great. So in case anyone struggles:

PHP Code:
PVOID SetDetour( PVOID* ppTarget, PVOID pHandler )
{
    if ( 
DetourTransactionBegin( ) != NO_ERROR )
        return 
FALSE;

    if ( 
DetourUpdateThread( GetCurrentThread( ) ) != NO_ERROR )
    {
        
DetourTransactionCommit( );
        return 
NULL;
    }

    
PDETOUR_TRAMPOLINE pTrampoline = NULL;
    
    if ( 
DetourAttachEx( ppTarget, pHandler, &pTrampoline, NULL, NULL ) != NO_ERROR )
    {
        
DetourTransactionCommit( );
        return 
NULL;        
    }

    if ( 
DetourTransactionCommit( ) != NO_ERROR )
    {
        
DetourTransactionAbort( );
        return 
NULL;
    }

    return 
pTrampoline;
} 
Retouring works the same, call DetourDetach as opposed to DetourAttach/DetourAttachEx

PHP Code:
    g_lpDispatchMessage = reinterpret_cast<PVOID*>( 0x14317DCD0 );
    
oDispatchMessage = reinterpret_cast<tDispatchMessage>( SetDetour( &g_lpDispatchMessage, hkDispatchMessage ) );

    
RemoveDetour( &g_lpDispatchMessage, hkDispatchMessage ); 
Reply With Quote
The Following 6 Users Say Thank You to For This Useful Post:
besoeso (05-12-2016), dude719 (05-12-2016), romero (05-26-2016), user_hidden (05-11-2016)