/// <summary>
        /// Uninstall the network detours.
        /// </summary>
        public void Dispose()
        {
            OnReceivePacket = null;

            if (SendHook.SuccessfullyInstalled)
            {
                SendHook.Uninstall();
            }

            if (RecvHook.SuccessfullyInstalled)
            {
                RecvHook.Uninstall();
            }

            if (SendToHook.SuccessfullyInstalled)
            {
                SendToHook.Uninstall();
            }

            if (RecvFromHook.SuccessfullyInstalled)
            {
                RecvFromHook.Uninstall();
            }

            if (WSASendHook.SuccessfullyInstalled)
            {
                WSASendHook.Uninstall();
            }

            if (WSARecvHook.SuccessfullyInstalled)
            {
                WSARecvHook.Uninstall();
            }
        }
        /// <summary>
        /// NOTE: You can currently only filter the packets for SEND and RECV channels.
        /// </summary>
        /// <param name="channels"> By default, all channels are selected. </param>
        /// <param name="interceptCallback"> The packets intercepted will be received here for logging, and filtering if necessary. </param>
        public NetworkDetour Install(PacketChannel channels, InterceptCallback interceptCallback)
        {
            SelectedChannels = channels;
            OnReceivePacket  = interceptCallback;

            if (SelectedChannels.HasFlag(PacketChannel.Send))
            {
                SendHook = new Detour().Install("ws2_32.dll", "send", callback_repl_send);
            }

            if (SelectedChannels.HasFlag(PacketChannel.Recv))
            {
                RecvHook = new Detour().Install("ws2_32.dll", "recv", callback_repl_recv);
            }

            if (SelectedChannels.HasFlag(PacketChannel.SendTo))
            {
                SendToHook = new Detour().Install("ws2_32.dll", "sendto", callback_repl_send_to);
            }

            if (SelectedChannels.HasFlag(PacketChannel.RecvFrom))
            {
                RecvFromHook = new Detour().Install("ws2_32.dll", "recvfrom", callback_repl_recv_from);
            }

            if (SelectedChannels.HasFlag(PacketChannel.WSASend))
            {
                WSASendHook = new Detour().Install("ws2_32.dll", "WSASend", callback_repl_wsa_send);
            }

            if (SelectedChannels.HasFlag(PacketChannel.WSARecv))
            {
                WSARecvHook = new Detour().Install("ws2_32.dll", "WSARecv", callback_repl_wsa_recv);
            }

            return(this);
        }
Beispiel #3
0
        public void SetInterceptCallback(InterceptCallback callback)
        {
            ThrowIfNotCreated();

            Native.enet_host_set_intercept_callback(nativeHost, Marshal.GetFunctionPointerForDelegate(callback));
        }
 private static CallbackRegistration SetInterceptCallback(Host host, InterceptCallback callback)
 {
     host.SetInterceptCallback(callback);
     return(new CallbackRegistration(callback));
 }
 public void Dispose() => this.callback = null;
 public CallbackRegistration(InterceptCallback callback)
 {
     this.callback = callback;
 }