Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. ...
  2.     extern "C" BOOL ( PASCAL * Real_ConnectEx)( SOCKET s, const struct sockaddr *name, int namelen, PVOID lpSendBuffer, DWORD dwSendDataLength, LPDWORD lpdwBytesSent, LPOVERLAPPED lpOverlapped ) = 0;
  3.  
  4.     BOOL PASCAL Detour_ConnectEx( SOCKET s, const struct sockaddr *name, int namelen, PVOID lpSendBuffer, DWORD dwSendDataLength, LPDWORD lpdwBytesSent, LPOVERLAPPED lpOverlapped )
  5.     {
  6.         char buffer[1024] = { 0 };
  7.         memcpy( buffer, name, namelen );
  8.         LogDestination( name );
  9.         if( ShouldDetour( name, (sockaddr *)buffer ) )
  10.         {
  11.             return Real_ConnectEx( s, (sockaddr *)buffer, namelen, lpSendBuffer, dwSendDataLength, lpdwBytesSent, lpOverlapped );
  12.         }
  13.         return Real_ConnectEx( s, name, namelen, lpSendBuffer, dwSendDataLength, lpdwBytesSent, lpOverlapped );
  14.     }
  15.  
  16.     void LoadConnectEx()
  17.     {
  18.         WSADATA wsaData = { 0 };
  19.         WSAStartup( MAKEWORD( 2, 2 ), &wsaData );
  20.  
  21.         DWORD dwBytes = 0;
  22.         SOCKET s = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
  23.         if( SOCKET_ERROR != s )
  24.         {
  25.             if( SOCKET_ERROR != WSAIoctl( s, SIO_GET_EXTENSION_FUNCTION_POINTER, &GuidConnectEx, sizeof( GuidConnectEx ), &lpfnConnectEx, sizeof(lpfnConnectEx), &dwBytes, NULL, NULL ) )
  26.             {
  27.                 Real_ConnectEx = lpfnConnectEx;
  28.                 printf( "Real_ConnectEx = %x\n", lpfnConnectEx );
  29.             }
  30.             else
  31.             {
  32.                 printf( "WSAIoctl failed\n" );
  33.             }
  34.         }
  35.         else
  36.         {
  37.             printf( "socket failed\n" );
  38.         }
  39.  
  40.         WSACleanup();
  41.     }
  42.  
  43. ...
  44.  
  45. void User_Initialize()
  46. {
  47.     nsDetours::LoadConnectEx();
  48.  
  49.     DetourRestoreAfterWith();
  50.     DetourTransactionBegin();
  51.     DetourUpdateThread( GetCurrentThread() );
  52.  
  53.     DetourAttach( &(PVOID&)nsDetours::Real_ConnectEx, nsDetours::Detour_ConnectEx ); // RoM uses ConnectEx on winxp+
  54.  
  55.     DetourTransactionCommit();
  56. }
  57.  
  58. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement