瀏覽代碼

修改无效handle的判断

老九 3 年之前
父節點
當前提交
a16844c0ea
共有 2 個文件被更改,包括 4 次插入6 次删除
  1. 2 3
      FastGithub.PacketIntercept/Dns/DnsInterceptor.cs
  2. 2 3
      FastGithub.PacketIntercept/Tcp/TcpInterceptor.cs

+ 2 - 3
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 =>

+ 2 - 3
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)}");