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)
|
if (preSocksItem != null)
|
||||||
{
|
{
|
||||||
var preSocksResult = await Build(nodeContext.AppConfig, preSocksItem);
|
var preSocksResult = await Build(nodeContext.AppConfig, preSocksItem);
|
||||||
|
|
||||||
|
var protectCoreTypeList = nodeContext.ProtectCoreTypeList;
|
||||||
|
protectCoreTypeList.Add(nodeContext.RunCoreType);
|
||||||
|
|
||||||
return preSocksResult with
|
return preSocksResult with
|
||||||
{
|
{
|
||||||
Context = preSocksResult.Context with
|
Context = preSocksResult.Context with
|
||||||
{
|
{
|
||||||
ProtectDomainList =
|
ProtectDomainList =
|
||||||
[.. nodeContext.ProtectDomainList ?? [], .. preSocksResult.Context.ProtectDomainList ?? []],
|
[.. nodeContext.ProtectDomainList ?? [], .. preSocksResult.Context.ProtectDomainList ?? []],
|
||||||
|
ProtectCoreTypeList = protectCoreTypeList,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ public record CoreConfigContext
|
|||||||
// TUN Compatibility
|
// TUN Compatibility
|
||||||
public bool IsTunEnabled { get; init; } = false;
|
public bool IsTunEnabled { get; init; } = false;
|
||||||
public HashSet<string> ProtectDomainList { get; init; } = [];
|
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 IsWindows { get; init; }
|
||||||
public bool IsMacOS { get; init; }
|
public bool IsMacOS { get; init; }
|
||||||
|
|||||||
@@ -34,18 +34,18 @@ public partial class CoreConfigSingboxService
|
|||||||
_coreConfig.route.rules.AddRange(tunRules);
|
_coreConfig.route.rules.AddRange(tunRules);
|
||||||
}
|
}
|
||||||
|
|
||||||
var (lstDnsExe, lstDirectExe) = BuildRoutingDirectExe();
|
var lstDirectExe = BuildRoutingDirectExe();
|
||||||
_coreConfig.route.rules.Add(new()
|
_coreConfig.route.rules.Add(new()
|
||||||
{
|
{
|
||||||
port = [53],
|
port = [53],
|
||||||
action = "hijack-dns",
|
action = "hijack-dns",
|
||||||
process_name = lstDnsExe
|
process_path = lstDirectExe
|
||||||
});
|
});
|
||||||
|
|
||||||
_coreConfig.route.rules.Add(new()
|
_coreConfig.route.rules.Add(new()
|
||||||
{
|
{
|
||||||
outbound = Global.DirectTag,
|
outbound = Global.DirectTag,
|
||||||
process_name = lstDirectExe
|
process_path = lstDirectExe
|
||||||
});
|
});
|
||||||
|
|
||||||
// ICMP Routing
|
// 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 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)
|
if (coreConfig.CoreType == ECoreType.v2rayN)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (coreConfig.CoreExes == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
foreach (var baseExeName in coreConfig.CoreExes)
|
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);
|
return directExeSet.ToList();
|
||||||
var lstDirectExe = new List<string>(directExeSet);
|
|
||||||
|
|
||||||
return (lstDnsExe, lstDirectExe);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GenRoutingUserRule(RulesItem? item)
|
private void GenRoutingUserRule(RulesItem? item)
|
||||||
|
|||||||
@@ -13,11 +13,11 @@ public partial class CoreConfigV2rayService
|
|||||||
{
|
{
|
||||||
_coreConfig.routing.rules.AddRange(tunRules);
|
_coreConfig.routing.rules.AddRange(tunRules);
|
||||||
}
|
}
|
||||||
var (lstDnsExe, lstDirectExe) = BuildRoutingDirectExe();
|
var lstDirectExe = BuildRoutingDirectExe();
|
||||||
_coreConfig.routing.rules.Add(new()
|
_coreConfig.routing.rules.Add(new()
|
||||||
{
|
{
|
||||||
port = "53",
|
port = "53",
|
||||||
process = lstDnsExe,
|
process = lstDirectExe,
|
||||||
outboundTag = Global.DnsOutboundTag,
|
outboundTag = Global.DnsOutboundTag,
|
||||||
});
|
});
|
||||||
_coreConfig.routing.rules.Add(new()
|
_coreConfig.routing.rules.Add(new()
|
||||||
@@ -232,36 +232,44 @@ public partial class CoreConfigV2rayService
|
|||||||
return finalRule;
|
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 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)
|
if (coreConfig.CoreType == ECoreType.v2rayN)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (coreConfig.CoreExes == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (coreConfig.CoreType == ECoreType.Xray)
|
||||||
|
{
|
||||||
|
directExeSet.Add("xray/");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
foreach (var baseExeName in coreConfig.CoreExes)
|
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/");
|
directExeSet.Add("self/");
|
||||||
|
|
||||||
var lstDnsExe = new List<string>(dnsExeSet);
|
return directExeSet.ToList();
|
||||||
var lstDirectExe = new List<string>(directExeSet);
|
|
||||||
|
|
||||||
return (lstDnsExe, lstDirectExe);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user