2025-05-21 09:23:29 +08:00
|
|
|
|
using dnlib.DotNet;
|
|
|
|
|
using Obfuz.Conf;
|
|
|
|
|
using Obfuz.Utils;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
|
|
namespace Obfuz.ObfusPasses.FieldEncrypt
|
|
|
|
|
{
|
|
|
|
|
public class ConfigurableEncryptPolicy : EncryptPolicyBase
|
|
|
|
|
{
|
|
|
|
|
class ObfuscationRule
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly XmlFieldRuleParser<ObfuscationRule> _configParser;
|
2025-05-29 22:20:27 +08:00
|
|
|
|
private readonly ObfuzIgnoreScopeComputeCache _obfuzIgnoreScopeComputeCache;
|
2025-05-21 09:23:29 +08:00
|
|
|
|
|
2025-05-29 22:20:27 +08:00
|
|
|
|
public ConfigurableEncryptPolicy(ObfuzIgnoreScopeComputeCache obfuzIgnoreScopeComputeCache, List<string> toObfuscatedAssemblyNames, List<string> configFiles)
|
2025-05-21 09:23:29 +08:00
|
|
|
|
{
|
2025-05-29 22:20:27 +08:00
|
|
|
|
_obfuzIgnoreScopeComputeCache = obfuzIgnoreScopeComputeCache;
|
2025-05-21 09:23:29 +08:00
|
|
|
|
_configParser = new XmlFieldRuleParser<ObfuscationRule>(toObfuscatedAssemblyNames, ParseRule, null);
|
|
|
|
|
_configParser.LoadConfigs(configFiles);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ObfuscationRule ParseRule(string configFile, XmlElement ele)
|
|
|
|
|
{
|
|
|
|
|
return new ObfuscationRule();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool NeedEncrypt(FieldDef field)
|
|
|
|
|
{
|
|
|
|
|
if (MetaUtil.HasEncryptFieldAttribute(field))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2025-05-30 08:15:49 +08:00
|
|
|
|
if (_obfuzIgnoreScopeComputeCache.HasSelfOrDeclaringOrEnclosingOrInheritObfuzIgnoreScope(field, field.DeclaringType, ObfuzScope.Field))
|
2025-05-21 09:23:29 +08:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
var rule = _configParser.GetFieldRule(field);
|
|
|
|
|
return rule != null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|