Clean Detours

Posts 1–3 of 3 · Page 1 of 1
Clean Detours
Here is my clean detours

Code:
void MessageBoxA_Detour( void ) 
{ 
    static decltype( &MessageBoxA ) lpMessageBoxA = reinterpret_cast<decltype( &MessageBoxA )>( GetProcAddress( LoadLibraryA( "user32.dll" ), "MessageBoxA" ) ); 

    decltype( &MessageBoxA ) hkMessageBoxA = []( HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType ) -> int 
    { 
        std::cout << "MessageBox Call: " << lpText << std::endl; 
         
        return 0; 
    }; 
    
    DetourFunc( reinterpret_cast<PBYTE>( lpMessageBoxA ), reinterpret_cast<PBYTE>( hkMessageBoxA ), 5 ); 
}
Usage:

Code:
MessageBoxA_Detour( ); 

MessageBoxA( HWND_DESKTOP, "Hooked", "Test", MB_OK );
This is not by you...

Also, you should not pass LPCTSTR's as argument type to MessageBoxA, since if you compile this with multi-byte character set TCHAR will be defined as wchar and you will have a argument type mismatch:

Code:
void MessageBoxA_Detour( void ) 
{ 
    static decltype( &MessageBoxA ) lpMessageBoxA = reinterpret_cast<decltype( &MessageBoxA )>( GetProcAddress( LoadLibraryA( "user32.dll" ), "MessageBoxA" ) ); 

    decltype( &MessageBoxA ) hkMessageBoxA = []( HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType ) -> int 
    { 
        std::cout << "MessageBox Call: " << lpText << std::endl; 
         
        return 0; 
    }; 
    
    DetourFunc( reinterpret_cast<PBYTE>( lpMessageBoxA ), reinterpret_cast<PBYTE>( hkMessageBoxA ), 5 ); 
}
Quote Originally Posted by -3ncrypted View Post
Here is my clean detours

Code:
void MessageBoxA_Detour( void ) 
{ 
    static decltype( &MessageBoxA ) lpMessageBoxA = reinterpret_cast<decltype( &MessageBoxA )>( GetProcAddress( LoadLibraryA( "user32.dll" ), "MessageBoxA" ) ); 

    decltype( &MessageBoxA ) hkMessageBoxA = []( HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType ) -> int 
    { 
        std::cout << "MessageBox Call: " << lpText << std::endl; 
         
        return 0; 
    }; 
    
    DetourFunc( reinterpret_cast<PBYTE>( lpMessageBoxA ), reinterpret_cast<PBYTE>( hkMessageBoxA ), 5 ); 
}
Usage:

Code:
MessageBoxA_Detour( ); 

MessageBoxA( HWND_DESKTOP, "Hooked", "Test", MB_OK );
It's nice but it's not even yours. I've seen you twice now post something and act as if you've created it when all you've done is rip it off another site.
Posts 1–3 of 3 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us