Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ...
- extern "C" BOOL ( PASCAL * Real_ConnectEx)( SOCKET s, const struct sockaddr *name, int namelen, PVOID lpSendBuffer, DWORD dwSendDataLength, LPDWORD lpdwBytesSent, LPOVERLAPPED lpOverlapped ) = 0;
- BOOL PASCAL Detour_ConnectEx( SOCKET s, const struct sockaddr *name, int namelen, PVOID lpSendBuffer, DWORD dwSendDataLength, LPDWORD lpdwBytesSent, LPOVERLAPPED lpOverlapped )
- {
- char buffer[1024] = { 0 };
- memcpy( buffer, name, namelen );
- LogDestination( name );
- if( ShouldDetour( name, (sockaddr *)buffer ) )
- {
- return Real_ConnectEx( s, (sockaddr *)buffer, namelen, lpSendBuffer, dwSendDataLength, lpdwBytesSent, lpOverlapped );
- }
- return Real_ConnectEx( s, name, namelen, lpSendBuffer, dwSendDataLength, lpdwBytesSent, lpOverlapped );
- }
- void LoadConnectEx()
- {
- WSADATA wsaData = { 0 };
- WSAStartup( MAKEWORD( 2, 2 ), &wsaData );
- DWORD dwBytes = 0;
- SOCKET s = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
- if( SOCKET_ERROR != s )
- {
- if( SOCKET_ERROR != WSAIoctl( s, SIO_GET_EXTENSION_FUNCTION_POINTER, &GuidConnectEx, sizeof( GuidConnectEx ), &lpfnConnectEx, sizeof(lpfnConnectEx), &dwBytes, NULL, NULL ) )
- {
- Real_ConnectEx = lpfnConnectEx;
- printf( "Real_ConnectEx = %x\n", lpfnConnectEx );
- }
- else
- {
- printf( "WSAIoctl failed\n" );
- }
- }
- else
- {
- printf( "socket failed\n" );
- }
- WSACleanup();
- }
- ...
- void User_Initialize()
- {
- nsDetours::LoadConnectEx();
- DetourRestoreAfterWith();
- DetourTransactionBegin();
- DetourUpdateThread( GetCurrentThread() );
- DetourAttach( &(PVOID&)nsDetours::Real_ConnectEx, nsDetours::Detour_ConnectEx ); // RoM uses ConnectEx on winxp+
- DetourTransactionCommit();
- }
- ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement