This commit is contained in:
Amazing_DM
2020-05-05 09:27:16 +08:00
parent 23d0970ed3
commit 8140fba21e
8 changed files with 81 additions and 12 deletions

View File

@@ -1,7 +1,10 @@
using Netch.Forms;
using Netch.Utils;
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
namespace Netch.Controllers
@@ -27,11 +30,41 @@ namespace Netch.Controllers
public bool Start(Models.Server server, Models.Mode mode)
{
MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting Shadowsocks")}");
File.Delete("logging\\shadowsocks.log");
//从DLL启动Shaowsocks
if (Global.Settings.BootShadowsocksFromDLL)
{
State = Models.State.Starting;
var client = Encoding.UTF8.GetBytes($"0.0.0.0:{Global.Settings.Socks5LocalPort}");
var remote = Encoding.UTF8.GetBytes($"{server.Hostname}:{server.Port}");
var passwd = Encoding.UTF8.GetBytes($"{server.Password}");
var method = Encoding.UTF8.GetBytes($"{server.EncryptMethod}");
if (!NativeMethods.Shadowsocks.Info(client, remote, passwd, method))
{
State = Models.State.Stopped;
Logging.Info("DllSS_Info设置失败");
return false;
}
Logging.Info("DllSS_Info设置成功");
if (!NativeMethods.Shadowsocks.Start())
{
State = Models.State.Stopped;
Logging.Info("DllSS_Start 启动失败!");
return false;
}
Logging.Info("DllSS_Start 启动成功!");
State = Models.State.Started;
return true;
}
if (!File.Exists("bin\\Shadowsocks.exe"))
{
return false;
}
Instance = MainController.GetProcess();
Instance.StartInfo.FileName = "bin\\Shadowsocks.exe";
@@ -90,6 +123,8 @@ namespace Netch.Controllers
{
Instance.Kill();
}
if (Global.Settings.BootShadowsocksFromDLL)
NativeMethods.Shadowsocks.Stop();
}
catch (Exception e)
{
@@ -101,7 +136,7 @@ namespace Netch.Controllers
{
if (!string.IsNullOrWhiteSpace(e.Data))
{
// File.AppendAllText("logging\\shadowsocks.log", $"{e.Data}\r\n");
File.AppendAllText("logging\\shadowsocks.log", $"{e.Data}\r\n");
if (State == Models.State.Starting)
{

View File

@@ -27,6 +27,9 @@ namespace Netch.Controllers
public bool Start(Models.Server server, Models.Mode mode)
{
MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting ShadowsocksR")}");
File.Delete("logging\\shadowsocksr.log");
if (!File.Exists("bin\\ShadowsocksR.exe"))
{
return false;

View File

@@ -52,6 +52,7 @@
this.ControlButton = new System.Windows.Forms.Button();
this.GlobalBypassIPsButton = new System.Windows.Forms.Button();
this.BehaviorGroupBox = new System.Windows.Forms.GroupBox();
this.BootShadowsocksFromDLLCheckBox = new System.Windows.Forms.CheckBox();
this.AclAddr = new System.Windows.Forms.TextBox();
this.AclLabel = new System.Windows.Forms.Label();
this.DetectionInterval_Label = new System.Windows.Forms.Label();
@@ -278,7 +279,7 @@
// ControlButton
//
this.ControlButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.ControlButton.Location = new System.Drawing.Point(781, 356);
this.ControlButton.Location = new System.Drawing.Point(804, 356);
this.ControlButton.Name = "ControlButton";
this.ControlButton.Size = new System.Drawing.Size(75, 23);
this.ControlButton.TabIndex = 11;
@@ -299,6 +300,7 @@
//
// BehaviorGroupBox
//
this.BehaviorGroupBox.Controls.Add(this.BootShadowsocksFromDLLCheckBox);
this.BehaviorGroupBox.Controls.Add(this.AclAddr);
this.BehaviorGroupBox.Controls.Add(this.AclLabel);
this.BehaviorGroupBox.Controls.Add(this.DetectionInterval_Label);
@@ -322,16 +324,26 @@
this.BehaviorGroupBox.Controls.Add(this.ExitWhenClosedCheckBox);
this.BehaviorGroupBox.Location = new System.Drawing.Point(438, 12);
this.BehaviorGroupBox.Name = "BehaviorGroupBox";
this.BehaviorGroupBox.Size = new System.Drawing.Size(420, 333);
this.BehaviorGroupBox.Size = new System.Drawing.Size(441, 333);
this.BehaviorGroupBox.TabIndex = 8;
this.BehaviorGroupBox.TabStop = false;
this.BehaviorGroupBox.Text = "Behavior";
//
// BootShadowsocksFromDLLCheckBox
//
this.BootShadowsocksFromDLLCheckBox.AutoSize = true;
this.BootShadowsocksFromDLLCheckBox.Location = new System.Drawing.Point(206, 102);
this.BootShadowsocksFromDLLCheckBox.Name = "BootShadowsocksFromDLLCheckBox";
this.BootShadowsocksFromDLLCheckBox.Size = new System.Drawing.Size(195, 21);
this.BootShadowsocksFromDLLCheckBox.TabIndex = 21;
this.BootShadowsocksFromDLLCheckBox.Text = "Boot Shadowsocks from DLL";
this.BootShadowsocksFromDLLCheckBox.UseVisualStyleBackColor = true;
//
// AclAddr
//
this.AclAddr.Location = new System.Drawing.Point(120, 258);
this.AclAddr.Name = "AclAddr";
this.AclAddr.Size = new System.Drawing.Size(294, 23);
this.AclAddr.Size = new System.Drawing.Size(315, 23);
this.AclAddr.TabIndex = 19;
this.AclAddr.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
@@ -357,7 +369,7 @@
//
this.DetectionInterval_TextBox.Location = new System.Drawing.Point(367, 174);
this.DetectionInterval_TextBox.Name = "DetectionInterval_TextBox";
this.DetectionInterval_TextBox.Size = new System.Drawing.Size(47, 23);
this.DetectionInterval_TextBox.Size = new System.Drawing.Size(68, 23);
this.DetectionInterval_TextBox.TabIndex = 17;
this.DetectionInterval_TextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
@@ -414,7 +426,7 @@
//
this.STUN_ServerPortTextBox.Location = new System.Drawing.Point(120, 229);
this.STUN_ServerPortTextBox.Name = "STUN_ServerPortTextBox";
this.STUN_ServerPortTextBox.Size = new System.Drawing.Size(294, 23);
this.STUN_ServerPortTextBox.Size = new System.Drawing.Size(315, 23);
this.STUN_ServerPortTextBox.TabIndex = 8;
this.STUN_ServerPortTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
@@ -450,7 +462,7 @@
//
this.STUN_ServerTextBox.Location = new System.Drawing.Point(120, 200);
this.STUN_ServerTextBox.Name = "STUN_ServerTextBox";
this.STUN_ServerTextBox.Size = new System.Drawing.Size(294, 23);
this.STUN_ServerTextBox.Size = new System.Drawing.Size(315, 23);
this.STUN_ServerTextBox.TabIndex = 11;
this.STUN_ServerTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
@@ -477,7 +489,7 @@
//
this.ProfileCount_TextBox.Location = new System.Drawing.Point(209, 149);
this.ProfileCount_TextBox.Name = "ProfileCount_TextBox";
this.ProfileCount_TextBox.Size = new System.Drawing.Size(208, 23);
this.ProfileCount_TextBox.Size = new System.Drawing.Size(226, 23);
this.ProfileCount_TextBox.TabIndex = 9;
this.ProfileCount_TextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
@@ -529,7 +541,7 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.ClientSize = new System.Drawing.Size(868, 390);
this.ClientSize = new System.Drawing.Size(891, 390);
this.Controls.Add(this.BehaviorGroupBox);
this.Controls.Add(this.PortGroupBox);
this.Controls.Add(this.GlobalBypassIPsButton);
@@ -601,5 +613,6 @@
private System.Windows.Forms.TextBox AclAddr;
private System.Windows.Forms.Label AclLabel;
private System.Windows.Forms.CheckBox UseFakeDNSCheckBox;
private System.Windows.Forms.CheckBox BootShadowsocksFromDLLCheckBox;
}
}

View File

@@ -56,6 +56,7 @@ namespace Netch.Forms
GlobalBypassIPsButton.Text = Utils.i18N.Translate(GlobalBypassIPsButton.Text);
ControlButton.Text = Utils.i18N.Translate(ControlButton.Text);
BypassModeCheckBox.Text = Utils.i18N.Translate(BypassModeCheckBox.Text);
BootShadowsocksFromDLLCheckBox.Text = Utils.i18N.Translate(BootShadowsocksFromDLLCheckBox.Text);
ExitWhenClosedCheckBox.Checked = Global.Settings.ExitWhenClosed;
StopWhenExitedCheckBox.Checked = Global.Settings.StopWhenExited;
@@ -67,6 +68,7 @@ namespace Netch.Forms
BypassModeCheckBox.Checked = Global.Settings.ProcessBypassMode;
EnableStartedTcping_CheckBox.Checked = Global.Settings.StartedTcping;
DetectionInterval_TextBox.Text = Global.Settings.StartedTcping_Interval.ToString();
BootShadowsocksFromDLLCheckBox.Checked = Global.Settings.BootShadowsocksFromDLL;
Socks5PortTextBox.Text = Global.Settings.Socks5LocalPort.ToString();
HTTPPortTextBox.Text = Global.Settings.HTTPLocalPort.ToString();
@@ -161,7 +163,8 @@ namespace Netch.Forms
Global.Settings.RunAtStartup = RunAtStartup.Checked;
Global.Settings.UseRedirector2 = Redirector2checkBox.Checked;
Global.Settings.ProcessBypassMode = BypassModeCheckBox.Checked;
Global.Settings.StartedTcping = EnableStartedTcping_CheckBox.Checked;
Global.Settings.BootShadowsocksFromDLL = BootShadowsocksFromDLLCheckBox.Checked;
// 开机自启判断
TaskSchedulerClass scheduler = new TaskSchedulerClass();

View File

@@ -184,5 +184,9 @@ namespace Netch.Models
/// </summary>
public string ACL = "https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/banAD.acl";
/// <summary>
/// 是否使用DLL启动Shadowsocks
/// </summary>
public bool BootShadowsocksFromDLL = true;
}
}

View File

@@ -63,5 +63,15 @@ namespace Netch
/// <returns>是否成功</returns>
[DllImport("bin\\sysproxy", CallingConvention = CallingConvention.Cdecl)]
public static extern bool SetURL([MarshalAs(UnmanagedType.LPTStr)] string remote);
public class Shadowsocks
{
[DllImport("bin\\shadowsocks-windows-dynamic", CallingConvention = CallingConvention.Cdecl)]
public static extern bool Info(byte[] client, byte[] remote, byte[] passwd, byte[] method);
[DllImport("bin\\shadowsocks-windows-dynamic", CallingConvention = CallingConvention.Cdecl)]
public static extern bool Start();
[DllImport("bin\\shadowsocks-windows-dynamic", CallingConvention = CallingConvention.Cdecl)]
public static extern void Stop();
}
}
}

View File

@@ -173,6 +173,7 @@
"Detection interval(/s)": "检测间隔(/秒)",
"Custom ACL": "自定义 ACL 规则",
"Process whitelist mode": "进程白名单模式",
"Boot Shadowsocks from DLL": "从DLL启动SS快速启动,推荐使用)",
"Profile": "配置名",
"Profiles": "配置",