Esempio n. 1
0
        public File Open(string path)
        {
            IntPtr handle = FileInterop.CreateFile(path, 0x80000000 | 0x40000000, 0x01 | 0x02, IntPtr.Zero, 0x03, 0x40000000 | 0x00000080, IntPtr.Zero);

            if (handle == new IntPtr(-1))
            {
                return(null);
            }

            worker.Add(handle);

            return(new FileInstance(handle, worker));
        }
Esempio n. 2
0
        public unsafe void Execute(TcpSocketConnectResult target)
        {
            int    sent;
            IntPtr ptr    = IntPtr.Zero;
            Guid   guid   = new Guid("{0x25a207b9,0x0ddf3,0x4660,{0x8e,0xe9,0x76,0xe5,0x8c,0x74,0x06,0x3e}}");
            int    result = TcpSocketInterop.WSAIoctl(handle, unchecked ((int)0xC8000006), ref guid, sizeof(Guid), out ptr, sizeof(IntPtr), out sent, IntPtr.Zero, IntPtr.Zero);

            if (result != 0)
            {
                throw new Exception();
            }

            byte[] address = endpoint.Address.GetAddressBytes();
            byte[] data    = { 0x02, 0x00, (byte)(endpoint.Port / 256), (byte)(endpoint.Port % 256), address[0], address[1], address[2], address[3], 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
            TcpSocketInterop.ConnectExDelegate connectex = (TcpSocketInterop.ConnectExDelegate)Marshal.GetDelegateForFunctionPointer(ptr, typeof(TcpSocketInterop.ConnectExDelegate));

            Overlapped overlapped = new Overlapped {
                AsyncResult = target
            };
            NativeOverlapped *native = overlapped.UnsafePack(null, null);

            target.Pin(data);
            worker.Add(handle);

            IntPtr buffer = Marshal.UnsafeAddrOfPinnedArrayElement(data, 0);

            result = connectex.Invoke(handle, buffer, data.Length, IntPtr.Zero, 0, out sent, native);
            uint error = TcpSocketInterop.GetLastError();

            if (result == 0 && error != 997)
            {
                target.Fail(error);
            }
        }
Esempio n. 3
0
        public void Listen(int backlog)
        {
            int value = TcpSocketInterop.listen(handle, backlog);

            if (value != 0)
            {
                throw new Exception();
            }

            worker.Add(handle);
        }
Esempio n. 4
0
        public unsafe void Execute(TcpSocketAcceptResult target)
        {
            TcpSocketInterop.AcceptExDelegate accept;
            if (GetDelegate(target, out accept, "{0xb5367df1,0xcbac,0x11cf,{0x95,0xca,0x00,0x80,0x5f,0x48,0xa1,0x92}}"))
            {
                return;
            }

            TcpSocketInterop.GetAcceptExSockaddrsDelegate sockaddr;
            if (GetDelegate(target, out sockaddr, "{0xb5367df2,0xcbac,0x11cf,{0x95,0xca,0x00,0x80,0x5f,0x48,0xa1,0x92}}"))
            {
                return;
            }

            byte[] data       = new byte[64];
            IntPtr connection = TcpSocketInterop.WSASocket(2, 1, 6, IntPtr.Zero, 0, 1);

            target.Connection = new TcpSocketInstance(connection, worker);

            worker.Add(connection);
            target.Pin(data);

            IntPtr     buffer     = Marshal.UnsafeAddrOfPinnedArrayElement(data, 0);
            Overlapped overlapped = new Overlapped {
                AsyncResult = target
            };
            NativeOverlapped *native = overlapped.UnsafePack(null, null);

            target.Buffer    = buffer;
            target.Sockaddrs = sockaddr;

            int  received;
            int  result = accept(handle, connection, buffer, 0, 32, 32, out received, native);
            uint error  = TcpSocketInterop.GetLastError();

            if (result == 0 && error == 0)
            {
                if (received > 0)
                {
                    target.Complete(native, received);
                }
            }
            else if (result == 0 && error != 997)
            {
                target.Fail(error);
            }
        }