diff --git a/Netch/Controllers/DNSController.cs b/Netch/Controllers/DNSController.cs index 5dc4fa59..4fb4e8e7 100644 --- a/Netch/Controllers/DNSController.cs +++ b/Netch/Controllers/DNSController.cs @@ -1,12 +1,15 @@ -namespace Netch.Controllers +using System.IO; +using System.Runtime.InteropServices; +using System.Text; + +namespace Netch.Controllers { public class DNSController : Controller { public DNSController() { Name = "DNS Service"; - MainFile = "unbound.exe"; - // RedirectStd = false; + RedirectStd = false; } /// @@ -15,12 +18,31 @@ /// public bool Start() { - return StartInstanceAuto("-c unbound-service.conf -v"); + if (!aiodns_dial(Encoding.UTF8.GetBytes(Path.GetFullPath("bin\\china_site_list")), + Encoding.UTF8.GetBytes("223.5.5.5:53"), + Encoding.UTF8.GetBytes("1.1.1.1:53")) + ) + return false; + return + aiodns_init(); } public override void Stop() { - StopInstance(); + aiodns_free(); } + + #region NativeMethods + + [DllImport("aiodns.bin", CallingConvention = CallingConvention.Cdecl)] + public static extern bool aiodns_dial(byte[] chinacon, byte[] chinadns, byte[] otherdns); + + [DllImport("aiodns.bin", CallingConvention = CallingConvention.Cdecl)] + public static extern bool aiodns_init(); + + [DllImport("aiodns.bin", CallingConvention = CallingConvention.Cdecl)] + public static extern void aiodns_free(); + + #endregion } } \ No newline at end of file diff --git a/Netch/Controllers/Mode/NFController.cs b/Netch/Controllers/Mode/NFController.cs index 2e468c9b..bf903fec 100644 --- a/Netch/Controllers/Mode/NFController.cs +++ b/Netch/Controllers/Mode/NFController.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.IO; +using System.Runtime.InteropServices; using System.ServiceProcess; using System.Text; using System.Threading.Tasks; @@ -62,18 +63,18 @@ namespace Netch.Controllers return false; } - NativeMethods.aio_dial((int) NameList.TYPE_CLRNAME, ""); + aio_dial((int) NameList.TYPE_CLRNAME, ""); foreach (var rule in mode.Rule) { - NativeMethods.aio_dial((int) NameList.TYPE_ADDNAME, rule); + aio_dial((int) NameList.TYPE_ADDNAME, rule); } - NativeMethods.aio_dial((int) NameList.TYPE_ADDNAME, "NTT.exe"); + aio_dial((int) NameList.TYPE_ADDNAME, "NTT.exe"); if (server.Type != "Socks5") { - NativeMethods.aio_dial((int) NameList.TYPE_TCPHOST, $"127.0.0.1:{Global.Settings.Socks5LocalPort}"); - NativeMethods.aio_dial((int) NameList.TYPE_UDPHOST, $"127.0.0.1:{Global.Settings.Socks5LocalPort}"); + aio_dial((int) NameList.TYPE_TCPHOST, $"127.0.0.1:{Global.Settings.Socks5LocalPort}"); + aio_dial((int) NameList.TYPE_UDPHOST, $"127.0.0.1:{Global.Settings.Socks5LocalPort}"); } else { @@ -84,8 +85,8 @@ namespace Netch.Controllers return false; } - NativeMethods.aio_dial((int) NameList.TYPE_TCPHOST, $"{result}:{server.Port}"); - NativeMethods.aio_dial((int) NameList.TYPE_UDPHOST, $"{result}:{server.Port}"); + aio_dial((int) NameList.TYPE_TCPHOST, $"{result}:{server.Port}"); + aio_dial((int) NameList.TYPE_UDPHOST, $"{result}:{server.Port}"); } if (Global.Settings.ModifySystemDNS) @@ -96,7 +97,7 @@ namespace Netch.Controllers DNS.SetDNS(dns); } - return NativeMethods.aio_init(); + return aio_init(); } public override void Stop() @@ -108,9 +109,28 @@ namespace Netch.Controllers DNS.SetDNS(_sysDns); }); - NativeMethods.aio_free(); + aio_free(); } + #region NativeMethods + + [DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)] + public static extern bool aio_dial(int name, [MarshalAs(UnmanagedType.LPWStr)] string value); + + [DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)] + public static extern bool aio_init(); + + [DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)] + public static extern bool aio_free(); + + [DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)] + public static extern ulong aio_getUP(); + + [DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)] + public static extern ulong aio_getDL(); + + #endregion + #region Utils /// diff --git a/Netch/Forms/SettingForm.cs b/Netch/Forms/SettingForm.cs index 21be3741..ca20dfd4 100644 --- a/Netch/Forms/SettingForm.cs +++ b/Netch/Forms/SettingForm.cs @@ -68,7 +68,7 @@ namespace Netch.Forms } else { - TUNTAPDNSTextBox.Text = "Unbound local DNS"; + TUNTAPDNSTextBox.Text = "Local DNS"; } } diff --git a/Netch/NativeMethods.cs b/Netch/NativeMethods.cs index 368e7608..b7f7dff3 100644 --- a/Netch/NativeMethods.cs +++ b/Netch/NativeMethods.cs @@ -78,20 +78,5 @@ namespace Netch [DllImport("dnsapi", EntryPoint = "DnsFlushResolverCache")] public static extern uint FlushDNSResolverCache(); - - [DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)] - public static extern bool aio_dial(int name, [MarshalAs(UnmanagedType.LPWStr)] string value); - - [DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)] - public static extern bool aio_init(); - - [DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)] - public static extern bool aio_free(); - - [DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)] - public static extern ulong aio_getUP(); - - [DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)] - public static extern ulong aio_getDL(); } } \ No newline at end of file diff --git a/binaries b/binaries index 8b849a23..f5a4d3bd 160000 --- a/binaries +++ b/binaries @@ -1 +1 @@ -Subproject commit 8b849a23230e7dfa3c196357b8b5cf196bb8468d +Subproject commit f5a4d3bd2892c20f26d24748980a412f04e6ee82