diff --git a/Netch/Controllers/Guard.cs b/Netch/Controllers/Guard.cs index 06cdf93b08..bd999de8fe 100644 --- a/Netch/Controllers/Guard.cs +++ b/Netch/Controllers/Guard.cs @@ -164,7 +164,7 @@ protected void StartInstanceAuto(string argument, ProcessPriorityClass priority switch (State) { case State.Started: - OnKeywordStarted(); + Task.Run(OnKeywordStarted); return; case State.Stopped: Stop(); diff --git a/Netch/Controllers/PcapController.cs b/Netch/Controllers/PcapController.cs new file mode 100644 index 0000000000..1f791493ac --- /dev/null +++ b/Netch/Controllers/PcapController.cs @@ -0,0 +1,55 @@ +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Netch.Models; + +namespace Netch.Controllers +{ + public class PcapController : Guard, IModeController + { + public override string Name { get; } = "pcap2socks"; + + public override string MainFile { get; protected set; } = "pcap2socks.exe"; + + protected override IEnumerable StartedKeywords { get; } = new[] {"└"}; + + private readonly OutboundAdapter _outbound = new(); + + protected override Encoding? InstanceOutputEncoding { get; } = Encoding.UTF8; + + public void Start(in Mode mode) + { + StartInstanceAuto($@"-i \Device\NPF_{_outbound.NetworkInterface.Id} {mode.FullRule.FirstOrDefault() ?? "-P n"}"); + } + + protected override void OnKeywordStarted() + { + Thread.Sleep(300); + Utils.Utils.Open(LogPath); + } + + protected override void OnKeywordStopped() + { + if (File.ReadAllText(LogPath).Length == 0) + { + Task.Run(() => + { + Thread.Sleep(1000); + Utils.Utils.Open("https://github.com/zhxie/pcap2socks#dependencies"); + }); + + throw new MessageException("Pleases install pcap2socks's dependency"); + } + + Utils.Utils.Open(LogPath); + } + + public override void Stop() + { + StopInstance(); + } + } +} \ No newline at end of file diff --git a/Netch/Utils/ModeHelper.cs b/Netch/Utils/ModeHelper.cs index 77eed66972..da300012f6 100644 --- a/Netch/Utils/ModeHelper.cs +++ b/Netch/Utils/ModeHelper.cs @@ -165,6 +165,8 @@ public static bool SkipServerController(Server server, Mode mode) return new HTTPController(); case 4: return null; + case 6: + return new PcapController(); default: Logging.Error("未知模式类型"); throw new MessageException("未知模式类型"); diff --git a/binaries b/binaries index 3b545ea849..f9e9be00ae 160000 --- a/binaries +++ b/binaries @@ -1 +1 @@ -Subproject commit 3b545ea849453d8196e75907f261f043b61fd3d8 +Subproject commit f9e9be00ae7f8f1d688c7b7d7a2fc2bfc31a9559 diff --git a/modes b/modes index 13886adee6..5f346056a0 160000 --- a/modes +++ b/modes @@ -1 +1 @@ -Subproject commit 13886adee6bf92661aac33ffc856ade562f619b1 +Subproject commit 5f346056a04c862d41b8a0d0b62d7abe42a32c40