From a16844c0ea303dede2a3d9adf86c0643b879b644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=81=E4=B9=9D?= <366193849@qq.com> Date: Sat, 25 Sep 2021 10:18:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=A0=E6=95=88handle?= =?UTF-8?q?=E7=9A=84=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FastGithub.PacketIntercept/Dns/DnsInterceptor.cs | 5 ++--- FastGithub.PacketIntercept/Tcp/TcpInterceptor.cs | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) 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)}");