From cecae73c03a8948c71dc9ba6675935ae27b63eae Mon Sep 17 00:00:00 2001 From: Connection Refused Date: Mon, 18 Oct 2021 18:50:54 +0800 Subject: [PATCH] [Netch] Compatible with the latest Redirector --- Netch/Controllers/NFController.cs | 10 +++++----- Netch/Interops/NFAPI.cs | 15 --------------- Netch/Interops/NF_STATUS.cs | 11 ----------- Netch/Interops/Redirector.cs | 10 ++++++++-- 4 files changed, 13 insertions(+), 33 deletions(-) delete mode 100644 Netch/Interops/NFAPI.cs delete mode 100644 Netch/Interops/NF_STATUS.cs diff --git a/Netch/Controllers/NFController.cs b/Netch/Controllers/NFController.cs index fa0f3c13..9c2ecf80 100644 --- a/Netch/Controllers/NFController.cs +++ b/Netch/Controllers/NFController.cs @@ -53,6 +53,8 @@ namespace Netch.Controllers // DNS Dial(NameList.AIO_FILTERDNS, _rdrConfig.DNSHijack.ToString().ToLower()); + Dial(NameList.AIO_DNSONLY, "false"); + Dial(NameList.AIO_DNSPROX, "true"); if (_rdrConfig.DNSHijack) { var dns = new Uri(DnsUtils.AppendScheme(DnsUtils.AppendPort(_rdrConfig.DNSHijackHost), "udp")); @@ -202,15 +204,13 @@ namespace Netch.Controllers } // 注册驱动文件 - var result = NFAPI.nf_registerDriver("netfilter2"); - if (result == NF_STATUS.NF_STATUS_SUCCESS) + if (Redirector.aio_register("netfilter2")) { Log.Information("Install netfilter2 driver finished"); } else { - Log.Error("Register netfilter2 failed: {Result}", result); - throw new MessageException($"Register netfilter2 failed\n{result}"); + Log.Error("Register netfilter2 failed"); } } @@ -237,7 +237,7 @@ namespace Netch.Controllers if (!File.Exists(SystemDriver)) return true; - NFAPI.nf_unRegisterDriver("netfilter2"); + Redirector.aio_unregister("netfilter2"); File.Delete(SystemDriver); return true; diff --git a/Netch/Interops/NFAPI.cs b/Netch/Interops/NFAPI.cs deleted file mode 100644 index d4a061c6..00000000 --- a/Netch/Interops/NFAPI.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Runtime.InteropServices; - -namespace Netch.Interops -{ - public static class NFAPI - { - private const string nfapinet_bin = "nfapinet.dll"; - - [DllImport(nfapinet_bin, CallingConvention = CallingConvention.Cdecl)] - public static extern NF_STATUS nf_registerDriver(string driverName); - - [DllImport(nfapinet_bin, CallingConvention = CallingConvention.Cdecl)] - public static extern NF_STATUS nf_unRegisterDriver(string driverName); - } -} \ No newline at end of file diff --git a/Netch/Interops/NF_STATUS.cs b/Netch/Interops/NF_STATUS.cs deleted file mode 100644 index a1a45152..00000000 --- a/Netch/Interops/NF_STATUS.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Netch.Interops -{ - public enum NF_STATUS : int - { - NF_STATUS_SUCCESS = 0, - NF_STATUS_FAIL = -1, - NF_STATUS_INVALID_ENDPOINT_ID = -2, - NF_STATUS_NOT_INITIALIZED = -3, - NF_STATUS_IO_ERROR = -4 - } -} \ No newline at end of file diff --git a/Netch/Interops/Redirector.cs b/Netch/Interops/Redirector.cs index 37144bbb..6c66c391 100644 --- a/Netch/Interops/Redirector.cs +++ b/Netch/Interops/Redirector.cs @@ -18,6 +18,8 @@ namespace Netch.Interops AIO_ICMPING, + AIO_DNSONLY, + AIO_DNSPROX, AIO_DNSHOST, AIO_DNSPORT, @@ -49,6 +51,12 @@ namespace Netch.Interops private const string Redirector_bin = "Redirector.bin"; + [DllImport(Redirector_bin, CallingConvention = CallingConvention.Cdecl)] + public static extern bool aio_register([MarshalAs(UnmanagedType.LPWStr)] string value); + + [DllImport(Redirector_bin, CallingConvention = CallingConvention.Cdecl)] + public static extern bool aio_unregister([MarshalAs(UnmanagedType.LPWStr)] string value); + [DllImport(Redirector_bin, CallingConvention = CallingConvention.Cdecl)] private static extern bool aio_dial(NameList name, [MarshalAs(UnmanagedType.LPWStr)] string value); @@ -58,12 +66,10 @@ namespace Netch.Interops [DllImport(Redirector_bin, CallingConvention = CallingConvention.Cdecl)] private static extern bool aio_free(); - /* [DllImport(Redirector_bin, CallingConvention = CallingConvention.Cdecl)] private static extern ulong aio_getUP(); [DllImport(Redirector_bin, CallingConvention = CallingConvention.Cdecl)] private static extern ulong aio_getDL(); - */ } } \ No newline at end of file