Compare commits

...

7 Commits
6.49 ... 6.50

Author SHA1 Message Date
2dust
5efb784115 up 6.50 2024-07-05 11:18:36 +08:00
2dust
acde5b8384 Bug fix 2024-07-05 11:18:14 +08:00
2dust
373ee6586a Optimize system proxy code 2024-07-04 17:07:05 +08:00
2dust
215308c329 Change srs source
https://github.com/2dust/sing-box-rules
2024-07-04 16:27:44 +08:00
2dust
478cadba5e Bug fix 2024-06-30 20:43:06 +08:00
2dust
f4af4da791 Adjust res 2024-06-30 10:00:28 +08:00
2dust
22d4f435de Add tun and mixin functions to clash 2024-06-28 20:29:44 +08:00
21 changed files with 209 additions and 120 deletions

View File

@@ -9,7 +9,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.27.1" />
<PackageReference Include="Google.Protobuf" Version="3.27.2" />
<PackageReference Include="Grpc.Net.Client" Version="2.63.0" />
<PackageReference Include="Grpc.Tools" Version="2.64.0">
<PrivateAssets>all</PrivateAssets>

View File

@@ -43,6 +43,7 @@ namespace v2rayN
Init();
Logging.LoggingEnabled(_config.guiItem.enableLog);
Logging.SaveLog($"v2rayN start up | {Utils.GetVersion()} | {Utils.GetExePath()}");
Logging.SaveLog($"{Environment.OSVersion} - {(Environment.Is64BitOperatingSystem ? 64 : 32)}");
Logging.ClearLogs();
Thread.CurrentThread.CurrentUICulture = new(_config.uiItem.currentLanguage);

View File

@@ -23,14 +23,14 @@ namespace v2rayN
public const string SpeedPingTestUrl = @"https://www.google.com/generate_204";
public const string JuicityCoreUrl = "https://github.com/juicity/juicity/releases";
public const string CustomRoutingListUrl = @"https://raw.githubusercontent.com/2dust/v2rayCustomRoutingList/master/";
public const string SingboxRulesetUrlGeosite = @"https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/{0}.srs";
public const string SingboxRulesetUrlGeoip = @"https://raw.githubusercontent.com/Loyalsoldier/geoip/release/srs/{0}.srs";
public const string SingboxRulesetUrl = @"https://raw.githubusercontent.com/2dust/sing-box-rules/rule-set-{0}/{1}.srs";
public const string PromotionUrl = @"aHR0cHM6Ly85LjIzNDQ1Ni54eXovYWJjLmh0bWw=";
public const string ConfigFileName = "guiNConfig.json";
public const string CoreConfigFileName = "config.json";
public const string CorePreConfigFileName = "configPre.json";
public const string CoreSpeedtestConfigFileName = "configSpeedtest.json";
public const string ClashMixinConfigFileName = "Mixin.yaml";
public const string V2raySampleClient = "v2rayN.Sample.SampleClientConfig";
public const string SingboxSampleClient = "v2rayN.Sample.SingboxSampleClientConfig";
public const string V2raySampleHttpRequestFileName = "v2rayN.Sample.SampleHttpRequest";
@@ -44,6 +44,8 @@ namespace v2rayN
public const string TunSingboxRulesFileName = "v2rayN.Sample.tun_singbox_rules";
public const string DNSV2rayNormalFileName = "v2rayN.Sample.dns_v2ray_normal";
public const string DNSSingboxNormalFileName = "v2rayN.Sample.dns_singbox_normal";
public const string ClashMixinYaml = "v2rayN.Sample.clash_mixin_yaml";
public const string ClashTunYaml = "v2rayN.Sample.clash_tun_yaml";
public const string DefaultSecurity = "auto";
public const string DefaultNetwork = "tcp";

View File

