diff --git a/.gitmodules b/.gitmodules index 75f53f31..0ab249d5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ [submodule "v2rayN/GlobalHotKeys"] path = v2rayN/GlobalHotKeys url = https://github.com/2dust/GlobalHotKeys -[submodule "v2rayN/NetBridge"] - path = v2rayN/NetBridge - url = https://github.com/2dust/NetBridge diff --git a/v2rayN/NetBridge b/v2rayN/NetBridge deleted file mode 160000 index e9b16cd1..00000000 --- a/v2rayN/NetBridge +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e9b16cd1871224c3413bdf43b4cf0ab46d4fb21e diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs index 5e5e30b5..636f65a7 100644 --- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs @@ -160,11 +160,7 @@ public static class ConfigHandler config.ClashUIItem.ConnectionsColumnItem ??= []; config.SystemProxyItem ??= new(); config.WebDavItem ??= new(); - config.CheckUpdateItem ??= new(); - config.NetBridgeItem ??= new() - { - RuleProcess = string.Empty - }; + config.CheckUpdateItem ??= new(); config.Fragment4RayItem ??= new() { Packets = "tlshello", diff --git a/v2rayN/ServiceLib/Manager/NetBridgeManager.cs b/v2rayN/ServiceLib/Manager/NetBridgeManager.cs deleted file mode 100644 index c4487201..00000000 --- a/v2rayN/ServiceLib/Manager/NetBridgeManager.cs +++ /dev/null @@ -1,239 +0,0 @@ -using NetBridgeLib.Services; - -namespace ServiceLib.Manager; - -public sealed class NetBridgeManager -{ - private static readonly Lazy _instance = new(() => new()); - public static NetBridgeManager Instance => _instance.Value; - private readonly Config _config = AppManager.Instance.Config; - private NetBridgeService? _netBridgeService; - private bool _isProxyRunning; - private bool _isInitialized; - private List _ruleConfigs = []; - private Func? _updateFunc; - private uint _proxyConfigId; - - public async Task Init(Func? updateFunc = null) - { - if (_isInitialized) - { - return; - } - - _updateFunc = updateFunc; - - try - { - _netBridgeService = new NetBridgeService(); - _netBridgeService.LogReceived += msg => - { - var message = $"NetBridge Log: {msg}"; - _ = _updateFunc?.Invoke(false, message); - }; - - _netBridgeService.ConnectionReceived += (processName, pid, destIp, destPort, proxyInfo) => - { - var message = $"NetBridge Connection: {processName} (PID: {pid}) -> {destIp}:{destPort} -> {proxyInfo}"; - _ = _updateFunc?.Invoke(false, message); - }; - - _ruleConfigs = BuildRuleConfigs(_config.NetBridgeItem?.RuleProcess); - _isInitialized = true; - } - catch (Exception ex) - { - var error = $"Failed to initialize NetBridgeService: {ex.Message}"; - await _updateFunc?.Invoke(true, error); - } - } - - public async Task Start() - { - if (_isProxyRunning) - { - return true; - } - - try - { - if (_netBridgeService == null) - { - return false; - } - - var started = _netBridgeService.Start(); - if (!started) - { - return false; - } - - _isProxyRunning = true; - } - catch (Exception ex) - { - var error = $"Failed to start NetBridgeService: {ex.Message}"; - await _updateFunc?.Invoke(true, error); - return false; - } - - return true; - } - - public async Task Stop() - { - if (!_isProxyRunning) - { - return true; - } - - try - { - if (_netBridgeService == null) - { - return false; - } - - var stopped = _netBridgeService.Stop(); - if (!stopped) - { - return false; - } - - _isProxyRunning = false; - } - catch (Exception ex) - { - var error = $"Failed to stop NetBridgeService: {ex.Message}"; - await _updateFunc?.Invoke(true, error); - return false; - } - - return true; - } - - public async Task UpdateRoutes(string? ruleProcess) - { - var newRuleConfigs = BuildRuleConfigs(ruleProcess); - - _ruleConfigs = newRuleConfigs; - - if (!_isProxyRunning) - { - return true; - } - - return await ApplyRoutesInternal(); - } - - public async Task UpdateProxyConfig(string proxyHost, int proxyPort) - { - try - { - if (_netBridgeService == null) - { - return false; - } - - var proxyType = "SOCKS5"; - var username = ""; - var password = ""; - - if (_proxyConfigId > 0) - { - var edited = _netBridgeService.EditProxyConfig(_proxyConfigId, proxyType, proxyHost, (ushort)proxyPort, username, password); - if (!edited) - { - return false; - } - } - else - { - _proxyConfigId = _netBridgeService.AddProxyConfig(proxyType, proxyHost, (ushort)proxyPort, username, password); - if (_proxyConfigId == 0) - { - return false; - } - } - - return await Task.FromResult(true); - } - catch (Exception ex) - { - var error = $"Failed to update proxy config: {ex.Message}"; - await _updateFunc?.Invoke(true, error); - return false; - } - } - - public async Task SetDnsViaProxy(bool enable) - { - if (_netBridgeService == null) - { - return false; - } - - _netBridgeService.SetDnsViaProxy(enable); - - return await Task.FromResult(true); - } - - private async Task ApplyRoutesInternal() - { - if (_netBridgeService == null) - { - return false; - } - - List rules; - - rules = _ruleConfigs.Select(JsonUtils.DeepCopy).ToList(); - - foreach (var rule in rules.Where(x => x.RuleId > 0)) - { - try - { - _ = _netBridgeService.DeleteRule(rule.RuleId); - } - catch - { - // ignored - } - } - - for (var i = 0; i < rules.Count; i++) - { - var rule = rules[i]; - var newRuleId = _netBridgeService.AddRule(rule.ProcessName, rule.TargetHosts, rule.TargetPorts, rule.Protocol, rule.Action, rule.ProxyConfigId); - if (newRuleId == 0) - { - return false; - } - - rules[i].RuleId = newRuleId; - } - - _ruleConfigs = rules; - - return await Task.FromResult(true); - } - - private static List BuildRuleConfigs(string? ruleProcess) - { - if (ruleProcess.IsNullOrEmpty()) - { - return new(); - } - - var processNames = Utils.String2List(Utils.Convert2Comma(ruleProcess)); - return processNames.Select(processName => new NetBridgeRuleConfig - { - ProcessName = processName, - TargetHosts = "*", - TargetPorts = "*", - Protocol = "BOTH", - Action = "PROXY", - ProxyConfigId = 0 - }).ToList(); - } -} diff --git a/v2rayN/ServiceLib/Models/Configs/Config.cs b/v2rayN/ServiceLib/Models/Configs/Config.cs index 9ebc2c41..69770d3c 100644 --- a/v2rayN/ServiceLib/Models/Configs/Config.cs +++ b/v2rayN/ServiceLib/Models/Configs/Config.cs @@ -29,7 +29,6 @@ public class Config public SystemProxyItem SystemProxyItem { get; set; } public WebDavItem WebDavItem { get; set; } public CheckUpdateItem CheckUpdateItem { get; set; } - public NetBridgeItem NetBridgeItem { get; set; } public Fragment4RayItem? Fragment4RayItem { get; set; } public List Inbound { get; set; } public List GlobalHotkeys { get; set; } diff --git a/v2rayN/ServiceLib/Models/Configs/ConfigItems.cs b/v2rayN/ServiceLib/Models/Configs/ConfigItems.cs index 1cddf707..490686a9 100644 --- a/v2rayN/ServiceLib/Models/Configs/ConfigItems.cs +++ b/v2rayN/ServiceLib/Models/Configs/ConfigItems.cs @@ -278,10 +278,3 @@ public class SimpleDNSItem public string? Hosts { get; set; } public string? DirectExpectedIPs { get; set; } } - -[Serializable] -public class NetBridgeItem -{ - public string? RuleProcess { get; set; } - public bool EnableDnsViaProxy { get; set; } -} diff --git a/v2rayN/ServiceLib/Models/Dto/NetBridgeRuleConfig.cs b/v2rayN/ServiceLib/Models/Dto/NetBridgeRuleConfig.cs deleted file mode 100644 index a12a64ab..00000000 --- a/v2rayN/ServiceLib/Models/Dto/NetBridgeRuleConfig.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace ServiceLib.Models.Dto; - -public sealed class NetBridgeRuleConfig -{ - public uint RuleId { get; set; } - public string ProcessName { get; set; } - public string TargetHosts { get; set; } - public string TargetPorts { get; set; } - public string Protocol { get; set; } - public string Action { get; set; } - public uint ProxyConfigId { get; set; } -} diff --git a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs index 8ecf40e7..216f3fb0 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs +++ b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs @@ -1329,15 +1329,6 @@ namespace ServiceLib.Resx { } } - /// - /// 查找类似 Process traffic hijacking (experimental) 的本地化字符串。 - /// - public static string menuNetBridge { - get { - return ResourceManager.GetString("menuNetBridge", resourceCulture); - } - } - /// /// 查找类似 New Update 的本地化字符串。 /// @@ -2328,15 +2319,6 @@ namespace ServiceLib.Resx { } } - /// - /// 查找类似 The process names that need to be proxied; separate multiple processes with commas. Processes not in the list will also be hijacked, but will connect directly. 的本地化字符串。 - /// - public static string NetBridgeRuleTips { - get { - return ResourceManager.GetString("NetBridgeRuleTips", resourceCulture); - } - } - /// /// 查找类似 Non-VMess or SS protocol 的本地化字符串。 /// @@ -3069,15 +3051,6 @@ namespace ServiceLib.Resx { } } - /// - /// 查找类似 Enables process traffic hijacking (experimental), similar to Proxifer; can coexist with system proxy; conflicts with TUN mode, please do not enable them simultaneously;please allow v2rayN to use a private network in your firewall. 的本地化字符串。 - /// - public static string TbEnableNetBridge { - get { - return ResourceManager.GetString("TbEnableNetBridge", resourceCulture); - } - } - /// /// 查找类似 DNS via Bridge 的本地化字符串。 /// @@ -3753,15 +3726,6 @@ namespace ServiceLib.Resx { } } - /// - /// 查找类似 Save rules 的本地化字符串。 - /// - public static string TbSaveNetBridgeRule { - get { - return ResourceManager.GetString("TbSaveNetBridgeRule", resourceCulture); - } - } - /// /// 查找类似 sing-box Full Config Template 的本地化字符串。 /// diff --git a/v2rayN/ServiceLib/Resx/ResUI.resx b/v2rayN/ServiceLib/Resx/ResUI.resx index 6bea42e5..70d001b2 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.resx @@ -1794,21 +1794,9 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if Split the tail of packets into smaller fragments. This may affect throughput and latency. - - Enables process traffic hijacking (experimental), similar to Proxifer; can coexist with system proxy; conflicts with TUN mode, please do not enable them simultaneously;please allow v2rayN to use a private network in your firewall. - - - The process names that need to be proxied; separate multiple processes with commas. Processes not in the list will also be hijacked, but will connect directly. - - - Process traffic hijacking (experimental) - DNS via Bridge - - Save rules - Insecure configuration detected: AllowInsecure is enabled but no certificate is provided. This may cause MITM attacks. diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx index 8aa676e1..b227a13d 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx @@ -1791,21 +1791,9 @@ 将数据包末端拆分为更小片段发送,可能影响吞吐与延迟。 - - 启用进程流量劫持(实验性),类似 Proxifer 功能;可以和系统代理并存;和 TUN 模式冲突,请不要同时开启;请在防火墙中允许 v2rayN 使用专用网络 - - - 需要代理的进程名,多个进程请用逗号分隔;不在列表中的进程也会被劫持,但是会直连 - - - 进程流量劫持(实验性) - DNS 通过 Bridge - - 保存规则 - 检测到不安全配置:AllowInsecure 已启用,但未提供证书。这可能会导致中间人攻击。 diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx index 61771c75..cce86dcc 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx @@ -1791,19 +1791,7 @@ 將封包末端拆分為更小的片段進行傳送,可能會影響吞吐量與延遲 - - 啟用進程流量劫持(實驗性),類似 Proxifer 功能;可以和系統代理並存;和 TUN 模式衝突,請不要同時開啟;請在防火牆中允許 v2rayN 使用專用網絡 - - - 需要代理程式的進程名,多個進程請用逗號分隔;不在清單中的進程也會被劫持,但是會直連 - - - 進程流量劫持(實驗性) - DNS 透過 Bridge - - 保存規則 - \ No newline at end of file diff --git a/v2rayN/ServiceLib/ServiceLib.csproj b/v2rayN/ServiceLib/ServiceLib.csproj index aea506fc..0f00474c 100644 --- a/v2rayN/ServiceLib/ServiceLib.csproj +++ b/v2rayN/ServiceLib/ServiceLib.csproj @@ -90,7 +90,6 @@ - diff --git a/v2rayN/ServiceLib/ViewModels/NetBridgeViewModel.cs b/v2rayN/ServiceLib/ViewModels/NetBridgeViewModel.cs deleted file mode 100644 index 6730db70..00000000 --- a/v2rayN/ServiceLib/ViewModels/NetBridgeViewModel.cs +++ /dev/null @@ -1,120 +0,0 @@ -namespace ServiceLib.ViewModels; - -public class NetBridgeViewModel : MyReactiveObject -{ - [Reactive] - public bool EnableNetBridge { get; set; } - - [Reactive] - public bool EnabletDnsViaProxy { get; set; } - - [Reactive] - public string RuleProcess { get; set; } - - public ReactiveCommand SaveRulesCmd { get; } - - public NetBridgeViewModel(Func>? updateView) - { - _config = AppManager.Instance.Config; - _updateView = updateView; - - SaveRulesCmd = ReactiveCommand.CreateFromTask(async () => - { - await SaveRulesAsync(); - }); - - this.WhenAnyValue(x => x.EnableNetBridge) - .Skip(1) - .Subscribe(async enabled => - { - await ToggleNetBridgeAsync(enabled); - }); - - this.WhenAnyValue(x => x.EnabletDnsViaProxy) - .Skip(1) - .Subscribe(async enabled => - { - await ToggleDnsViaProxyAsync(enabled); - }); - - _ = Init(); - } - - private async Task Init() - { - EnabletDnsViaProxy = _config.NetBridgeItem.EnableDnsViaProxy; - - _config.NetBridgeItem ??= new() - { - RuleProcess = string.Empty - }; - - EnableNetBridge = false; - if (_config.NetBridgeItem.RuleProcess.IsNullOrEmpty()) - { - _config.NetBridgeItem.RuleProcess = "Chrome.exe"; - } - RuleProcess = _config.NetBridgeItem.RuleProcess; - - await Task.CompletedTask; - } - - private async Task ToggleNetBridgeAsync(bool enabled) - { - await NetBridgeManager.Instance.Init(UpdateViewHandler); - - if (enabled) - { - var succeed = await NetBridgeManager.Instance.Start(); - if (succeed) - { - await NetBridgeManager.Instance.UpdateProxyConfig(Global.Loopback, AppManager.Instance.GetLocalPort(EInboundProtocol.socks)); - await NetBridgeManager.Instance.UpdateRoutes(RuleProcess); - await NetBridgeManager.Instance.SetDnsViaProxy(EnabletDnsViaProxy); - } - NoticeManager.Instance.Enqueue(succeed ? ResUI.OperationSuccess : ResUI.OperationFailed); - } - else - { - var succeed = await NetBridgeManager.Instance.Stop(); - NoticeManager.Instance.Enqueue(succeed ? ResUI.OperationSuccess : ResUI.OperationFailed); - } - } - - private async Task ToggleDnsViaProxyAsync(bool enabled) - { - _config.NetBridgeItem.EnableDnsViaProxy = enabled; - - await NetBridgeManager.Instance.SetDnsViaProxy(enabled); - } - - /// - private async Task SaveRulesAsync() - { - _config.NetBridgeItem ??= new(); - - var normalizedRuleProcess = RuleProcess; - _config.NetBridgeItem.RuleProcess = normalizedRuleProcess; - RuleProcess = normalizedRuleProcess; - - if (await ConfigHandler.SaveConfig(_config) != 0) - { - NoticeManager.Instance.Enqueue(ResUI.OperationFailed); - return; - } - - await NetBridgeManager.Instance.Init(UpdateViewHandler); - if (EnableNetBridge) - { - var routesUpdated = await NetBridgeManager.Instance.UpdateRoutes(normalizedRuleProcess); - NoticeManager.Instance.Enqueue(routesUpdated ? ResUI.OperationSuccess : ResUI.OperationFailed); - } - } - - private async Task UpdateViewHandler(bool isError, string msg) - { - NoticeManager.Instance.SendMessageEx(msg); - - return await Task.FromResult(true); - } -} diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml index 765b83c5..5473f96f 100644 --- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml +++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml @@ -89,7 +89,6 @@ - diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs index 1cd5d486..15c47b05 100644 --- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs @@ -12,7 +12,6 @@ public partial class MainWindow : WindowBase private readonly WindowNotificationManager? _manager; private CheckUpdateView? _checkUpdateView; private BackupAndRestoreView? _backupAndRestoreView; - private NetBridgeView? _netBridgeView; private bool _blCloseByUser = false; public MainWindow() @@ -29,7 +28,6 @@ public partial class MainWindow : WindowBase btnNewUpdate.Click += MenuCheckUpdate_Click; menuBackupAndRestore.Click += MenuBackupAndRestore_Click; menuClose.Click += MenuClose_Click; - menuNetBridge.Click += MenuNetBridge_Click; ViewModel = new MainWindowViewModel(UpdateViewHandler); @@ -167,7 +165,6 @@ public partial class MainWindow : WindowBase { Title = $"{Utils.GetVersion()}"; menuAddServerViaScan.IsVisible = false; - menuNetBridge.IsVisible = false; } if (_config.UiItem.AutoHideStartup && Utils.IsWindows()) @@ -382,19 +379,6 @@ public partial class MainWindow : WindowBase DialogHost.Show(_backupAndRestoreView); } - private void MenuNetBridge_Click(object? sender, RoutedEventArgs e) - { - if (Utils.IsAdministrator()) - { - _netBridgeView ??= new NetBridgeView(); - DialogHost.Show(_netBridgeView); - } - else - { - NoticeManager.Instance.SendMessageAndEnqueue(ResUI.RunAsAdmin); - } - } - private async void MenuClose_Click(object? sender, RoutedEventArgs e) { if (await UI.ShowYesNo(this, ResUI.menuExitTips) != ButtonResult.Yes) diff --git a/v2rayN/v2rayN.Desktop/Views/NetBridgeView.axaml b/v2rayN/v2rayN.Desktop/Views/NetBridgeView.axaml deleted file mode 100644 index b18f0e47..00000000 --- a/v2rayN/v2rayN.Desktop/Views/NetBridgeView.axaml +++ /dev/null @@ -1,94 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - -