diff --git a/Netch/Controllers/NFController.cs b/Netch/Controllers/NFController.cs index 7f274f2d..fa0f3c13 100644 --- a/Netch/Controllers/NFController.cs +++ b/Netch/Controllers/NFController.cs @@ -34,7 +34,8 @@ namespace Netch.Controllers CheckDriver(); Dial(NameList.AIO_FILTERLOOPBACK, "false"); - Dial(NameList.AIO_FILTERINTRANET, "false"); + Dial(NameList.AIO_FILTERINTRANET, "true"); + Dial(NameList.AIO_FILTERPARENT, _rdrConfig.ChildProcessHandle.ToString().ToLower()); Dial(NameList.AIO_FILTERICMP, _rdrConfig.FilterICMP.ToString().ToLower()); Dial(NameList.AIO_ICMPING, _rdrConfig.ICMPDelay.ToString()); @@ -50,8 +51,14 @@ namespace Netch.Controllers // Mode Rule DialRule(_mode); - // Features TODO - // Dial(NameList.AIO_DNSHOST, _rdrConfig.DNSHijack ? _rdrConfig.DNSHijackHost : ""); + // DNS + Dial(NameList.AIO_FILTERDNS, _rdrConfig.DNSHijack.ToString().ToLower()); + if (_rdrConfig.DNSHijack) + { + var dns = new Uri(DnsUtils.AppendScheme(DnsUtils.AppendPort(_rdrConfig.DNSHijackHost), "udp")); + Dial(NameList.AIO_DNSHOST, dns.Host); + Dial(NameList.AIO_DNSPORT, dns.Port.ToString()); + } if (!await InitAsync()) throw new MessageException("Redirector start failed."); diff --git a/Netch/Forms/SettingForm.Designer.cs b/Netch/Forms/SettingForm.Designer.cs index e968740e..df414492 100644 --- a/Netch/Forms/SettingForm.Designer.cs +++ b/Netch/Forms/SettingForm.Designer.cs @@ -95,9 +95,9 @@ namespace Netch.Forms this.StopWhenExitedCheckBox = new System.Windows.Forms.CheckBox(); this.StartWhenOpenedCheckBox = new System.Windows.Forms.CheckBox(); this.MinimizeWhenStartedCheckBox = new System.Windows.Forms.CheckBox(); - this.NoSupportDialogCheckBox = new System.Windows.Forms.CheckBox(); this.RunAtStartupCheckBox = new System.Windows.Forms.CheckBox(); this.CheckUpdateWhenOpenedCheckBox = new System.Windows.Forms.CheckBox(); + this.NoSupportDialogCheckBox = new System.Windows.Forms.CheckBox(); this.CheckBetaUpdateCheckBox = new System.Windows.Forms.CheckBox(); this.UpdateServersWhenOpenedCheckBox = new System.Windows.Forms.CheckBox(); this.AioDNSTabPage = new System.Windows.Forms.TabPage(); @@ -109,6 +109,7 @@ namespace Netch.Forms this.AioDNSListenPortTextBox = new System.Windows.Forms.TextBox(); this.ControlButton = new System.Windows.Forms.Button(); this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); + this.DNSHijackLabel = new System.Windows.Forms.Label(); this.TabControl.SuspendLayout(); this.GeneralTabPage.SuspendLayout(); this.PortGroupBox.SuspendLayout(); @@ -324,6 +325,7 @@ namespace Netch.Forms this.NFTabPage.Controls.Add(this.ProcessFilterProtocolLabel); this.NFTabPage.Controls.Add(this.ProcessFilterProtocolComboBox); this.NFTabPage.Controls.Add(this.FilterICMPCheckBox); + this.NFTabPage.Controls.Add(this.DNSHijackLabel); this.NFTabPage.Controls.Add(this.ICMPDelayLabel); this.NFTabPage.Controls.Add(this.ICMPDelayTextBox); this.NFTabPage.Controls.Add(this.DNSHijackCheckBox); @@ -367,7 +369,7 @@ namespace Netch.Forms // ICMPDelayLabel // this.ICMPDelayLabel.AutoSize = true; - this.ICMPDelayLabel.Location = new System.Drawing.Point(30, 80); + this.ICMPDelayLabel.Location = new System.Drawing.Point(65, 80); this.ICMPDelayLabel.Name = "ICMPDelayLabel"; this.ICMPDelayLabel.Size = new System.Drawing.Size(100, 17); this.ICMPDelayLabel.TabIndex = 3; @@ -387,33 +389,29 @@ namespace Netch.Forms this.DNSHijackCheckBox.AutoSize = true; this.DNSHijackCheckBox.Location = new System.Drawing.Point(15, 110); this.DNSHijackCheckBox.Name = "DNSHijackCheckBox"; - this.DNSHijackCheckBox.Size = new System.Drawing.Size(196, 21); + this.DNSHijackCheckBox.Size = new System.Drawing.Size(92, 21); this.DNSHijackCheckBox.TabIndex = 5; - this.DNSHijackCheckBox.Text = "Handle process\'s DNS Hijack"; + this.DNSHijackCheckBox.Text = "DNS Hijack"; this.DNSHijackCheckBox.UseVisualStyleBackColor = true; - this.DNSHijackCheckBox.Visible = false; // // DNSHijackHostTextBox // this.DNSHijackHostTextBox.DataBindings.Add(new System.Windows.Forms.Binding("Enabled", this.DNSHijackCheckBox, "Checked", true)); - this.DNSHijackHostTextBox.Location = new System.Drawing.Point(237, 108); + this.DNSHijackHostTextBox.Location = new System.Drawing.Point(237, 138); this.DNSHijackHostTextBox.Name = "DNSHijackHostTextBox"; this.DNSHijackHostTextBox.Size = new System.Drawing.Size(191, 23); this.DNSHijackHostTextBox.TabIndex = 6; this.DNSHijackHostTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; - this.DNSHijackHostTextBox.Visible = false; // // ChildProcessHandleCheckBox // this.ChildProcessHandleCheckBox.AutoSize = true; - this.ChildProcessHandleCheckBox.Enabled = false; - this.ChildProcessHandleCheckBox.Location = new System.Drawing.Point(15, 140); + this.ChildProcessHandleCheckBox.Location = new System.Drawing.Point(15, 170); this.ChildProcessHandleCheckBox.Name = "ChildProcessHandleCheckBox"; this.ChildProcessHandleCheckBox.Size = new System.Drawing.Size(150, 21); this.ChildProcessHandleCheckBox.TabIndex = 7; this.ChildProcessHandleCheckBox.Text = "Child Process Handle"; this.ChildProcessHandleCheckBox.UseVisualStyleBackColor = true; - this.ChildProcessHandleCheckBox.Visible = false; // // WinTUNTabPage // @@ -785,16 +783,6 @@ namespace Netch.Forms this.MinimizeWhenStartedCheckBox.Text = "Minimize when started"; this.MinimizeWhenStartedCheckBox.UseVisualStyleBackColor = true; // - // NoSupportDialogCheckBox - // - this.NoSupportDialogCheckBox.AutoSize = true; - this.NoSupportDialogCheckBox.Location = new System.Drawing.Point(6, 72); - this.NoSupportDialogCheckBox.Name = "NoSupportDialogCheckBox"; - this.NoSupportDialogCheckBox.Size = new System.Drawing.Size(174, 21); - this.NoSupportDialogCheckBox.TabIndex = 6; - this.NoSupportDialogCheckBox.Text = "Disable Support Warning"; - this.NoSupportDialogCheckBox.UseVisualStyleBackColor = true; - // // RunAtStartupCheckBox // this.RunAtStartupCheckBox.AutoSize = true; @@ -816,6 +804,16 @@ namespace Netch.Forms this.CheckUpdateWhenOpenedCheckBox.TextAlign = System.Drawing.ContentAlignment.MiddleRight; this.CheckUpdateWhenOpenedCheckBox.UseVisualStyleBackColor = true; // + // NoSupportDialogCheckBox + // + this.NoSupportDialogCheckBox.AutoSize = true; + this.NoSupportDialogCheckBox.Location = new System.Drawing.Point(6, 72); + this.NoSupportDialogCheckBox.Name = "NoSupportDialogCheckBox"; + this.NoSupportDialogCheckBox.Size = new System.Drawing.Size(174, 21); + this.NoSupportDialogCheckBox.TabIndex = 6; + this.NoSupportDialogCheckBox.Text = "Disable Support Warning"; + this.NoSupportDialogCheckBox.UseVisualStyleBackColor = true; + // // CheckBetaUpdateCheckBox // this.CheckBetaUpdateCheckBox.AutoSize = true; @@ -929,6 +927,15 @@ namespace Netch.Forms this.flowLayoutPanel1.Size = new System.Drawing.Size(480, 400); this.flowLayoutPanel1.TabIndex = 0; // + // DNSHijackLabel + // + this.DNSHijackLabel.AutoSize = true; + this.DNSHijackLabel.Location = new System.Drawing.Point(65, 140); + this.DNSHijackLabel.Name = "DNSHijackLabel"; + this.DNSHijackLabel.Size = new System.Drawing.Size(34, 17); + this.DNSHijackLabel.TabIndex = 3; + this.DNSHijackLabel.Text = "DNS"; + // // SettingForm // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); @@ -1047,5 +1054,6 @@ namespace Netch.Forms private System.Windows.Forms.TextBox ICMPDelayTextBox; private System.Windows.Forms.Label ICMPDelayLabel; private System.Windows.Forms.CheckBox NoSupportDialogCheckBox; + private System.Windows.Forms.Label DNSHijackLabel; } } \ No newline at end of file diff --git a/Netch/Forms/SettingForm.cs b/Netch/Forms/SettingForm.cs index 6041ed57..8704acbb 100644 --- a/Netch/Forms/SettingForm.cs +++ b/Netch/Forms/SettingForm.cs @@ -94,14 +94,14 @@ namespace Netch.Forms Enum.GetNames(typeof(PortType)), Global.Settings.Redirector.FilterProtocol.ToString()); - BindCheckBox(DNSHijackCheckBox, b => Global.Settings.Redirector.DNSHijack = b, Global.Settings.Redirector.DNSHijack); - - BindTextBox(DNSHijackHostTextBox, s => true, s => Global.Settings.Redirector.DNSHijackHost = s, Global.Settings.Redirector.DNSHijackHost); - BindCheckBox(FilterICMPCheckBox, b => Global.Settings.Redirector.FilterICMP = b, Global.Settings.Redirector.FilterICMP); BindTextBox(ICMPDelayTextBox, s => true, s => Global.Settings.Redirector.ICMPDelay = s, Global.Settings.Redirector.ICMPDelay); + BindCheckBox(DNSHijackCheckBox, b => Global.Settings.Redirector.DNSHijack = b, Global.Settings.Redirector.DNSHijack); + + BindTextBox(DNSHijackHostTextBox, s => true, s => Global.Settings.Redirector.DNSHijackHost = s, Global.Settings.Redirector.DNSHijackHost); + BindCheckBox(ChildProcessHandleCheckBox, s => Global.Settings.Redirector.ChildProcessHandle = s, Global.Settings.Redirector.ChildProcessHandle); diff --git a/Netch/Interops/Redirector.cs b/Netch/Interops/Redirector.cs index 0a79b461..37144bbb 100644 --- a/Netch/Interops/Redirector.cs +++ b/Netch/Interops/Redirector.cs @@ -10,12 +10,17 @@ namespace Netch.Interops { AIO_FILTERLOOPBACK, AIO_FILTERINTRANET, // LAN + AIO_FILTERPARENT, AIO_FILTERICMP, AIO_FILTERTCP, AIO_FILTERUDP, + AIO_FILTERDNS, AIO_ICMPING, + AIO_DNSHOST, + AIO_DNSPORT, + AIO_TGTHOST, AIO_TGTPORT, AIO_TGTUSER, diff --git a/Netch/Utils/ServerConverterWithTypeDiscriminator.cs b/Netch/JsonConverter/ServerConverterWithTypeDiscriminator.cs similarity index 94% rename from Netch/Utils/ServerConverterWithTypeDiscriminator.cs rename to Netch/JsonConverter/ServerConverterWithTypeDiscriminator.cs index 752739dd..cb071358 100644 --- a/Netch/Utils/ServerConverterWithTypeDiscriminator.cs +++ b/Netch/JsonConverter/ServerConverterWithTypeDiscriminator.cs @@ -2,8 +2,9 @@ using System.Text.Json; using System.Text.Json.Serialization; using Netch.Models; +using Netch.Utils; -namespace Netch.Utils +namespace Netch.JsonConverter { public class ServerConverterWithTypeDiscriminator : JsonConverter { diff --git a/Netch/Models/Setting.cs b/Netch/Models/Setting.cs index 670983b2..68958e91 100644 --- a/Netch/Models/Setting.cs +++ b/Netch/Models/Setting.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Text.Json; -using System.Text.Json.Serialization; using Netch.Utils; namespace Netch.Models @@ -111,7 +110,6 @@ namespace Netch.Models /// /// 是否代理子进程 /// - [JsonIgnore] public bool ChildProcessHandle { get; set; } = false; } diff --git a/Netch/Netch.csproj b/Netch/Netch.csproj index 677b1a7b..ab46e681 100644 --- a/Netch/Netch.csproj +++ b/Netch/Netch.csproj @@ -70,6 +70,10 @@ + + + + <_FilesToBundle Remove="$(PkgMicrosoft_Diagnostics_Tracing_TraceEvent)\build\native\x86\**" /> diff --git a/Netch/Utils/Configuration.cs b/Netch/Utils/Configuration.cs index 85bafbe8..33a52836 100644 --- a/Netch/Utils/Configuration.cs +++ b/Netch/Utils/Configuration.cs @@ -5,6 +5,7 @@ using System.Text.Json; using System.Text.Json.Serialization; using System.Threading.Tasks; using Microsoft.VisualStudio.Threading; +using Netch.JsonConverter; using Netch.Models; using Serilog; @@ -90,8 +91,8 @@ namespace Netch.Utils for (var i = 0; i < settings.Profiles.Count; i++) settings.Profiles[i].Index = i; - settings.AioDNS.ChinaDNS = Utils.HostAppendPort(settings.AioDNS.ChinaDNS); - settings.AioDNS.OtherDNS = Utils.HostAppendPort(settings.AioDNS.OtherDNS); + settings.AioDNS.ChinaDNS = DnsUtils.AppendPort(settings.AioDNS.ChinaDNS); + settings.AioDNS.OtherDNS = DnsUtils.AppendPort(settings.AioDNS.OtherDNS); } /// diff --git a/Netch/Utils/DnsUtils.cs b/Netch/Utils/DnsUtils.cs index 6dc9bd7a..371cc455 100644 --- a/Netch/Utils/DnsUtils.cs +++ b/Netch/Utils/DnsUtils.cs @@ -101,5 +101,21 @@ namespace Netch.Utils { return string.Join(",", dns); } + + public static string AppendPort(string host, ushort port = 53) + { + if (!host.Contains(':')) + return host + $":{port}"; + + return host; + } + + public static string AppendScheme(string value, string scheme = "tcp") + { + if (!value.Contains(Uri.SchemeDelimiter)) + return scheme + Uri.SchemeDelimiter + value; + + return value; + } } } \ No newline at end of file diff --git a/Netch/Utils/ShareLink.cs b/Netch/Utils/ShareLink.cs index 69746f3f..71b7ad85 100644 --- a/Netch/Utils/ShareLink.cs +++ b/Netch/Utils/ShareLink.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Text; using System.Text.Json; +using Netch.JsonConverter; using Netch.Models; using Netch.Servers; using Serilog; diff --git a/Netch/Utils/Utils.cs b/Netch/Utils/Utils.cs index 1546f12e..64a149dd 100644 --- a/Netch/Utils/Utils.cs +++ b/Netch/Utils/Utils.cs @@ -246,14 +246,6 @@ namespace Netch.Utils return subnet.GetAddressBytes().Sum(b => Convert.ToString(b, 2).Count(c => c == '1')); } - public static string HostAppendPort(string host, ushort port = 53) - { - if (!host.Contains(':')) - host += $":{port}"; - - return host; - } - public static string GetHostFromUri(string str) { var startIndex = str.LastIndexOf('/');