@@ -82,7 +82,8 @@ namespace v2rayN.Handler.CoreConfig
//socks-port
fileContent["socks-port"] = LazyConfig.Instance.GetLocalPort(EInboundProtocol.socks);
//log-level
fileContent["log-level"] = _config.coreBasicItem.loglevel;
fileContent["log-level"] = GetLogLevel(_config.coreBasicItem.loglevel);
//external-controller
fileContent["external-controller"] = $"{Global.Loopback}:{LazyConfig.Instance.StatePort2}";
//allow-lan
@@ -97,7 +98,7 @@ namespace v2rayN.Handler.CoreConfig
}
//ipv6
//fileContent["ipv6"] = _config.EnableIpv6;
fileContent["ipv6"] = _config.clashUIItem.enableIPv6;
//mode
if (!fileContent.ContainsKey("mode"))
@@ -112,27 +113,27 @@ namespace v2rayN.Handler.CoreConfig
}
}
////enable tun mode
//if (config.EnableTun)
//{
// string tun = Utils.GetEmbedText(Global.SampleTun);
// if (!string.IsNullOrEmpty(tun))
// {
// var tunContent = Utils.FromYaml<Dictionary<string, object>>(tun);
// if (tunContent != null)
// fileContent["tun"] = tunContent["tun"];
// }
//}
//enable tun mode
if (_config.tunModeItem.enableTun)
{
string tun = Utils.GetEmbedText(Global.ClashTunYaml);
if (!string.IsNullOrEmpty(tun))
{
var tunContent = YamlUtils.FromYaml<Dictionary<string, object>>(tun);
if (tunContent != null)
fileContent["tun"] = tunContent["tun"];
}
}
//Mixin
//try
//{
// MixinContent(fileContent, config, node);
//}
//catch (Exception ex)
//{
// Logging.SaveLog("GenerateClientConfigClash-Mixin", ex);
//}
try
{
MixinContent(fileContent, node);
}
catch (Exception ex)
{
Logging.SaveLog("GenerateClientConfigClash-Mixin", ex);
}
var txtFileNew = YamlUtils.ToYaml(fileContent).Replace(tagYamlStr2, tagYamlStr3);
File.WriteAllText(fileName, txtFileNew);
@@ -156,49 +157,48 @@ namespace v2rayN.Handler.CoreConfig
return 0;
}
//private static void MixinContent(Dictionary<string, object> fileContent, Config config, ProfileItem node)
//{
// if (!config.EnableMixinContent)
// {
// return;
// }
private void MixinContent(Dictionary<string, object> fileContent, ProfileItem node)
{
//if (!_config.clashUIItem.enableMixinContent)
//{
// return;
//}
// var path = Utils.GetConfigPath(Global.mixinConfigFileName);
// if (!File.Exists(path))
// {
// return;
// }
var path = Utils.GetConfigPath(Global.ClashMixinConfigFileName);
if (!File.Exists(path))
{
return;
}
// var txtFile = File.ReadAllText(Utils.GetConfigPath(Global.mixinConfigFileName));
// //txtFile = txtFile.Replace("!<str>", "");
var txtFile = File.ReadAllText(Utils.GetConfigPath(Global.ClashMixinConfigFileName));
// var mixinContent = YamlUtils.FromYaml<Dictionary<string, object>>(txtFile);
// if (mixinContent == null)
// {
// return;
// }
// foreach (var item in mixinContent)
// {
// if (!config.EnableTun && item.Key == "tun")
// {
// continue;
// }
var mixinContent = YamlUtils.FromYaml<Dictionary<string, object>>(txtFile);
if (mixinContent == null)
{
return;
}
foreach (var item in mixinContent)
{
if (!_config.tunModeItem.enableTun && item.Key == "tun")
{
continue;
}
// if (item.Key.StartsWith("prepend-")
// || item.Key.StartsWith("append-")
// || item.Key.StartsWith("removed-"))
// {
// ModifyContentMerge(fileContent, item.Key, item.Value);
// }
// else
// {
// fileContent[item.Key] = item.Value;
// }
// }
// return;
//}
if (item.Key.StartsWith("prepend-")
|| item.Key.StartsWith("append-")
|| item.Key.StartsWith("removed-"))
{
ModifyContentMerge(fileContent, item.Key, item.Value);
}
else
{
fileContent[item.Key] = item.Value;
}
}
return;
}
private static void ModifyContentMerge(Dictionary<string, object> fileContent, string key, object value)
private void ModifyContentMerge(Dictionary<string, object> fileContent, string key, object value)
{
bool blPrepend = false;
bool blRemoved = false;
@@ -255,5 +255,17 @@ namespace v2rayN.Handler.CoreConfig
}
}
}
private string GetLogLevel(string level)
{
if (level == "none")
{
return "silent";
}
else
{
return level;
}
}
}
}

View File

