Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <detours.h>
- #pragma comment( lib, "Ws2_32.lib" )
- #pragma comment( lib, "detours.lib" )
- //#pragma comment( lib, "detoured.lib" )
- int ( WINAPI *Real_Send )( SOCKET s, const char *buf, int len, int flags ) = send;
- int ( WINAPI *Real_Recv )( SOCKET s, char *buf, int len, int flags ) = recv;
- int WINAPI Mine_Send( SOCKET s, const char* buf, int len, int flags );
- int WINAPI Mine_Recv( SOCKET s, char *buf, int len, int flags );
- int WINAPI Mine_Send( SOCKET s, const char *buf, int len, int flags ) {
- MessageBoxA(NULL, "Sending data", "Sending Data", MB_OK);
- return Real_Send( s, buf, len, flags );
- }
- int WINAPI Mine_Recv( SOCKET s, char *buf, int len, int flags ) {
- MessageBoxA(NULL, "Receiving data", "Receiving Data", MB_OK);
- return Real_Recv( s, buf, len, flags );
- }
- BOOL WINAPI DllMain( HINSTANCE, DWORD dwReason, LPVOID ) {
- switch ( dwReason ) {
- case DLL_PROCESS_ATTACH:
- MessageBox(NULL, "From DLL", "I am attached", MB_OK);
- DetourTransactionBegin();
- DetourUpdateThread( GetCurrentThread() );
- DetourAttach( &(PVOID &)Real_Send, Mine_Send );
- DetourAttach( &(PVOID &)Real_Recv, Mine_Recv );
- if ((DetourTransactionCommit()) == NO_ERROR)
- {
- MessageBox(NULL, "Detours successful", "Detoured", MB_OK);
- }
- break;
- case DLL_PROCESS_DETACH:
- MessageBox(NULL, "From DLL", "I am deattached", MB_OK);
- DetourTransactionBegin();
- DetourUpdateThread( GetCurrentThread() );
- DetourDetach( &(PVOID &)Real_Send, Mine_Send );
- DetourDetach( &(PVOID &)Real_Recv, Mine_Recv );
- DetourTransactionCommit();
- break;
- }
- return TRUE;
- }
Advertisement
Add Comment
Please, Sign In to add comment