2

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

Community
  • 1
  • 1
  • Typically it's inet_ntop, but I'm not sure about C# having access to that. https://msdn.microsoft.com/en-us/library/windows/desktop/cc805843(v=vs.85).aspx – Mike Oct 13 '15 at 14:07
  • Actually this(stackoverflow.com/a/17430748/3312744) code for the inet and how to make it in C#. the problem I don't know how to get the Ptr to sockaddr. this(stackoverflow.com/a/11732261/3312744) answer if I know how to make it will solve it – user3312744 Oct 18 '15 at 05:00
  • The question can be (How to get an IntPtr which points to a sockaddr structure from a P/Invoked native function (such as connect)?) – – user3312744 Oct 18 '15 at 05:00

0 Answers0