@@ -983,9 +983,7 @@ namespace v2rayN.Handler.CoreConfig
type = "remote",
format = "binary",
tag = item,
url = item.StartsWith(geosite) ?
string.Format(Global.SingboxRulesetUrlGeosite, item) :
string.Format(Global.SingboxRulesetUrlGeoip, item.Replace($"{geoip}-", "")),
url = string.Format(Global.SingboxRulesetUrl, item.StartsWith(geosite) ? geosite : geoip, item),
download_detour = Global.ProxyTag
});
}

View File

@@ -29,15 +29,23 @@ namespace v2rayN.Handler
/// <returns>true: one of connection is successfully updated proxy settings</returns>
public static bool SetProxy(string? strProxy, string? exceptions, int type)
{
// set proxy for LAN
bool result = SetConnectionProxy(null, strProxy, exceptions, type);
// set proxy for dial up connections
var connections = EnumerateRasEntries();
foreach (var connection in connections)
try
{
result |= SetConnectionProxy(connection, strProxy, exceptions, type);
// set proxy for LAN
bool result = SetConnectionProxy(null, strProxy, exceptions, type);
// set proxy for dial up connections
var connections = EnumerateRasEntries();
foreach (var connection in connections)
{
result |= SetConnectionProxy(connection, strProxy, exceptions, type);
}
return result;
}
catch (Exception ex)
{
Logging.SaveLog(ex.Message, ex);
return false;
}
return result;
}
private static bool SetConnectionProxy(string? connectionName, string? strProxy, string? exceptions, int type)

View File

