Guest User

Untitled

a guest
Mar 14th, 2012
865
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #include <windows.h>
  2. #include <detours.h>
  3.  
  4. #pragma comment( lib, "Ws2_32.lib" )
  5. #pragma comment( lib, "detours.lib" )
  6. //#pragma comment( lib, "detoured.lib" )
  7.  
  8. int ( WINAPI *Real_Send )( SOCKET s, const char *buf, int len, int flags ) = send;
  9. int ( WINAPI *Real_Recv )( SOCKET s, char *buf, int len, int flags ) = recv;
  10. int WINAPI Mine_Send( SOCKET s, const char* buf, int len, int flags );
  11. int WINAPI Mine_Recv( SOCKET s, char *buf, int len, int flags );
  12.  
  13. int WINAPI Mine_Send( SOCKET s, const char *buf, int len, int flags ) {
  14. MessageBoxA(NULL, "Sending data", "Sending Data", MB_OK);
  15.  
  16. return Real_Send( s, buf, len, flags );
  17. }
  18.  
  19. int WINAPI Mine_Recv( SOCKET s, char *buf, int len, int flags ) {
  20. MessageBoxA(NULL, "Receiving data", "Receiving Data", MB_OK);
  21.  
  22. return Real_Recv( s, buf, len, flags );
  23. }
  24.  
  25. BOOL WINAPI DllMain( HINSTANCE, DWORD dwReason, LPVOID ) {
  26. switch ( dwReason ) {
  27. case DLL_PROCESS_ATTACH:
  28. MessageBox(NULL, "From DLL", "I am attached", MB_OK);
  29. DetourTransactionBegin();
  30. DetourUpdateThread( GetCurrentThread() );
  31. DetourAttach( &(PVOID &)Real_Send, Mine_Send );
  32. DetourAttach( &(PVOID &)Real_Recv, Mine_Recv );
  33. if ((DetourTransactionCommit()) == NO_ERROR)
  34. {
  35. MessageBox(NULL, "Detours successful", "Detoured", MB_OK);
  36. }
  37. break;
  38.  
  39. case DLL_PROCESS_DETACH:
  40. MessageBox(NULL, "From DLL", "I am deattached", MB_OK);
  41. DetourTransactionBegin();
  42. DetourUpdateThread( GetCurrentThread() );
  43. DetourDetach( &(PVOID &)Real_Send, Mine_Send );
  44. DetourDetach( &(PVOID &)Real_Recv, Mine_Recv );
  45. DetourTransactionCommit();
  46. break;
  47. }
  48.  
  49. return TRUE;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment