From 5a9d6e145dad771a957716d83cae7057acaa1846 Mon Sep 17 00:00:00 2001 From: ChsBuffer <33744752+chsbuffer@users.noreply.github.com> Date: Thu, 11 Mar 2021 13:02:36 +0800 Subject: [PATCH] Cut SS DLL --- Netch/Forms/SettingForm.Designer.cs | 21 ++-------- Netch/Forms/SettingForm.cs | 1 - Netch/Models/Setting.cs | 5 --- Netch/Servers/Shadowsocks/SSController.cs | 48 ----------------------- Netch/Utils/Bandwidth.cs | 3 -- binaries | 2 +- 6 files changed, 5 insertions(+), 75 deletions(-) diff --git a/Netch/Forms/SettingForm.Designer.cs b/Netch/Forms/SettingForm.Designer.cs index 8c37c7d6..93342a0e 100644 --- a/Netch/Forms/SettingForm.Designer.cs +++ b/Netch/Forms/SettingForm.Designer.cs @@ -44,7 +44,6 @@ namespace Netch.Forms this.RedirectorLabel = new System.Windows.Forms.Label(); this.RedirectorTextBox = new System.Windows.Forms.TextBox(); this.AllowDevicesCheckBox = new System.Windows.Forms.CheckBox(); - this.BootShadowsocksFromDLLCheckBox = new System.Windows.Forms.CheckBox(); this.ResolveServerHostnameCheckBox = new System.Windows.Forms.CheckBox(); this.ProfileCountLabel = new System.Windows.Forms.Label(); this.ProfileCountTextBox = new System.Windows.Forms.TextBox(); @@ -156,7 +155,6 @@ namespace Netch.Forms this.GeneralTabPage.Controls.Add(this.TCPingRadioBtn); this.GeneralTabPage.Controls.Add(this.ICMPingRadioBtn); this.GeneralTabPage.Controls.Add(this.PortGroupBox); - this.GeneralTabPage.Controls.Add(this.BootShadowsocksFromDLLCheckBox); this.GeneralTabPage.Controls.Add(this.ResolveServerHostnameCheckBox); this.GeneralTabPage.Controls.Add(this.ProfileCountLabel); this.GeneralTabPage.Controls.Add(this.ProfileCountTextBox); @@ -180,7 +178,7 @@ namespace Netch.Forms // ServerPingTypeLabel // this.ServerPingTypeLabel.AutoSize = true; - this.ServerPingTypeLabel.Location = new System.Drawing.Point(267, 66); + this.ServerPingTypeLabel.Location = new System.Drawing.Point(267, 44); this.ServerPingTypeLabel.Name = "ServerPingTypeLabel"; this.ServerPingTypeLabel.Size = new System.Drawing.Size(89, 12); this.ServerPingTypeLabel.TabIndex = 16; @@ -189,7 +187,7 @@ namespace Netch.Forms // TCPingRadioBtn // this.TCPingRadioBtn.AutoSize = true; - this.TCPingRadioBtn.Location = new System.Drawing.Point(332, 85); + this.TCPingRadioBtn.Location = new System.Drawing.Point(332, 63); this.TCPingRadioBtn.Name = "TCPingRadioBtn"; this.TCPingRadioBtn.Size = new System.Drawing.Size(59, 16); this.TCPingRadioBtn.TabIndex = 15; @@ -200,7 +198,7 @@ namespace Netch.Forms // ICMPingRadioBtn // this.ICMPingRadioBtn.AutoSize = true; - this.ICMPingRadioBtn.Location = new System.Drawing.Point(268, 85); + this.ICMPingRadioBtn.Location = new System.Drawing.Point(268, 63); this.ICMPingRadioBtn.Name = "ICMPingRadioBtn"; this.ICMPingRadioBtn.Size = new System.Drawing.Size(65, 16); this.ICMPingRadioBtn.TabIndex = 14; @@ -286,20 +284,10 @@ namespace Netch.Forms this.AllowDevicesCheckBox.TextAlign = System.Drawing.ContentAlignment.MiddleRight; this.AllowDevicesCheckBox.UseVisualStyleBackColor = true; // - // BootShadowsocksFromDLLCheckBox - // - this.BootShadowsocksFromDLLCheckBox.AutoSize = true; - this.BootShadowsocksFromDLLCheckBox.Location = new System.Drawing.Point(267, 15); - this.BootShadowsocksFromDLLCheckBox.Name = "BootShadowsocksFromDLLCheckBox"; - this.BootShadowsocksFromDLLCheckBox.Size = new System.Drawing.Size(60, 16); - this.BootShadowsocksFromDLLCheckBox.TabIndex = 1; - this.BootShadowsocksFromDLLCheckBox.Text = "SS DLL"; - this.BootShadowsocksFromDLLCheckBox.UseVisualStyleBackColor = true; - // // ResolveServerHostnameCheckBox // this.ResolveServerHostnameCheckBox.AutoSize = true; - this.ResolveServerHostnameCheckBox.Location = new System.Drawing.Point(267, 37); + this.ResolveServerHostnameCheckBox.Location = new System.Drawing.Point(267, 15); this.ResolveServerHostnameCheckBox.Name = "ResolveServerHostnameCheckBox"; this.ResolveServerHostnameCheckBox.Size = new System.Drawing.Size(162, 16); this.ResolveServerHostnameCheckBox.TabIndex = 2; @@ -1106,7 +1094,6 @@ namespace Netch.Forms private System.Windows.Forms.Label Socks5PortLabel; private System.Windows.Forms.TextBox Socks5PortTextBox; private System.Windows.Forms.CheckBox ResolveServerHostnameCheckBox; - private System.Windows.Forms.CheckBox BootShadowsocksFromDLLCheckBox; private System.Windows.Forms.GroupBox TUNTAPGroupBox; private System.Windows.Forms.CheckBox UseFakeDNSCheckBox; private System.Windows.Forms.CheckBox ProxyDNSCheckBox; diff --git a/Netch/Forms/SettingForm.cs b/Netch/Forms/SettingForm.cs index e1596c92..8aac6c89 100644 --- a/Netch/Forms/SettingForm.cs +++ b/Netch/Forms/SettingForm.cs @@ -44,7 +44,6 @@ namespace Netch.Forms 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}); - BindCheckBox(BootShadowsocksFromDLLCheckBox, c => Global.Settings.BootShadowsocksFromDLL = c, Global.Settings.BootShadowsocksFromDLL); BindCheckBox(ResolveServerHostnameCheckBox, c => Global.Settings.ResolveServerHostname = c, Global.Settings.ResolveServerHostname); BindRadioBox(ICMPingRadioBtn, _ => { }, !Global.Settings.ServerTCPing); diff --git a/Netch/Models/Setting.cs b/Netch/Models/Setting.cs index 5a7a83f8..45840f38 100644 --- a/Netch/Models/Setting.cs +++ b/Netch/Models/Setting.cs @@ -102,11 +102,6 @@ namespace Netch.Models public AioDNSConfig AioDNS { get; set; } = new(); - /// - /// 是否使用DLL启动Shadowsocks - /// - public bool BootShadowsocksFromDLL { get; set; } = true; - /// /// 全局绕过 IP 列表 /// diff --git a/Netch/Servers/Shadowsocks/SSController.cs b/Netch/Servers/Shadowsocks/SSController.cs index 0a8092e1..d1c535cd 100644 --- a/Netch/Servers/Shadowsocks/SSController.cs +++ b/Netch/Servers/Shadowsocks/SSController.cs @@ -1,17 +1,13 @@ using System.Collections.Generic; using System.IO; -using System.Runtime.InteropServices; using System.Text; using Netch.Controllers; using Netch.Models; -using Netch.Utils; namespace Netch.Servers.Shadowsocks { public class SSController : Guard, IServerController { - public bool DllFlag; - public override string MainFile { get; protected set; } = "Shadowsocks.exe"; protected override IEnumerable StartedKeywords { get; } = new[] {"listening at"}; @@ -28,35 +24,6 @@ namespace Netch.Servers.Shadowsocks { var server = (Shadowsocks) s; - DllFlag = Global.Settings.BootShadowsocksFromDLL && mode.Type is 0 or 1 or 2 && !server.HasPlugin(); - - //从DLL启动Shaowsocks - if (DllFlag) - { - State = State.Starting; - var client = Encoding.UTF8.GetBytes($"{this.LocalAddress()}:{this.Socks5LocalPort()}"); - var remote = Encoding.UTF8.GetBytes($"{server.AutoResolveHostname()}:{server.Port}"); - var passwd = Encoding.UTF8.GetBytes($"{server.Password}"); - var method = Encoding.UTF8.GetBytes($"{server.EncryptMethod}"); - if (!ShadowsocksDLL.Info(client, remote, passwd, method)) - { - State = State.Stopped; - throw new MessageException("DLL SS INFO 设置失败!"); - } - - Logging.Info("DLL SS INFO 设置成功!"); - - if (!ShadowsocksDLL.Start()) - { - State = State.Stopped; - throw new MessageException("DLL SS 启动失败!"); - } - - Logging.Info("DLL SS 启动成功!"); - State = State.Started; - return; - } - #region Argument var argument = new StringBuilder(); @@ -76,22 +43,7 @@ namespace Netch.Servers.Shadowsocks public override void Stop() { - if (DllFlag) - ShadowsocksDLL.Stop(); - else StopInstance(); } - - private class ShadowsocksDLL - { - [DllImport("shadowsocks-windows-dynamic", CallingConvention = CallingConvention.Cdecl)] - public static extern bool Info(byte[] client, byte[] remote, byte[] passwd, byte[] method); - - [DllImport("shadowsocks-windows-dynamic", CallingConvention = CallingConvention.Cdecl)] - public static extern bool Start(); - - [DllImport("shadowsocks-windows-dynamic", CallingConvention = CallingConvention.Cdecl)] - public static extern void Stop(); - } } } \ No newline at end of file diff --git a/Netch/Utils/Bandwidth.cs b/Netch/Utils/Bandwidth.cs index ade5c7a9..3c86c728 100644 --- a/Netch/Utils/Bandwidth.cs +++ b/Netch/Utils/Bandwidth.cs @@ -57,9 +57,6 @@ namespace Netch.Utils { case null: break; - case SSController {DllFlag: true}: - instances.Add(Process.GetCurrentProcess()); - break; case Guard instanceController: if (instanceController.Instance != null) instances.Add(instanceController.Instance); diff --git a/binaries b/binaries index 17865998..61b435e2 160000 --- a/binaries +++ b/binaries @@ -1 +1 @@ -Subproject commit 1786599872891a9214a671e7c4f3d5832ce29dde +Subproject commit 61b435e28cac8bb495131a1a9fe31e262c61d6b8