适配新Redirector

This commit is contained in:
ChsBuffer
2020-09-06 23:37:32 +08:00
parent 664cff4e52
commit c4f06eb45d
5 changed files with 39 additions and 24 deletions

View File

@@ -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);
}

View File

@@ -25,7 +25,7 @@ namespace Netch
/// <param name="index">适配器索引</param>
/// <param name="metric">跃点数</param>
/// <returns>是否成功</returns>
[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);
/// <summary>
@@ -37,14 +37,14 @@ namespace Netch
/// <param name="index">适配器索引</param>
/// <param name="metric">跃点数</param>
/// <returns>是否成功</returns>
[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);
/// <summary>
/// 设置直连
/// </summary>
/// <returns>是否成功</returns>
[DllImport("bin\\sysproxy", CallingConvention = CallingConvention.Cdecl)]
[DllImport("sysproxy", CallingConvention = CallingConvention.Cdecl)]
public static extern bool SetDIRECT();
/// <summary>
@@ -53,7 +53,7 @@ namespace Netch
/// <param name="remote">地址</param>
/// <param name="bypass">绕过</param>
/// <returns>是否成功</returns>
[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);
/// <summary>
@@ -61,37 +61,37 @@ namespace Netch
/// </summary>
/// <param name="remote">URL</param>
/// <returns>是否成功</returns>
[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();
}
}

View File

@@ -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"};

View File

@@ -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