I hook the connect function using deviare , and C#. the issue is I need to get the IP Address from the sockaddr(which is the second param in the connect function) .
I checked the answers: C# sockaddr to sockaddr_in & https://stackoverflow.com/a/17430748/3312744
I tried to use them. But I face a problem of getting the IntPtr from the connect function. I tried the following:
IParam pm = callInfo.Params.get_Item(1);
IntPtr sock = new IntPtr(pm.Value) ;
IPAddress ip_ader = ConvertSockAddrPtrToIPAddress(sock);
the ConvertSockAddrPtrToIPAddress is a method used in this answer: https://stackoverflow.com/a/17430748/3312744 but an exception always thrown.
the exception is (The runtime has encountered a fatal error. The address of the error was at 0x531a0858, on thread 0x724. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.)
Sorry for the weak English. Thank you in advance