mirror of
https://github.com/2dust/v2rayN.git
synced 2026-10-15 17:55:00 +03:00
Add process matching rules support (#8643)
* Add process matching rules support * Fix
This commit is contained in:
@@ -280,9 +280,49 @@ public partial class CoreConfigSingboxService
|
||||
|
||||
if (_config.TunModeItem.EnableTun && item.Process?.Count > 0)
|
||||
{
|
||||
rule3.process_name = item.Process;
|
||||
rules.Add(rule3);
|
||||
hasDomainIp = true;
|
||||
var ruleProcName = JsonUtils.DeepCopy(rule3);
|
||||
var ruleProcPath = JsonUtils.DeepCopy(rule3);
|
||||
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
|
||||
|
||||
@@ -77,12 +77,17 @@ public partial class CoreConfigV2rayService
|
||||
{
|
||||
rule.inboundTag = null;
|
||||
}
|
||||
if (rule.process?.Count == 0)
|
||||
{
|
||||
rule.process = null;
|
||||
}
|
||||
|
||||
var hasDomainIp = false;
|
||||
if (rule.domain?.Count > 0)
|
||||
{
|
||||
var it = JsonUtils.DeepCopy(rule);
|
||||
it.ip = null;
|
||||
it.process = null;
|
||||
it.type = "field";
|
||||
for (var k = it.domain.Count - 1; k >= 0; k--)
|
||||
{
|
||||
@@ -99,6 +104,16 @@ public partial class CoreConfigV2rayService
|
||||
{
|
||||
var it = JsonUtils.DeepCopy(rule);
|
||||
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";
|
||||
v2rayConfig.routing.rules.Add(it);
|
||||
hasDomainIp = true;
|
||||
|
||||
Reference in New Issue
Block a user