diff --git a/FastGithub.PacketIntercept/Dns/DnsInterceptor.cs b/FastGithub.PacketIntercept/Dns/DnsInterceptor.cs index 7569464..46801a7 100644 --- a/FastGithub.PacketIntercept/Dns/DnsInterceptor.cs +++ b/FastGithub.PacketIntercept/Dns/DnsInterceptor.cs @@ -62,10 +62,9 @@ namespace FastGithub.PacketIntercept.Dns await Task.Yield(); var handle = WinDivert.WinDivertOpen(DNS_FILTER, WinDivertLayer.Network, 0, WinDivertOpenFlags.None); - if (handle == IntPtr.MaxValue || handle == IntPtr.Zero) + if (handle == new IntPtr(unchecked((long)ulong.MaxValue))) { - const int ERROR_INVALID_HANDLE = 0x6; - throw new Win32Exception(ERROR_INVALID_HANDLE, "打开驱动失败"); + throw new Win32Exception(); } cancellationToken.Register(hwnd => diff --git a/FastGithub.PacketIntercept/Tcp/TcpInterceptor.cs b/FastGithub.PacketIntercept/Tcp/TcpInterceptor.cs index 2dfd4c7..db7bf15 100644 --- a/FastGithub.PacketIntercept/Tcp/TcpInterceptor.cs +++ b/FastGithub.PacketIntercept/Tcp/TcpInterceptor.cs @@ -50,10 +50,9 @@ namespace FastGithub.PacketIntercept.Tcp await Task.Yield(); var handle = WinDivert.WinDivertOpen(this.filter, WinDivertLayer.Network, 0, WinDivertOpenFlags.None); - if (handle == IntPtr.MaxValue || handle == IntPtr.Zero) + if (handle == new IntPtr(unchecked((long)ulong.MaxValue))) { - const int ERROR_INVALID_HANDLE = 0x6; - throw new Win32Exception(ERROR_INVALID_HANDLE, "打开驱动失败"); + throw new Win32Exception(); } this.logger.LogInformation($"tcp://{IPAddress.Loopback}:{BinaryPrimitives.ReverseEndianness(this.oldServerPort)} => tcp://{IPAddress.Loopback}:{BinaryPrimitives.ReverseEndianness(this.newServerPort)}");