mirror of
https://github.com/2dust/v2rayN.git
synced 2026-07-26 09:52:05 +03:00
Add ProtectCoreTypeList (#9756)
* Add ProtectCoreTypeList * Add process path restrictions
This commit is contained in:
@@ -193,12 +193,17 @@ public class CoreConfigContextBuilder
|
||||
if (preSocksItem != null)
|
||||
{
|
||||
var preSocksResult = await Build(nodeContext.AppConfig, preSocksItem);
|
||||
|
||||
var protectCoreTypeList = nodeContext.ProtectCoreTypeList;
|
||||
protectCoreTypeList.Add(nodeContext.RunCoreType);
|
||||
|
||||
return preSocksResult with
|
||||
{
|
||||
Context = preSocksResult.Context with
|
||||
{
|
||||
ProtectDomainList =
|
||||
[.. nodeContext.ProtectDomainList ?? [], .. preSocksResult.Context.ProtectDomainList ?? []],
|
||||
ProtectCoreTypeList = protectCoreTypeList,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ public record CoreConfigContext
|
||||
// TUN Compatibility
|
||||
public bool IsTunEnabled { get; init; } = false;
|
||||
public HashSet<string> ProtectDomainList { get; init; } = [];
|
||||
// Typically, it is the core of the outbound chain
|
||||
public HashSet<ECoreType> ProtectCoreTypeList { get; init; } = [];
|
||||
|
||||
public bool IsWindows { get; init; }
|
||||
public bool IsMacOS { get; init; }
|
||||
|
||||
@@ -34,18 +34,18 @@ public partial class CoreConfigSingboxService
|
||||
_coreConfig.route.rules.AddRange(tunRules);
|
||||
}
|
||||
|
||||
var (lstDnsExe, lstDirectExe) = BuildRoutingDirectExe();
|
||||
var lstDirectExe = BuildRoutingDirectExe();
|
||||
_coreConfig.route.rules.Add(new()
|
||||
{
|
||||
port = [53],
|
||||
action = "hijack-dns",
|
||||
process_name = lstDnsExe
|
||||
process_path = lstDirectExe
|
||||
});
|
||||
|
||||
_coreConfig.route.rules.Add(new()
|
||||
{
|
||||
outbound = Global.DirectTag,
|
||||
process_name = lstDirectExe
|
||||
process_path = lstDirectExe
|
||||
});
|
||||
|
||||
// ICMP Routing
|
||||
@@ -256,34 +256,38 @@ public partial class CoreConfigSingboxService
|
||||
}
|
||||
}
|
||||
|
||||
private static (List<string> lstDnsExe, List<string> lstDirectExe) BuildRoutingDirectExe()
|
||||
private List<string> BuildRoutingDirectExe()
|
||||
{
|
||||
var dnsExeSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
var directExeSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
var coreInfoResult = CoreInfoManager.Instance.GetCoreInfo();
|
||||
var allCoreInfo = CoreInfoManager.Instance.GetCoreInfo();
|
||||
|
||||
foreach (var coreConfig in coreInfoResult)
|
||||
foreach (var coreConfig in allCoreInfo)
|
||||
{
|
||||
if (!context.ProtectCoreTypeList.Contains(coreConfig.CoreType))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (coreConfig.CoreType == ECoreType.v2rayN)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (coreConfig.CoreExes == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
foreach (var baseExeName in coreConfig.CoreExes)
|
||||
{
|
||||
if (coreConfig.CoreType != ECoreType.sing_box)
|
||||
//directExeSet.Add(Utils.GetExeName(baseExeName));
|
||||
var exePath = CoreInfoManager.Instance.GetCoreExecFile(coreConfig, out _);
|
||||
if (!exePath.IsNullOrEmpty())
|
||||
{
|
||||
dnsExeSet.Add(Utils.GetExeName(baseExeName));
|
||||
directExeSet.Add(exePath);
|
||||
}
|
||||
directExeSet.Add(Utils.GetExeName(baseExeName));
|
||||
}
|
||||
}
|
||||
|
||||
var lstDnsExe = new List<string>(dnsExeSet);
|
||||
var lstDirectExe = new List<string>(directExeSet);
|
||||
|
||||
return (lstDnsExe, lstDirectExe);
|
||||
return directExeSet.ToList();
|
||||
}
|
||||
|
||||
private void GenRoutingUserRule(RulesItem? item)
|
||||
|
||||
@@ -13,11 +13,11 @@ public partial class CoreConfigV2rayService
|
||||
{
|
||||
_coreConfig.routing.rules.AddRange(tunRules);
|
||||
}
|
||||
var (lstDnsExe, lstDirectExe) = BuildRoutingDirectExe();
|
||||
var lstDirectExe = BuildRoutingDirectExe();
|
||||
_coreConfig.routing.rules.Add(new()
|
||||
{
|
||||
port = "53",
|
||||
process = lstDnsExe,
|
||||
process = lstDirectExe,
|
||||
outboundTag = Global.DnsOutboundTag,
|
||||
});
|
||||
_coreConfig.routing.rules.Add(new()
|
||||
@@ -232,36 +232,44 @@ public partial class CoreConfigV2rayService
|
||||
return finalRule;
|
||||
}
|
||||
|
||||
private static (List<string> lstDnsExe, List<string> lstDirectExe) BuildRoutingDirectExe()
|
||||
private List<string> BuildRoutingDirectExe()
|
||||
{
|
||||
var dnsExeSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
var directExeSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
var coreInfoResult = CoreInfoManager.Instance.GetCoreInfo();
|
||||
var allCoreInfo = CoreInfoManager.Instance.GetCoreInfo();
|
||||
|
||||
foreach (var coreConfig in coreInfoResult)
|
||||
foreach (var coreConfig in allCoreInfo)
|
||||
{
|
||||
if (!context.ProtectCoreTypeList.Contains(coreConfig.CoreType))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (coreConfig.CoreType == ECoreType.v2rayN)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (coreConfig.CoreExes == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (coreConfig.CoreType == ECoreType.Xray)
|
||||
{
|
||||
directExeSet.Add("xray/");
|
||||
continue;
|
||||
}
|
||||
foreach (var baseExeName in coreConfig.CoreExes)
|
||||
{
|
||||
if (coreConfig.CoreType != ECoreType.Xray)
|
||||
//directExeSet.Add(Utils.GetExeName(baseExeName));
|
||||
var exePath = CoreInfoManager.Instance.GetCoreExecFile(coreConfig, out _);
|
||||
if (!exePath.IsNullOrEmpty())
|
||||
{
|
||||
dnsExeSet.Add(Utils.GetExeName(baseExeName));
|
||||
directExeSet.Add(exePath);
|
||||
}
|
||||
directExeSet.Add(Utils.GetExeName(baseExeName));
|
||||
}
|
||||
}
|
||||
|
||||
directExeSet.Add("xray/");
|
||||
//directExeSet.Add("xray/");
|
||||
directExeSet.Add("self/");
|
||||
|
||||
var lstDnsExe = new List<string>(dnsExeSet);
|
||||
var lstDirectExe = new List<string>(directExeSet);
|
||||
|
||||
return (lstDnsExe, lstDirectExe);
|
||||
return directExeSet.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user