mirror of
https://github.com/2dust/v2rayN.git
synced 2026-01-18 03:49:34 +00:00
Add process matching rules support (#8643)
* Add process matching rules support * Fix
This commit is contained in:
parent
2fefafdd37
commit
c42dcd2876
12 changed files with 69 additions and 11 deletions
|
|
@ -68,6 +68,7 @@ public class Rule4Sbox
|
||||||
public List<string>? ip_cidr { get; set; }
|
public List<string>? ip_cidr { get; set; }
|
||||||
public List<string>? source_ip_cidr { get; set; }
|
public List<string>? source_ip_cidr { get; set; }
|
||||||
public List<string>? process_name { get; set; }
|
public List<string>? process_name { get; set; }
|
||||||
|
public List<string>? process_path { get; set; }
|
||||||
public List<string>? rule_set { get; set; }
|
public List<string>? rule_set { get; set; }
|
||||||
public List<Rule4Sbox>? rules { get; set; }
|
public List<Rule4Sbox>? rules { get; set; }
|
||||||
public string? action { get; set; }
|
public string? action { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -259,6 +259,8 @@ public class RulesItem4Ray
|
||||||
public List<string>? domain { get; set; }
|
public List<string>? domain { get; set; }
|
||||||
|
|
||||||
public List<string>? protocol { get; set; }
|
public List<string>? protocol { get; set; }
|
||||||
|
|
||||||
|
public List<string>? process { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BalancersItem4Ray
|
public class BalancersItem4Ray
|
||||||
|
|
|
||||||
2
v2rayN/ServiceLib/Resx/ResUI.Designer.cs
generated
2
v2rayN/ServiceLib/Resx/ResUI.Designer.cs
generated
|
|
@ -3286,7 +3286,7 @@ namespace ServiceLib.Resx {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 Full process name (Tun mode) 的本地化字符串。
|
/// 查找类似 Process (Tun mode) 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string TbRoutingRuleProcess {
|
public static string TbRoutingRuleProcess {
|
||||||
get {
|
get {
|
||||||
|
|
|
||||||
|
|
@ -1027,7 +1027,7 @@
|
||||||
<value>پروتکل sing-box Mux</value>
|
<value>پروتکل sing-box Mux</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbRoutingRuleProcess" xml:space="preserve">
|
<data name="TbRoutingRuleProcess" xml:space="preserve">
|
||||||
<value>نام کامل فرانید (حالت Tun)</value>
|
<value>Process (Tun mode)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbRoutingRuleIP" xml:space="preserve">
|
<data name="TbRoutingRuleIP" xml:space="preserve">
|
||||||
<value>IP or IP CIDR</value>
|
<value>IP or IP CIDR</value>
|
||||||
|
|
|
||||||
|
|
@ -1024,7 +1024,7 @@
|
||||||
<value>Protocole de multiplexage Mux (sing-box)</value>
|
<value>Protocole de multiplexage Mux (sing-box)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbRoutingRuleProcess" xml:space="preserve">
|
<data name="TbRoutingRuleProcess" xml:space="preserve">
|
||||||
<value>Nom complet du processus (mode Tun)</value>
|
<value>Process (Tun mode)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbRoutingRuleIP" xml:space="preserve">
|
<data name="TbRoutingRuleIP" xml:space="preserve">
|
||||||
<value>IP ou IP CIDR</value>
|
<value>IP ou IP CIDR</value>
|
||||||
|
|
|
||||||
|
|
@ -1027,7 +1027,7 @@
|
||||||
<value>sing-box Mux protokoll</value>
|
<value>sing-box Mux protokoll</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbRoutingRuleProcess" xml:space="preserve">
|
<data name="TbRoutingRuleProcess" xml:space="preserve">
|
||||||
<value>Teljes folyamatnév (Tun mód)</value>
|
<value>Process (Tun mode)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbRoutingRuleIP" xml:space="preserve">
|
<data name="TbRoutingRuleIP" xml:space="preserve">
|
||||||
<value>IP vagy IP CIDR</value>
|
<value>IP vagy IP CIDR</value>
|
||||||
|
|
|
||||||
|
|
@ -1027,7 +1027,7 @@
|
||||||
<value>sing-box Mux Protocol</value>
|
<value>sing-box Mux Protocol</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbRoutingRuleProcess" xml:space="preserve">
|
<data name="TbRoutingRuleProcess" xml:space="preserve">
|
||||||
<value>Full process name (Tun mode)</value>
|
<value>Process (Tun mode)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbRoutingRuleIP" xml:space="preserve">
|
<data name="TbRoutingRuleIP" xml:space="preserve">
|
||||||
<value>IP or IP CIDR</value>
|
<value>IP or IP CIDR</value>
|
||||||
|
|
|
||||||
|
|
@ -1027,7 +1027,7 @@
|
||||||
<value>Протокол Mux для sing-box</value>
|
<value>Протокол Mux для sing-box</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbRoutingRuleProcess" xml:space="preserve">
|
<data name="TbRoutingRuleProcess" xml:space="preserve">
|
||||||
<value>Полное имя процесса (режим TUN)</value>
|
<value>Process (Tun mode)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbRoutingRuleIP" xml:space="preserve">
|
<data name="TbRoutingRuleIP" xml:space="preserve">
|
||||||
<value>IP-адрес или сеть CIDR</value>
|
<value>IP-адрес или сеть CIDR</value>
|
||||||
|
|
|
||||||
|
|
@ -1024,7 +1024,7 @@
|
||||||
<value>sing-box Mux 多路复用协议</value>
|
<value>sing-box Mux 多路复用协议</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbRoutingRuleProcess" xml:space="preserve">
|
<data name="TbRoutingRuleProcess" xml:space="preserve">
|
||||||
<value>进程名全称 (Tun 模式)</value>
|
<value>进程 (Tun 模式)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbRoutingRuleIP" xml:space="preserve">
|
<data name="TbRoutingRuleIP" xml:space="preserve">
|
||||||
<value>IP 或 IP CIDR</value>
|
<value>IP 或 IP CIDR</value>
|
||||||
|
|
|
||||||
|
|
@ -1024,7 +1024,7 @@
|
||||||
<value>sing-box Mux 多路復用協定</value>
|
<value>sing-box Mux 多路復用協定</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbRoutingRuleProcess" xml:space="preserve">
|
<data name="TbRoutingRuleProcess" xml:space="preserve">
|
||||||
<value>行程名全稱 (Tun 模式)</value>
|
<value>行程 (Tun 模式)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbRoutingRuleIP" xml:space="preserve">
|
<data name="TbRoutingRuleIP" xml:space="preserve">
|
||||||
<value>IP 或 IP CIDR</value>
|
<value>IP 或 IP CIDR</value>
|
||||||
|
|
|
||||||
|
|
@ -280,9 +280,49 @@ public partial class CoreConfigSingboxService
|
||||||
|
|
||||||
if (_config.TunModeItem.EnableTun && item.Process?.Count > 0)
|
if (_config.TunModeItem.EnableTun && item.Process?.Count > 0)
|
||||||
{
|
{
|
||||||
rule3.process_name = item.Process;
|
var ruleProcName = JsonUtils.DeepCopy(rule3);
|
||||||
rules.Add(rule3);
|
var ruleProcPath = JsonUtils.DeepCopy(rule3);
|
||||||
hasDomainIp = true;
|
foreach (var process in item.Process)
|
||||||
|
{
|
||||||
|
// sing-box doesn't support this, fall back to process name match
|
||||||
|
if (process is "self/" or "xray/")
|
||||||
|
{
|
||||||
|
ruleProcName.process_name.Add(Utils.GetExeName("sing-box"));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.Contains('/') || process.Contains('\\'))
|
||||||
|
{
|
||||||
|
var procPath = process;
|
||||||
|
if (Utils.IsWindows())
|
||||||
|
{
|
||||||
|
procPath = procPath.Replace('/', '\\');
|
||||||
|
}
|
||||||
|
ruleProcPath.process_path.Add(procPath);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// sing-box strictly matches the exe suffix on Windows
|
||||||
|
var procName = process;
|
||||||
|
if (Utils.IsWindows() && !procName.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
procName += ".exe";
|
||||||
|
}
|
||||||
|
|
||||||
|
ruleProcName.process_name.Add(procName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ruleProcName.process_name.Count > 0)
|
||||||
|
{
|
||||||
|
rules.Add(ruleProcName);
|
||||||
|
hasDomainIp = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ruleProcPath.process_path.Count > 0)
|
||||||
|
{
|
||||||
|
rules.Add(ruleProcPath);
|
||||||
|
hasDomainIp = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hasDomainIp
|
if (!hasDomainIp
|
||||||
|
|
|
||||||
|
|
@ -77,12 +77,17 @@ public partial class CoreConfigV2rayService
|
||||||
{
|
{
|
||||||
rule.inboundTag = null;
|
rule.inboundTag = null;
|
||||||
}
|
}
|
||||||
|
if (rule.process?.Count == 0)
|
||||||
|
{
|
||||||
|
rule.process = null;
|
||||||
|
}
|
||||||
|
|
||||||
var hasDomainIp = false;
|
var hasDomainIp = false;
|
||||||
if (rule.domain?.Count > 0)
|
if (rule.domain?.Count > 0)
|
||||||
{
|
{
|
||||||
var it = JsonUtils.DeepCopy(rule);
|
var it = JsonUtils.DeepCopy(rule);
|
||||||
it.ip = null;
|
it.ip = null;
|
||||||
|
it.process = null;
|
||||||
it.type = "field";
|
it.type = "field";
|
||||||
for (var k = it.domain.Count - 1; k >= 0; k--)
|
for (var k = it.domain.Count - 1; k >= 0; k--)
|
||||||
{
|
{
|
||||||
|
|
@ -99,6 +104,16 @@ public partial class CoreConfigV2rayService
|
||||||
{
|
{
|
||||||
var it = JsonUtils.DeepCopy(rule);
|
var it = JsonUtils.DeepCopy(rule);
|
||||||
it.domain = null;
|
it.domain = null;
|
||||||
|
it.process = null;
|
||||||
|
it.type = "field";
|
||||||
|
v2rayConfig.routing.rules.Add(it);
|
||||||
|
hasDomainIp = true;
|
||||||
|
}
|
||||||
|
if (_config.TunModeItem.EnableTun && rule.process?.Count > 0)
|
||||||
|
{
|
||||||
|
var it = JsonUtils.DeepCopy(rule);
|
||||||
|
it.domain = null;
|
||||||
|
it.ip = null;
|
||||||
it.type = "field";
|
it.type = "field";
|
||||||
v2rayConfig.routing.rules.Add(it);
|
v2rayConfig.routing.rules.Add(it);
|
||||||
hasDomainIp = true;
|
hasDomainIp = true;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue