diff --git a/Netch/Controllers/Mode/NFController.cs b/Netch/Controllers/Mode/NFController.cs index 3341deb1..238ac3ab 100644 --- a/Netch/Controllers/Mode/NFController.cs +++ b/Netch/Controllers/Mode/NFController.cs @@ -41,6 +41,11 @@ namespace Netch.Controllers BinDriver = "bin\\" + BinDriver; } + public NFController() + { + Name = "Redirector"; + } + public override bool Start(Server server, Mode mode) { Logging.Info("内置驱动版本: " + DriverVersion(BinDriver)); @@ -57,26 +62,35 @@ namespace Netch.Controllers return false; } - NativeMethods.aio_dial((int)NameList.TYPE_CLRNAME, ""); + NativeMethods.aio_dial((int) NameList.TYPE_CLRNAME, ""); foreach (var rule in mode.Rule) { - NativeMethods.aio_dial((int)NameList.TYPE_ADDNAME, rule); + NativeMethods.aio_dial((int) NameList.TYPE_ADDNAME, rule); } + NativeMethods.aio_dial((int) NameList.TYPE_ADDNAME, "NTT.exe"); - var result = DNS.Lookup(server.Hostname); - if (result == null) + if (!MainController.IsSocks5Server) { - Logging.Info("无法解析服务器 IP 地址"); - return false; + NativeMethods.aio_dial((int) NameList.TYPE_TCPHOST, $"127.0.0.01:{MainController.Socks5Port}"); + NativeMethods.aio_dial((int) NameList.TYPE_UDPHOST, $"127.0.0.01:{MainController.Socks5Port}"); + } + else + { + var result = DNS.Lookup(server.Hostname); + if (result == null) + { + Logging.Info("无法解析服务器 IP 地址"); + return false; + } + NativeMethods.aio_dial((int) NameList.TYPE_TCPHOST, $"{result}:{server.Port}"); + NativeMethods.aio_dial((int) NameList.TYPE_UDPHOST, $"{result}:{server.Port}"); } - NativeMethods.aio_dial((int)NameList.TYPE_TCPHOST, $"{result}:{server.Port}"); - NativeMethods.aio_dial((int)NameList.TYPE_UDPHOST, $"{result}:{server.Port}"); if (Global.Settings.ModifySystemDNS) { // 备份并替换系统 DNS _sysDns = DNS.getSystemDns(); - string[] dns = { "1.1.1.1", "8.8.8.8" }; + string[] dns = {"1.1.1.1", "8.8.8.8"}; DNS.SetDNS(dns); } diff --git a/Netch/NativeMethods.cs b/Netch/NativeMethods.cs index fd4847dc..368e7608 100644 --- a/Netch/NativeMethods.cs +++ b/Netch/NativeMethods.cs @@ -25,7 +25,7 @@ namespace Netch /// 适配器索引 /// 跃点数 /// 是否成功 - [DllImport("bin\\NetchCore", CallingConvention = CallingConvention.Cdecl, EntryPoint = "CreateRoute")] + [DllImport("NetchCore", CallingConvention = CallingConvention.Cdecl, EntryPoint = "CreateRoute")] public static extern bool CreateRoute(string address, int cidr, string gateway, int index, int metric = 0); /// @@ -37,14 +37,14 @@ namespace Netch /// 适配器索引 /// 跃点数 /// 是否成功 - [DllImport("bin\\NetchCore", CallingConvention = CallingConvention.Cdecl, EntryPoint = "DeleteRoute")] + [DllImport("NetchCore", CallingConvention = CallingConvention.Cdecl, EntryPoint = "DeleteRoute")] public static extern bool DeleteRoute(string address, int cidr, string gateway, int index, int metric = 0); /// /// 设置直连 /// /// 是否成功 - [DllImport("bin\\sysproxy", CallingConvention = CallingConvention.Cdecl)] + [DllImport("sysproxy", CallingConvention = CallingConvention.Cdecl)] public static extern bool SetDIRECT(); /// @@ -53,7 +53,7 @@ namespace Netch /// 地址 /// 绕过 /// 是否成功 - [DllImport("bin\\sysproxy", CallingConvention = CallingConvention.Cdecl)] + [DllImport("sysproxy", CallingConvention = CallingConvention.Cdecl)] public static extern bool SetGlobal([MarshalAs(UnmanagedType.LPTStr)] string remote, [MarshalAs(UnmanagedType.LPTStr)] string bypass); /// @@ -61,37 +61,37 @@ namespace Netch /// /// URL /// 是否成功 - [DllImport("bin\\sysproxy", CallingConvention = CallingConvention.Cdecl)] + [DllImport("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)] + [DllImport("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)] + [DllImport("shadowsocks-windows-dynamic", CallingConvention = CallingConvention.Cdecl)] public static extern bool Start(); - [DllImport("bin\\shadowsocks-windows-dynamic", CallingConvention = CallingConvention.Cdecl)] + [DllImport("shadowsocks-windows-dynamic", CallingConvention = CallingConvention.Cdecl)] public static extern void Stop(); } [DllImport("dnsapi", EntryPoint = "DnsFlushResolverCache")] public static extern uint FlushDNSResolverCache(); - [DllImport("bin\\Redirector.bin", CallingConvention = CallingConvention.Cdecl)] + [DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)] public static extern bool aio_dial(int name, [MarshalAs(UnmanagedType.LPWStr)] string value); - [DllImport("bin\\Redirector.bin", CallingConvention = CallingConvention.Cdecl)] + [DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)] public static extern bool aio_init(); - [DllImport("bin\\Redirector.bin", CallingConvention = CallingConvention.Cdecl)] + [DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)] public static extern bool aio_free(); - [DllImport("bin\\Redirector.bin", CallingConvention = CallingConvention.Cdecl)] + [DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)] public static extern ulong aio_getUP(); - [DllImport("bin\\Redirector.bin", CallingConvention = CallingConvention.Cdecl)] + [DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)] public static extern ulong aio_getDL(); } } \ No newline at end of file diff --git a/Netch/Netch.cs b/Netch/Netch.cs index bb4d5368..356ce15d 100644 --- a/Netch/Netch.cs +++ b/Netch/Netch.cs @@ -22,6 +22,7 @@ namespace Netch { // 设置当前目录 Directory.SetCurrentDirectory(Global.NetchDir); + Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Process) + ";" + Path.Combine(Global.NetchDir, "bin"), EnvironmentVariableTarget.Process); // 预创建目录 var directories = new[] {"mode", "data", "i18n", "logging"}; diff --git a/Netch/PostBuild.bat b/Netch/PostBuild.bat index c58db01d..c6f53711 100644 --- a/Netch/PostBuild.bat +++ b/Netch/PostBuild.bat @@ -35,7 +35,7 @@ XCOPY /s /Y %SolutionDir%binaries %TargetDir%bin\ >NUL XCOPY /s /Y %SolutionDir%translations\i18n %TargetDir%i18n\ >NUL XCOPY /s /Y %SolutionDir%modes\mode %TargetDir%mode\ >NUL -MOVE /Y %TargetDir%bin\Core.bin %TargetDir% >NUL +rem MOVE /Y %TargetDir%bin\Core.bin %TargetDir% >NUL DEL /f %TargetDir%*.config >NUL 2>&1 DEL /f %TargetDir%*.pdb >NUL 2>&1 diff --git a/binaries b/binaries index 79341341..9a740dd9 160000 --- a/binaries +++ b/binaries @@ -1 +1 @@ -Subproject commit 79341341c16dc65a3322ee7bc2efcd558d8ce575 +Subproject commit 9a740dd99c4f8fc48bedb19b3be6b75b6b671770