修改无效handle的判断

This commit is contained in:
老九 2021-09-25 10:18:51 +08:00
parent b4623ddb60
commit a16844c0ea
2 changed files with 4 additions and 6 deletions

View File

@ -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 =>

View File

@ -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)}");