From 3565251b4d7e0176ef8b8dc7f571eb95443ef3ae Mon Sep 17 00:00:00 2001 From: ChsBuffer <33744752+chsbuffer@users.noreply.github.com> Date: Sun, 28 Mar 2021 02:12:51 +0800 Subject: [PATCH] Update Redirector extract RedirectorConfig move BypassIPs to Setting.TUNTAP --- Netch/Controllers/NFController.cs | 18 ++--- Netch/Controllers/TUNController.cs | 2 +- Netch/Forms/GlobalBypassIPForm.cs | 9 ++- Netch/Forms/SettingForm.Designer.cs | 112 ++++++++++++---------------- Netch/Forms/SettingForm.cs | 36 ++++----- Netch/Interops/RedirectorInterop.cs | 36 +++++---- Netch/Models/Setting.cs | 84 ++++++++++----------- Netch/Utils/ModeHelper.cs | 4 +- 8 files changed, 133 insertions(+), 168 deletions(-) diff --git a/Netch/Controllers/NFController.cs b/Netch/Controllers/NFController.cs index b871b490..6a32627c 100644 --- a/Netch/Controllers/NFController.cs +++ b/Netch/Controllers/NFController.cs @@ -25,21 +25,21 @@ namespace Netch.Controllers { CheckDriver(); - Dial(NameList.TYPE_FILTERLOOPBACK, "false"); - Dial(NameList.TYPE_TCPLISN, Global.Settings.RedirectorTCPPort.ToString()); + Dial(NameList.TYPE_FILTLOP, "false"); + var p = PortHelper.GetAvailablePort(); + Dial(NameList.TYPE_TCPLISN, p.ToString()); + Dial(NameList.TYPE_UDPLISN, p.ToString()); // Server - Dial(NameList.TYPE_FILTERUDP, (Global.Settings.ProcessProxyProtocol != PortType.TCP).ToString().ToLower()); - Dial(NameList.TYPE_FILTERTCP, (Global.Settings.ProcessProxyProtocol != PortType.UDP).ToString().ToLower()); - dial_Server(Global.Settings.ProcessProxyProtocol); + Dial(NameList.TYPE_FILTUDP, (Global.Settings.Redirector.ProxyProtocol != PortType.TCP).ToString().ToLower()); + Dial(NameList.TYPE_FILTTCP, (Global.Settings.Redirector.ProxyProtocol != PortType.UDP).ToString().ToLower()); + dial_Server(Global.Settings.Redirector.ProxyProtocol); // Mode Rule dial_Name(mode); // Features - Dial(NameList.TYPE_REDIRCTOR_DNS, Global.Settings.RedirectDNS ? Global.Settings.RedirectDNSAddr : ""); - Dial(NameList.TYPE_REDIRCTOR_ICMP, Global.Settings.RedirectICMP ? Global.Settings.RedirectICMPAddr : ""); - Dial(NameList.TYPE_FILTERCHILDPROC, Global.Settings.ChildProcessHandle.ToString().ToLower()); + Dial(NameList.TYPE_DNSHOST, Global.Settings.Redirector.DNSHijack ? Global.Settings.Redirector.DNSHijackHost : ""); if (!Init()) throw new MessageException("Redirector Start failed, run Netch with \"-console\" argument"); @@ -126,7 +126,7 @@ namespace Netch.Controllers Dial(NameList.TYPE_TCPPASS + offset, socks5.Password ?? string.Empty); Dial(NameList.TYPE_TCPMETH + offset, string.Empty); } - else if (server is Shadowsocks shadowsocks && !shadowsocks.HasPlugin() && Global.Settings.RedirectorSS) + else if (server is Shadowsocks shadowsocks && !shadowsocks.HasPlugin() && Global.Settings.Redirector.RedirectorSS) { Dial(NameList.TYPE_TCPTYPE + offset, "Shadowsocks"); Dial(NameList.TYPE_TCPHOST + offset, $"{shadowsocks.AutoResolveHostname()}:{shadowsocks.Port}"); diff --git a/Netch/Controllers/TUNController.cs b/Netch/Controllers/TUNController.cs index d5c3faf0..ada37e9b 100644 --- a/Netch/Controllers/TUNController.cs +++ b/Netch/Controllers/TUNController.cs @@ -149,7 +149,7 @@ namespace Netch.Controllers RouteAction(Action.Create, $"{_serverAddresses}/32", RouteType.Outbound); Logging.Info("绕行 → 全局绕过 IP"); - RouteAction(Action.Create, Global.Settings.BypassIPs, RouteType.Outbound); + RouteAction(Action.Create, Global.Settings.TUNTAP.BypassIPs, RouteType.Outbound); #region Rule IPs diff --git a/Netch/Forms/GlobalBypassIPForm.cs b/Netch/Forms/GlobalBypassIPForm.cs index 5baa2d78..eac41ef2 100644 --- a/Netch/Forms/GlobalBypassIPForm.cs +++ b/Netch/Forms/GlobalBypassIPForm.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Net; using System.Windows.Forms; using Netch.Properties; @@ -18,7 +19,7 @@ namespace Netch.Forms { i18N.TranslateForm(this); - IPListBox.Items.AddRange(Global.Settings.BypassIPs.ToArray()); + IPListBox.Items.AddRange(Global.Settings.TUNTAP.BypassIPs.Cast().ToArray()); for (var i = 32; i >= 1; i--) PrefixComboBox.Items.Add(i); @@ -31,7 +32,7 @@ namespace Netch.Forms if (!string.IsNullOrEmpty(IPTextBox.Text)) { if (IPAddress.TryParse(IPTextBox.Text, out var address)) - IPListBox.Items.Add(string.Format("{0}/{1}", address, PrefixComboBox.SelectedItem)); + IPListBox.Items.Add($"{address}/{PrefixComboBox.SelectedItem}"); else MessageBoxX.Show(i18N.Translate("Please enter a correct IP address")); } @@ -51,9 +52,9 @@ namespace Netch.Forms private void ControlButton_Click(object sender, EventArgs e) { - Global.Settings.BypassIPs.Clear(); + Global.Settings.TUNTAP.BypassIPs.Clear(); foreach (var ip in IPListBox.Items) - Global.Settings.BypassIPs.Add((string) ip); + Global.Settings.TUNTAP.BypassIPs.Add((string) ip); Configuration.Save(); MessageBoxX.Show(i18N.Translate("Saved")); diff --git a/Netch/Forms/SettingForm.Designer.cs b/Netch/Forms/SettingForm.Designer.cs index 79f4684a..62abb182 100644 --- a/Netch/Forms/SettingForm.Designer.cs +++ b/Netch/Forms/SettingForm.Designer.cs @@ -38,8 +38,6 @@ namespace Netch.Forms this.Socks5PortTextBox = new System.Windows.Forms.TextBox(); this.HTTPPortLabel = new System.Windows.Forms.Label(); this.HTTPPortTextBox = new System.Windows.Forms.TextBox(); - this.RedirectorLabel = new System.Windows.Forms.Label(); - this.RedirectorTextBox = new System.Windows.Forms.TextBox(); this.AllowDevicesCheckBox = new System.Windows.Forms.CheckBox(); this.ResolveServerHostnameCheckBox = new System.Windows.Forms.CheckBox(); this.ServerPingTypeLabel = new System.Windows.Forms.Label(); @@ -59,10 +57,10 @@ namespace Netch.Forms this.groupBox1 = new System.Windows.Forms.GroupBox(); this.ProcessProxyProtocolLabel = new System.Windows.Forms.Label(); this.ProcessProxyProtocolComboBox = new System.Windows.Forms.ComboBox(); - this.DNSRedirectorCheckBox = new System.Windows.Forms.CheckBox(); - this.RDRDNSTextBox = new System.Windows.Forms.TextBox(); - this.ICMPRedirectorCheckBox = new System.Windows.Forms.CheckBox(); - this.ModifiedICMPTextBox = new System.Windows.Forms.TextBox(); + this.DNSHijackCheckBox = new System.Windows.Forms.CheckBox(); + this.DNSHijackHostTextBox = new System.Windows.Forms.TextBox(); + this.ICMPHijackCheckBox = new System.Windows.Forms.CheckBox(); + this.ICMPHijackHostTextBox = new System.Windows.Forms.TextBox(); this.RedirectorSSCheckBox = new System.Windows.Forms.CheckBox(); this.ChildProcessHandleCheckBox = new System.Windows.Forms.CheckBox(); this.TAPTabPage = new System.Windows.Forms.TabPage(); @@ -174,8 +172,6 @@ namespace Netch.Forms this.PortGroupBox.Controls.Add(this.Socks5PortTextBox); this.PortGroupBox.Controls.Add(this.HTTPPortLabel); this.PortGroupBox.Controls.Add(this.HTTPPortTextBox); - this.PortGroupBox.Controls.Add(this.RedirectorLabel); - this.PortGroupBox.Controls.Add(this.RedirectorTextBox); this.PortGroupBox.Controls.Add(this.AllowDevicesCheckBox); this.PortGroupBox.Location = new System.Drawing.Point(8, 6); this.PortGroupBox.Name = "PortGroupBox"; @@ -218,23 +214,6 @@ namespace Netch.Forms this.HTTPPortTextBox.TabIndex = 3; this.HTTPPortTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // - // RedirectorLabel - // - this.RedirectorLabel.AutoSize = true; - this.RedirectorLabel.Location = new System.Drawing.Point(9, 83); - this.RedirectorLabel.Name = "RedirectorLabel"; - this.RedirectorLabel.Size = new System.Drawing.Size(95, 17); - this.RedirectorLabel.TabIndex = 4; - this.RedirectorLabel.Text = "Redirector TCP"; - // - // RedirectorTextBox - // - this.RedirectorTextBox.Location = new System.Drawing.Point(120, 80); - this.RedirectorTextBox.Name = "RedirectorTextBox"; - this.RedirectorTextBox.Size = new System.Drawing.Size(90, 23); - this.RedirectorTextBox.TabIndex = 5; - this.RedirectorTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; - // // AllowDevicesCheckBox // this.AllowDevicesCheckBox.AutoSize = true; @@ -358,7 +337,7 @@ namespace Netch.Forms // LanguageLabel // this.LanguageLabel.AutoSize = true; - this.LanguageLabel.Location = new System.Drawing.Point(17, 254); + this.LanguageLabel.Location = new System.Drawing.Point(12, 254); this.LanguageLabel.Name = "LanguageLabel"; this.LanguageLabel.Size = new System.Drawing.Size(65, 17); this.LanguageLabel.TabIndex = 15; @@ -390,10 +369,10 @@ namespace Netch.Forms // this.groupBox1.Controls.Add(this.ProcessProxyProtocolLabel); this.groupBox1.Controls.Add(this.ProcessProxyProtocolComboBox); - this.groupBox1.Controls.Add(this.DNSRedirectorCheckBox); - this.groupBox1.Controls.Add(this.RDRDNSTextBox); - this.groupBox1.Controls.Add(this.ICMPRedirectorCheckBox); - this.groupBox1.Controls.Add(this.ModifiedICMPTextBox); + this.groupBox1.Controls.Add(this.DNSHijackCheckBox); + this.groupBox1.Controls.Add(this.DNSHijackHostTextBox); + this.groupBox1.Controls.Add(this.ICMPHijackCheckBox); + this.groupBox1.Controls.Add(this.ICMPHijackHostTextBox); this.groupBox1.Location = new System.Drawing.Point(5, 6); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(450, 117); @@ -418,43 +397,45 @@ namespace Netch.Forms this.ProcessProxyProtocolComboBox.Size = new System.Drawing.Size(191, 25); this.ProcessProxyProtocolComboBox.TabIndex = 1; // - // DNSRedirectorCheckBox + // DNSHijackCheckBox // - this.DNSRedirectorCheckBox.AutoSize = true; - this.DNSRedirectorCheckBox.Location = new System.Drawing.Point(6, 51); - this.DNSRedirectorCheckBox.Name = "DNSRedirectorCheckBox"; - this.DNSRedirectorCheckBox.Size = new System.Drawing.Size(196, 21); - this.DNSRedirectorCheckBox.TabIndex = 2; - this.DNSRedirectorCheckBox.Text = "Handle process\'s DNS Hijack"; - this.DNSRedirectorCheckBox.UseVisualStyleBackColor = true; + this.DNSHijackCheckBox.AutoSize = true; + this.DNSHijackCheckBox.Location = new System.Drawing.Point(6, 51); + this.DNSHijackCheckBox.Name = "DNSHijackCheckBox"; + this.DNSHijackCheckBox.Size = new System.Drawing.Size(196, 21); + this.DNSHijackCheckBox.TabIndex = 2; + this.DNSHijackCheckBox.Text = "Handle process\'s DNS Hijack"; + this.DNSHijackCheckBox.UseVisualStyleBackColor = true; // - // RDRDNSTextBox + // DNSHijackHostTextBox // - this.RDRDNSTextBox.DataBindings.Add(new System.Windows.Forms.Binding("Enabled", this.DNSRedirectorCheckBox, "Checked", true)); - this.RDRDNSTextBox.Location = new System.Drawing.Point(253, 46); - this.RDRDNSTextBox.Name = "RDRDNSTextBox"; - this.RDRDNSTextBox.Size = new System.Drawing.Size(191, 23); - this.RDRDNSTextBox.TabIndex = 4; - this.RDRDNSTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.DNSHijackHostTextBox.DataBindings.Add(new System.Windows.Forms.Binding("Enabled", this.DNSHijackCheckBox, "Checked", true)); + this.DNSHijackHostTextBox.Location = new System.Drawing.Point(253, 46); + this.DNSHijackHostTextBox.Name = "DNSHijackHostTextBox"; + this.DNSHijackHostTextBox.Size = new System.Drawing.Size(191, 23); + this.DNSHijackHostTextBox.TabIndex = 4; + this.DNSHijackHostTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // - // ICMPRedirectorCheckBox + // ICMPHijackCheckBox // - this.ICMPRedirectorCheckBox.AutoSize = true; - this.ICMPRedirectorCheckBox.Location = new System.Drawing.Point(6, 81); - this.ICMPRedirectorCheckBox.Name = "ICMPRedirectorCheckBox"; - this.ICMPRedirectorCheckBox.Size = new System.Drawing.Size(139, 21); - this.ICMPRedirectorCheckBox.TabIndex = 5; - this.ICMPRedirectorCheckBox.Text = "Global ICMP Hijack"; - this.ICMPRedirectorCheckBox.UseVisualStyleBackColor = true; + this.ICMPHijackCheckBox.AutoSize = true; + this.ICMPHijackCheckBox.Enabled = false; + this.ICMPHijackCheckBox.Location = new System.Drawing.Point(6, 81); + this.ICMPHijackCheckBox.Name = "ICMPHijackCheckBox"; + this.ICMPHijackCheckBox.Size = new System.Drawing.Size(139, 21); + this.ICMPHijackCheckBox.TabIndex = 5; + this.ICMPHijackCheckBox.Text = "Global ICMP Hijack"; + this.ICMPHijackCheckBox.UseVisualStyleBackColor = true; // - // ModifiedICMPTextBox + // ICMPHijackHostTextBox // - this.ModifiedICMPTextBox.DataBindings.Add(new System.Windows.Forms.Binding("Enabled", this.ICMPRedirectorCheckBox, "Checked", true)); - this.ModifiedICMPTextBox.Location = new System.Drawing.Point(253, 78); - this.ModifiedICMPTextBox.Name = "ModifiedICMPTextBox"; - this.ModifiedICMPTextBox.Size = new System.Drawing.Size(191, 23); - this.ModifiedICMPTextBox.TabIndex = 7; - this.ModifiedICMPTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.ICMPHijackHostTextBox.DataBindings.Add(new System.Windows.Forms.Binding("Enabled", this.ICMPHijackCheckBox, "Checked", true)); + this.ICMPHijackHostTextBox.Enabled = false; + this.ICMPHijackHostTextBox.Location = new System.Drawing.Point(253, 78); + this.ICMPHijackHostTextBox.Name = "ICMPHijackHostTextBox"; + this.ICMPHijackHostTextBox.Size = new System.Drawing.Size(191, 23); + this.ICMPHijackHostTextBox.TabIndex = 7; + this.ICMPHijackHostTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // // RedirectorSSCheckBox // @@ -469,6 +450,7 @@ namespace Netch.Forms // ChildProcessHandleCheckBox // this.ChildProcessHandleCheckBox.AutoSize = true; + this.ChildProcessHandleCheckBox.Enabled = false; this.ChildProcessHandleCheckBox.Location = new System.Drawing.Point(11, 151); this.ChildProcessHandleCheckBox.Name = "ChildProcessHandleCheckBox"; this.ChildProcessHandleCheckBox.Size = new System.Drawing.Size(150, 21); @@ -1029,8 +1011,6 @@ namespace Netch.Forms private System.Windows.Forms.TabPage TAPTabPage; private System.Windows.Forms.TabPage v2rayTabPage; private System.Windows.Forms.GroupBox PortGroupBox; - private System.Windows.Forms.Label RedirectorLabel; - private System.Windows.Forms.TextBox RedirectorTextBox; private System.Windows.Forms.CheckBox AllowDevicesCheckBox; private System.Windows.Forms.Label HTTPPortLabel; private System.Windows.Forms.TextBox HTTPPortTextBox; @@ -1049,7 +1029,7 @@ namespace Netch.Forms private System.Windows.Forms.Label TUNTAPAddressLabel; private System.Windows.Forms.TextBox TUNTAPAddressTextBox; private System.Windows.Forms.Button GlobalBypassIPsButton; - private System.Windows.Forms.CheckBox DNSRedirectorCheckBox; + private System.Windows.Forms.CheckBox DNSHijackCheckBox; private System.Windows.Forms.Button ControlButton; private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; private System.Windows.Forms.TabPage OtherTabPage; @@ -1093,16 +1073,16 @@ namespace Netch.Forms private System.Windows.Forms.Label ChinaDNSLabel; private System.Windows.Forms.TextBox OtherDNSTextBox; private System.Windows.Forms.TextBox ChinaDNSTextBox; - private System.Windows.Forms.TextBox RDRDNSTextBox; + private System.Windows.Forms.TextBox DNSHijackHostTextBox; private System.Windows.Forms.CheckBox RedirectorSSCheckBox; private System.Windows.Forms.Label ServerPingTypeLabel; private System.Windows.Forms.RadioButton TCPingRadioBtn; private System.Windows.Forms.RadioButton ICMPingRadioBtn; private System.Windows.Forms.ComboBox ProcessProxyProtocolComboBox; private System.Windows.Forms.Label ProcessProxyProtocolLabel; - private System.Windows.Forms.CheckBox ICMPRedirectorCheckBox; - private System.Windows.Forms.TextBox ModifiedICMPTextBox; + private System.Windows.Forms.CheckBox ICMPHijackCheckBox; private System.Windows.Forms.CheckBox ChildProcessHandleCheckBox; private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.TextBox ICMPHijackHostTextBox; } } \ No newline at end of file diff --git a/Netch/Forms/SettingForm.cs b/Netch/Forms/SettingForm.cs index 4c4213c8..a8504505 100644 --- a/Netch/Forms/SettingForm.cs +++ b/Netch/Forms/SettingForm.cs @@ -26,20 +26,15 @@ namespace Netch.Forms #region General BindTextBox(Socks5PortTextBox, - p => p.ToString() != HTTPPortTextBox.Text && p.ToString() != RedirectorTextBox.Text, + p => p.ToString() != HTTPPortTextBox.Text, p => Global.Settings.Socks5LocalPort = p, Global.Settings.Socks5LocalPort); BindTextBox(HTTPPortTextBox, - p => p.ToString() != Socks5PortTextBox.Text && p.ToString() != RedirectorTextBox.Text, + p => p.ToString() != Socks5PortTextBox.Text, p => Global.Settings.HTTPLocalPort = p, Global.Settings.HTTPLocalPort); - BindTextBox(RedirectorTextBox, - p => p.ToString() != Socks5PortTextBox.Text && p.ToString() != HTTPPortTextBox.Text, - p => Global.Settings.RedirectorTCPPort = p, - Global.Settings.RedirectorTCPPort); - BindCheckBox(AllowDevicesCheckBox, c => Global.Settings.LocalAddress = AllowDevicesCheckBox.Checked ? "0.0.0.0" : "127.0.0.1", Global.Settings.LocalAddress switch {"127.0.0.1" => false, "0.0.0.0" => true, _ => false}); @@ -103,28 +98,27 @@ namespace Netch.Forms #region Process Mode - BindCheckBox(DNSRedirectorCheckBox, b => Global.Settings.RedirectDNS = b, Global.Settings.RedirectDNS); + BindCheckBox(DNSHijackCheckBox, b => Global.Settings.Redirector.DNSHijack = b, Global.Settings.Redirector.DNSHijack); - BindTextBox(RDRDNSTextBox, - s => DnsUtils.TrySplit(s, out _, 2), - s => Global.Settings.RedirectDNSAddr = s, - Global.Settings.RedirectDNSAddr); + BindTextBox(DNSHijackHostTextBox, s => true, s => Global.Settings.Redirector.DNSHijackHost = s, Global.Settings.Redirector.DNSHijackHost); - BindCheckBox(ICMPRedirectorCheckBox, b => Global.Settings.RedirectICMP = b, Global.Settings.RedirectICMP); + BindCheckBox(ICMPHijackCheckBox, b => Global.Settings.Redirector.ICMPHijack = b, Global.Settings.Redirector.ICMPHijack); - BindTextBox(ModifiedICMPTextBox, - s => DnsUtils.TrySplit(s, out _, 2), - s => Global.Settings.RedirectICMPAddr = s, - Global.Settings.RedirectICMPAddr); + BindTextBox(ICMPHijackHostTextBox, + s => IPAddress.TryParse(s, out _), + s => Global.Settings.Redirector.ICMPHost = s, + Global.Settings.Redirector.ICMPHost); - BindCheckBox(RedirectorSSCheckBox, s => Global.Settings.RedirectorSS = s, Global.Settings.RedirectorSS); + BindCheckBox(RedirectorSSCheckBox, s => Global.Settings.Redirector.RedirectorSS = s, Global.Settings.Redirector.RedirectorSS); - BindCheckBox(ChildProcessHandleCheckBox, s => Global.Settings.ChildProcessHandle = s, Global.Settings.ChildProcessHandle); + BindCheckBox(ChildProcessHandleCheckBox, + s => Global.Settings.Redirector.ChildProcessHandle = s, + Global.Settings.Redirector.ChildProcessHandle); BindListComboBox(ProcessProxyProtocolComboBox, - s => Global.Settings.ProcessProxyProtocol = (PortType) Enum.Parse(typeof(PortType), s.ToString(), false), + s => Global.Settings.Redirector.ProxyProtocol = (PortType) Enum.Parse(typeof(PortType), s.ToString(), false), Enum.GetNames(typeof(PortType)), - Global.Settings.ProcessProxyProtocol.ToString()); + Global.Settings.Redirector.ProxyProtocol.ToString()); #endregion diff --git a/Netch/Interops/RedirectorInterop.cs b/Netch/Interops/RedirectorInterop.cs index 6051ca2c..aa60bad4 100644 --- a/Netch/Interops/RedirectorInterop.cs +++ b/Netch/Interops/RedirectorInterop.cs @@ -7,12 +7,13 @@ namespace Netch.Interops { public enum NameList { - //bool - TYPE_FILTERLOOPBACK, - TYPE_FILTERTCP, - TYPE_FILTERUDP, - TYPE_FILTERIP, - TYPE_FILTERCHILDPROC, //子进程捕获 + TYPE_FILTLOP, + TYPE_FILTTCP, + TYPE_FILTUDP, + TYPE_CLRNAME, + TYPE_ADDNAME, + TYPE_BYPNAME, + TYPE_DNSHOST, TYPE_TCPLISN, TYPE_TCPTYPE, @@ -20,24 +21,21 @@ namespace Netch.Interops TYPE_TCPUSER, TYPE_TCPPASS, TYPE_TCPMETH, + TYPE_TCPPROT, + TYPE_TCPPRPA, + TYPE_TCPOBFS, + TYPE_TCPOBPA, + TYPE_UDPLISN, TYPE_UDPTYPE, TYPE_UDPHOST, TYPE_UDPUSER, TYPE_UDPPASS, TYPE_UDPMETH, - - TYPE_ADDNAME, - TYPE_ADDFIP, - - TYPE_BYPNAME, - - TYPE_CLRNAME, - TYPE_CLRFIP, - - //str addr x.x.x.x only ipv4 - TYPE_REDIRCTOR_DNS, - TYPE_REDIRCTOR_ICMP + TYPE_UDPPROT, + TYPE_UDPPRPA, + TYPE_UDPOBFS, + TYPE_UDPOBPA } public static bool Dial(NameList name, string value) @@ -56,7 +54,7 @@ namespace Netch.Interops return aio_free(); } - public const int UdpNameListOffset = (int) NameList.TYPE_UDPTYPE - (int) NameList.TYPE_TCPTYPE; + public const int UdpNameListOffset = (int) NameList.TYPE_UDPLISN - (int) NameList.TYPE_TCPLISN; private const string Redirector_bin = "Redirector.bin"; diff --git a/Netch/Models/Setting.cs b/Netch/Models/Setting.cs index de8adaea..b3baee81 100644 --- a/Netch/Models/Setting.cs +++ b/Netch/Models/Setting.cs @@ -37,6 +37,11 @@ namespace Netch.Models /// 使用自定义 DNS 设置 /// public bool UseCustomDNS { get; set; } = true; + + /// + /// 全局绕过 IP 列表 + /// + public List BypassIPs { get; set; } = new(); } public class KcpConfig @@ -80,11 +85,45 @@ namespace Netch.Models public string RulePath { get; set; } = "bin\\aiodns.conf"; } + public class RedirectorConfig + { + /// + /// 不代理TCP + /// + public PortType ProxyProtocol { get; set; } = PortType.Both; + + /// + /// 是否开启DNS转发 + /// + public bool DNSHijack { get; set; } = true; + + /// + /// 转发DNS地址 + /// + public string DNSHijackHost { get; set; } = "1.1.1.1:53"; + + public string ICMPHost { get; set; } = "1.2.4.8"; + + public bool ICMPHijack { get; set; } = false; + + /// + /// 是否使用RDR内置SS + /// + public bool RedirectorSS { get; set; } = false; + + /// + /// 是否代理子进程 + /// + public bool ChildProcessHandle { get; set; } = false; + } + /// /// 用于读取和写入的配置的类 /// public class Setting { + public RedirectorConfig Redirector { get; set; } = new(); + /// /// 服务器列表 /// @@ -92,11 +131,6 @@ namespace Netch.Models public AioDNSConfig AioDNS { get; set; } = new(); - /// - /// 全局绕过 IP 列表 - /// - public List BypassIPs { get; set; } = new(); - /// /// 是否检查 Beta 更新 /// @@ -142,31 +176,6 @@ namespace Netch.Models /// public int ModeComboBoxSelectedIndex { get; set; } = -1; - /// - /// 转发DNS地址 - /// - public string RedirectDNSAddr { get; set; } = "1.1.1.1"; - - /// - /// 是否开启DNS转发 - /// - public bool RedirectDNS { get; set; } = true; - - /// - /// 转发ICMP地址 - /// - public string RedirectICMPAddr { get; set; } = "1.2.4.8"; - - /// - /// 是否开启ICMP转发 - /// - public bool RedirectICMP { get; set; } = false; - - /// - /// 不代理TCP - /// - public PortType ProcessProxyProtocol { get; set; } = PortType.Both; - /// /// 快捷配置数量 /// @@ -182,21 +191,6 @@ namespace Netch.Models /// public byte ProfileTableColumnCount { get; set; } = 5; - /// - /// 是否使用RDR内置SS - /// - public bool RedirectorSS { get; set; } = true; - - /// - /// 是否代理子进程 - /// - public bool ChildProcessHandle { get; set; } = false; - - /// - /// Redirector TCP 占用端口 - /// - public ushort RedirectorTCPPort { get; set; } = 3901; - /// /// 网页请求超时 毫秒 /// diff --git a/Netch/Utils/ModeHelper.cs b/Netch/Utils/ModeHelper.cs index f4c78045..8523fe07 100644 --- a/Netch/Utils/ModeHelper.cs +++ b/Netch/Utils/ModeHelper.cs @@ -115,7 +115,7 @@ namespace Netch.Utils return server switch { Socks5 => true, - Shadowsocks shadowsocks when !shadowsocks.HasPlugin() && Global.Settings.RedirectorSS => true, + Shadowsocks shadowsocks when !shadowsocks.HasPlugin() && Global.Settings.Redirector.RedirectorSS => true, _ => false }; case 1: @@ -135,8 +135,6 @@ namespace Netch.Utils switch (type) { case 0: - port = Global.Settings.RedirectorTCPPort; - portName = "Redirector TCP"; return new NFController(); case 1: case 2: