Hooking winsock recv

Jul 13, 2009 at 1:24 AM

I 'm trying to hook the recv fucntion in ws2_32.dll , in my own application ( so without dllinjection , just local hook). I would like to monitor the packets sent from a flash object. However something goes wrong because the application hangs.

I'm using these dllimpots .

[DllImport("ws2_32.dll")]
        static extern int recv([In] IntPtr socketHandle,  ref  IntPtr buffer,
            [In] int count, [In] System.Net.Sockets.SocketFlags socketFlags
            );
        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
        delegate int recvPointer(
               [In] IntPtr socketHandle,  ref IntPtr buffer,
             [In] int count, [In] System.Net.Sockets.SocketFlags socketFlags
            );

 

i tried also

[DllImport("ws2_32.dll")]
        static extern int recv([In] IntPtr socketHandle, StringBuilder buf,
            [In] int count, [In] System.Net.Sockets.SocketFlags socketFlags
            );
        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
        delegate int recvPointer(
               [In] IntPtr socketHandle,  StringBuilder buf,
             [In] int count, [In] System.Net.Sockets.SocketFlags socketFlags
            );

and also to set characterset to ansi.

But nothing worked . Can someone help me?

Thanks in advance.

Jul 22, 2009 at 12:24 AM

I managed to make the functions recv and send to work. But i have problems with 64bit os .

On my system windows xp 32bit everything works , but trying on vista 64 it crashes.

Is there any difference between  sockets in 32bit and 64bit?

Aug 26, 2009 at 9:07 PM

Can you post the code that you used to get this working? I've used yours as a jump off point but can't get it working...