@@ -6,30 +6,7 @@ namespace v2rayN.Handler
{
public static class SysProxyHandle
{
//private const string _userWininetConfigFile = "user-wininet.json";
//private static string _queryStr;
// In general, this won't change
// format:
// <flags><CR-LF>
// <proxy-server><CR-LF>
// <bypass-list><CR-LF>
// <pac-url>
private enum RET_ERRORS : int
{
RET_NO_ERROR = 0,
INVALID_FORMAT = 1,
NO_PERMISSION = 2,
SYSCALL_FAILED = 3,
NO_MEMORY = 4,
INVAILD_OPTION_COUNT = 5,
};
static SysProxyHandle()
{
}
private const string _regPath = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings";
public static bool UpdateSysProxy(Config config, bool forceDisable)
{
@@ -65,11 +42,17 @@ namespace v2rayN.Handler
.Replace("{http_port}", port.ToString())
.Replace("{socks_port}", portSocks.ToString());
}
ProxySetting.SetProxy(strProxy, strExceptions, 2); // set a named proxy
if (!ProxySetting.SetProxy(strProxy, strExceptions, 2))
{
SetProxy(strProxy, strExceptions, 2);
}
}
else if (type == ESysProxyType.ForcedClear)
{
ProxySetting.UnsetProxy(); // set to no proxy
if (!ProxySetting.UnsetProxy())
{
UnsetProxy();
}
}
else if (type == ESysProxyType.Unchanged)
{
@@ -78,7 +61,10 @@ namespace v2rayN.Handler
{
PacHandler.Start(Utils.GetConfigPath(), port, portPac);
var strProxy = $"{Global.HttpProtocol}{Global.Loopback}:{portPac}/pac?t={DateTime.Now.Ticks}";
ProxySetting.SetProxy(strProxy, "", 4); // use pac script url for auto-config proxy
if (!ProxySetting.SetProxy(strProxy, "", 4))
{
SetProxy(strProxy, "", 4);
}
}
if (type != ESysProxyType.Pac)
@@ -95,14 +81,38 @@ namespace v2rayN.Handler
public static void ResetIEProxy4WindowsShutDown()
{
try
SetProxy(null, null, 1);
}
private static void UnsetProxy()
{
SetProxy(null, null, 1);
}
private static bool SetProxy(string? strProxy, string? exceptions, int type)
{
if (type == 1)
{
//TODO To be verified
Utils.RegWriteValue(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", 0);
Utils.RegWriteValue(_regPath, "ProxyEnable", 0);
Utils.RegWriteValue(_regPath, "ProxyServer", string.Empty);
Utils.RegWriteValue(_regPath, "ProxyOverride", string.Empty);
Utils.RegWriteValue(_regPath, "AutoConfigURL", string.Empty);
}
catch
if (type == 2)
{
Utils.RegWriteValue(_regPath, "ProxyEnable", 1);
Utils.RegWriteValue(_regPath, "ProxyServer", strProxy ?? string.Empty);
Utils.RegWriteValue(_regPath, "ProxyOverride", exceptions ?? string.Empty);
Utils.RegWriteValue(_regPath, "AutoConfigURL", string.Empty);
}
else if (type == 4)
{
Utils.RegWriteValue(_regPath, "ProxyEnable", 0);
Utils.RegWriteValue(_regPath, "ProxyServer", string.Empty);
Utils.RegWriteValue(_regPath, "ProxyOverride", string.Empty);
Utils.RegWriteValue(_regPath, "AutoConfigURL", strProxy ?? string.Empty);
}
return true;
}
}
}

View File

@@ -217,6 +217,8 @@ namespace v2rayN.Models
{
public ERuleMode ruleMode { get; set; }
public bool showInTaskbar { get; set; }
public bool enableIPv6 { get; set; }
public bool enableMixinContent { get; set; }
public int proxiesSorting { get; set; }
public bool proxiesAutoRefresh { get; set; }
public int proxiesAutoDelayTestInterval { get; set; } = 10;

View File

@@ -3032,7 +3032,7 @@ namespace v2rayN.Resx {
}
/// <summary>
/// 查找类似 HTTP port=SOCKS port+1;Pac port=SOCKS port+4;API port=SOCKS port+5; 的本地化字符串。
/// 查找类似 http port = +1; Pac port = +4; *ray API port = +5; mihomo API port = +6; 的本地化字符串。
/// </summary>
public static string TbSettingsSocksPortTip {
get {

View File

@@ -1037,7 +1037,7 @@
<value>Copy the font TTF/TTC file to the directory guiFonts, restart the settings</value>
</data>
<data name="TbSettingsSocksPortTip" xml:space="preserve">
<value>HTTP port=SOCKS port+1;Pac port=SOCKS port+4;API port=SOCKS port+5;</value>
<value>http port = +1; Pac port = +4; *ray API port = +5; mihomo API port = +6;</value>
</data>
<data name="TbSettingsStartBootTip" xml:space="preserve">
<value>Set this with admin privileges, get admin privileges after startup</value>

View File

@@ -1042,9 +1042,6 @@
<data name="TbSettingsCurrentFontFamilyTip" xml:space="preserve">
<value>Скопируйте файл шрифта TTF/TTC в каталог guiFonts, перезапустите настройки</value>
</data>
<data name="TbSettingsSocksPortTip" xml:space="preserve">
<value>HTTP port=socks port+1</value>
</data>
<data name="TbSettingsStartBootTip" xml:space="preserve">
<value>Установите это с правами администратора</value>
</data>

View File

@@ -1037,7 +1037,7 @@
<value>拷贝字体TTF/TTC文件到目录guiFonts重启设置</value>
</data>
<data name="TbSettingsSocksPortTip" xml:space="preserve">
<value>http端口=socks端口+1Pac端口=socks端口+4API端口=socks端口+5</value>
<value>http端口= +1Pac端口= +4*ray API端口= +5mihomo API端口= +6</value>
</data>
<data name="TbSettingsStartBootTip" xml:space="preserve">
<value>以管理员权限设置此项,在启动后获得管理员权限</value>

View File

@@ -1037,7 +1037,7 @@
<value>複製字型TTF/TTC文件到目錄guiFonts重啟設定</value>
</data>
<data name="TbSettingsSocksPortTip" xml:space="preserve">
<value>HTTP埠=SOCKS埠+1</value>
<value>http端口= +1Pac端口= +4*ray API端口= +5mihomo API端口= +6</value>
</data>
<data name="TbSettingsStartBootTip" xml:space="preserve">
<value>以管理員權限設定此項,在啟動後獲得管理員權限</value>

View File

@@ -0,0 +1,39 @@
#
# 配置文件内容不会被修改,混合行为只会发生在内存中
#
# 注意下面缩进请用支持yaml显示的编辑器打开
#
# 使用clash配置文件关键字则覆盖原配置
#
# removed-rules 循环匹配rules数组每行,符合则移除当前行 (此规则请放最前面)
#
# append-rules 数组合并至原配置rules数组后
# prepend-rules 数组合并至原配置rules数组前
# append-proxies 数组合并至原配置proxies数组后
# prepend-proxies 数组合并至原配置proxies数组前
# append-proxy-groups 数组合并至原配置proxy-groups数组后
# prepend-proxy-groups 数组合并至原配置proxy-groups数组前
# append-rule-providers 数组合并至原配置rule-providers数组后
# prepend-rule-providers 数组合并至原配置rule-providers数组前
#
dns:
enable: true
enhanced-mode: fake-ip
nameserver:
- 114.114.114.114
- 223.5.5.5
- 8.8.8.8
fallback: []
fake-ip-filter:
- +.stun.*.*
- +.stun.*.*.*
- +.stun.*.*.*.*
- +.stun.*.*.*.*.*
- "*.n.n.srv.nintendo.net"
- +.stun.playstation.net
- xbox.*.*.microsoft.com
- "*.*.xboxlive.com"
- "*.msftncsi.com"
- "*.msftconnecttest.com"
- WORKGROUP

View File

@@ -0,0 +1,7 @@
tun:
enable: true
stack: gvisor
dns-hijack:
- 0.0.0.0:53
auto-route: true
auto-detect-interface: true

View File

@@ -5,6 +5,11 @@
"bittorrent"
]
},
{
"outboundTag": "block",
"port": "443",
"network": "udp"
},
{
"outboundTag": "block",
"domain": [
@@ -15,7 +20,7 @@
"outboundTag": "proxy",
"domain": [
"geosite:geolocation-!cn",
"geosite:gfw",
"geosite:greatfire"
]
},

View File

@@ -1,4 +1,9 @@
[
{
"outboundTag": "block",
"port": "443",
"network": "udp"
},
{
"port": "0-65535",
"outboundTag": "proxy"

View File

@@ -6,6 +6,11 @@
"domain:example-example2.com"
]
},
{
"outboundTag": "block",
"port": "443",
"network": "udp"
},
{
"outboundTag": "block",
"domain": [

View File

@@ -2,7 +2,6 @@ using DynamicData;
using DynamicData.Binding;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Splat;
using System.Reactive;
using System.Reactive.Linq;
using System.Windows;
@@ -15,11 +14,6 @@ namespace v2rayN.ViewModels
{
private static Config _config;
static ClashConnectionsViewModel()
{
_config = LazyConfig.Instance.GetConfig();
}
private IObservableCollection<ClashConnectionModel> _connectionItems = new ObservableCollectionExtended<ClashConnectionModel>();
public IObservableCollection<ClashConnectionModel> ConnectionItems => _connectionItems;
@@ -38,6 +32,7 @@ namespace v2rayN.ViewModels
public ClashConnectionsViewModel()
{
_config = LazyConfig.Instance.GetConfig();
SortingSelected = _config.clashUIItem.connectionsSorting;
AutoRefresh = _config.clashUIItem.connectionsAutoRefresh;

View File

@@ -147,6 +147,7 @@ namespace v2rayN.ViewModels
public void ProxiesReload()
{
GetClashProxies(true);
ProxiesDelayTest();
}
public void ProxiesClear()

View File

@@ -10,15 +10,15 @@
<ImplicitUsings>enable</ImplicitUsings>
<ApplicationIcon>v2rayN.ico</ApplicationIcon>
<Copyright>Copyright © 2017-2024 (GPLv3)</Copyright>
<FileVersion>6.49</FileVersion>
<FileVersion>6.50</FileVersion>
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Downloader" Version="3.0.6" />
<PackageReference Include="Downloader" Version="3.1.2" />
<PackageReference Include="MaterialDesignThemes" Version="5.1.0" />
<PackageReference Include="H.NotifyIcon.Wpf" Version="2.0.131" />
<PackageReference Include="QRCoder.Xaml" Version="1.5.1" />
<PackageReference Include="QRCoder.Xaml" Version="1.6.0" />
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
<PackageReference Include="TaskScheduler" Version="2.11.0" />
<PackageReference Include="ZXing.Net.Bindings.Windows.Compatibility" Version="0.16.12" />
@@ -31,6 +31,8 @@
<ItemGroup>
<AdditionalFiles Include="app.manifest" />
<EmbeddedResource Include="Sample\clash_mixin_yaml" />
<EmbeddedResource Include="Sample\clash_tun_yaml" />
<EmbeddedResource Include="Sample\SingboxSampleOutbound" />
<EmbeddedResource Include="Sample\SingboxSampleClientConfig">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>