static IEnumerable<ProtectionSettingsInfo> ProcessAttributes(IEnumerable<ObfuscationAttributeInfo> attrs) { bool hasAttr = false; ProtectionSettingsInfo info; foreach (var attr in attrs) { info = new ProtectionSettingsInfo(); info.Exclude = (attr.Exclude ?? true); info.ApplyToMember = (attr.ApplyToMembers ?? true); info.Settings = attr.FeatureValue; if (!string.IsNullOrEmpty(attr.FeatureName)) throw new ArgumentException("Feature name must not be set."); if (info.Exclude && (!string.IsNullOrEmpty(attr.FeatureName) || !string.IsNullOrEmpty(attr.FeatureValue))) { throw new ArgumentException("Feature property cannot be set when Exclude is true."); } yield return info; hasAttr = true; } if (!hasAttr) { info = new ProtectionSettingsInfo(); info.Exclude = false; info.ApplyToMember = false; info.Settings = ""; yield return info; } }
ProtectionSettingsInfo AddRule(ObfuscationAttributeInfo attr, List<ProtectionSettingsInfo> infos) { Debug.Assert(attr.FeatureName != null); var pattern = attr.FeatureName; PatternExpression expr; try { expr = new PatternParser().Parse(pattern); } catch (Exception ex) { throw new Exception("Error when parsing pattern " + pattern + " in ObfuscationAttribute. Owner=" + attr.Owner, ex); } var info = new ProtectionSettingsInfo(); info.Condition = expr; info.Exclude = (attr.Exclude ?? true); info.ApplyToMember = (attr.ApplyToMembers ?? true); info.Settings = attr.FeatureValue; bool ok = true; try { new ObfAttrParser(protections).ParseProtectionString(null, info.Settings); } catch { ok = false; } if (!ok) context.Logger.ErrorFormat("Ignoring rule '{0}' in {1}.", info.Settings, attr.Owner); else if (infos != null) infos.Add(info); return info; }
bool ToInfo(ObfuscationAttributeInfo attr, out ProtectionSettingsInfo info) { info = new ProtectionSettingsInfo(); info.Condition = null; info.Exclude = (attr.Exclude ?? true); info.ApplyToMember = (attr.ApplyToMembers ?? true); info.Settings = attr.FeatureValue; bool ok = true; try { new ObfAttrParser(protections).ParseProtectionString(null, info.Settings); } catch { ok = false; } if (!ok) { context.Logger.WarnFormat("Ignoring rule '{0}' in {1}.", info.Settings, attr.Owner); return(false); } if (!string.IsNullOrEmpty(attr.FeatureName)) { throw new ArgumentException("Feature name must not be set. Owner=" + attr.Owner); } if (info.Exclude && (!string.IsNullOrEmpty(attr.FeatureName) || !string.IsNullOrEmpty(attr.FeatureValue))) { throw new ArgumentException("Feature property cannot be set when Exclude is true. Owner=" + attr.Owner); } return(true); }
bool ToInfo(ObfuscationAttributeInfo attr, out ProtectionSettingsInfo info) { info = new ProtectionSettingsInfo(); info.Condition = null; info.Exclude = (attr.Exclude ?? true); info.ApplyToMember = (attr.ApplyToMembers ?? true); info.Settings = attr.FeatureValue; bool ok = true; try { new ObfAttrParser(protections).ParseProtectionString(null, info.Settings); } catch { ok = false; } if (!ok) { context.Logger.WarnFormat("忽略 {1} 中的规则“{0}”。", info.Settings, attr.Owner); return(false); } if (!string.IsNullOrEmpty(attr.FeatureName)) { throw new ArgumentException("不得设置功能名称。 所有者=" + attr.Owner); } if (info.Exclude && (!string.IsNullOrEmpty(attr.FeatureName) || !string.IsNullOrEmpty(attr.FeatureValue))) { throw new ArgumentException("当Exclude为true时,无法设置要素属性。 所有者=" + attr.Owner); } return(true); }
ProtectionSettingsInfo ToInfo(Rule rule, PatternExpression expr) { var info = new ProtectionSettingsInfo(); info.Condition = expr; info.Exclude = false; info.ApplyToMember = true; var settings = new StringBuilder(); if (rule.Preset != ProtectionPreset.None) settings.AppendFormat("preset({0});", rule.Preset.ToString().ToLowerInvariant()); foreach (var item in rule) { settings.Append(item.Action == SettingItemAction.Add ? '+' : '-'); settings.Append(item.Id); if (item.Count > 0) { settings.Append('('); int i = 0; foreach (var arg in item) { if (i != 0) settings.Append(','); settings.AppendFormat("{0}='{1}'", arg.Key, arg.Value.Replace("'", "\\'")); i++; } settings.Append(')'); } settings.Append(';'); } info.Settings = settings.ToString(); return info; }
IEnumerable <ProtectionSettingsInfo> ProcessAttributes(IEnumerable <ObfuscationAttributeInfo> attrs) { bool hasAttr = false; ProtectionSettingsInfo info; foreach (var attr in attrs) { info = new ProtectionSettingsInfo(); info.Exclude = (attr.Exclude ?? true); info.ApplyToMember = (attr.ApplyToMembers ?? true); info.Settings = attr.FeatureValue; bool ok = true; try { new ObfAttrParser(protections).ParseProtectionString(null, info.Settings); } catch { ok = false; } if (!ok) { context.Logger.WarnFormat("Ignoring rule '{0}'.", info.Settings); continue; } if (!string.IsNullOrEmpty(attr.FeatureName)) { throw new ArgumentException("Feature name must not be set."); } if (info.Exclude && (!string.IsNullOrEmpty(attr.FeatureName) || !string.IsNullOrEmpty(attr.FeatureValue))) { throw new ArgumentException("Feature property cannot be set when Exclude is true."); } yield return(info); hasAttr = true; } if (!hasAttr) { info = new ProtectionSettingsInfo(); info.Exclude = false; info.ApplyToMember = false; info.Settings = ""; yield return(info); } }
ProtectionSettingsInfo AddRule(ObfuscationAttributeInfo attr, List <ProtectionSettingsInfo> infos) { Debug.Assert(attr.FeatureName != null); var pattern = attr.FeatureName; PatternExpression expr; try { expr = new PatternParser().Parse(pattern); } catch (Exception ex) { throw new Exception("解析模式时出错 " + pattern + " 在ObfuscationAttribute中。 所有者=" + attr.Owner, ex); } var info = new ProtectionSettingsInfo(); info.Condition = expr; info.Exclude = (attr.Exclude ?? true); info.ApplyToMember = (attr.ApplyToMembers ?? true); info.Settings = attr.FeatureValue; bool ok = true; try { new ObfAttrParser(protections).ParseProtectionString(null, info.Settings); } catch { ok = false; } if (!ok) { context.Logger.WarnFormat("忽略规则 '{0}' in {1}.", info.Settings, attr.Owner); } else if (infos != null) { infos.Add(info); } return(info); }
static IEnumerable <ProtectionSettingsInfo> ProcessAttributes(IEnumerable <ObfuscationAttributeInfo> attrs) { foreach (var attr in attrs) { var info = new ProtectionSettingsInfo(); info.Exclude = (attr.Exclude ?? true); info.ApplyToMember = (attr.ApplyToMembers ?? true); info.Settings = attr.FeatureValue; if (!string.IsNullOrEmpty(attr.FeatureName)) { throw new ArgumentException("Feature name must not be set."); } if (info.Exclude && (!string.IsNullOrEmpty(attr.FeatureName) || !string.IsNullOrEmpty(attr.FeatureValue))) { throw new ArgumentException("Feature property cannot be set when Exclude is true."); } yield return(info); } }
ProtectionSettingsInfo ToInfo(Rule rule, PatternExpression expr) { var info = new ProtectionSettingsInfo(); info.Condition = expr; info.Exclude = false; info.ApplyToMember = true; var settings = new StringBuilder(); if (rule.Preset != ProtectionPreset.None) settings.AppendFormat("preset({0});", rule.Preset.ToString().ToLowerInvariant()); foreach (var item in rule) { settings.Append(item.Action == SettingItemAction.Add ? '+' : '-'); settings.Append(item.Id); if (item.Count > 0) { settings.Append('('); int i = 0; foreach (var arg in item) { if (i != 0) settings.Append(','); settings.AppendFormat("{0}='{1}'", arg.Key, arg.Value.Replace("'", "\\'")); i++; } settings.Append(')'); } settings.Append(';'); } info.Settings = settings.ToString(); return info; }
bool ToInfo(ObfuscationAttributeInfo attr, out ProtectionSettingsInfo info) { info = new ProtectionSettingsInfo(); info.Condition = null; info.Exclude = (attr.Exclude ?? true); info.ApplyToMember = (attr.ApplyToMembers ?? true); info.Settings = attr.FeatureValue; bool ok = true; try { new ObfAttrParser(protections).ParseProtectionString(null, info.Settings); } catch { ok = false; } if (!ok) { context.Logger.WarnFormat("Ignoring rule '{0}' in {1}.", info.Settings, attr.Owner); return false; } if (!string.IsNullOrEmpty(attr.FeatureName)) throw new ArgumentException("Feature name must not be set. Owner=" + attr.Owner); if (info.Exclude && (!string.IsNullOrEmpty(attr.FeatureName) || !string.IsNullOrEmpty(attr.FeatureValue))) { throw new ArgumentException("Feature property cannot be set when Exclude is true. Owner=" + attr.Owner); } return true; }
ProtectionSettingsInfo AddRule(ObfuscationAttributeInfo attr, List<ProtectionSettingsInfo> infos) { Debug.Assert(attr.FeatureName != null); var pattern = attr.FeatureName; PatternExpression expr; try { expr = new PatternParser().Parse(pattern); } catch (Exception ex) { throw new Exception("Error when parsing pattern " + pattern + " in ObfuscationAttribute. Owner=" + attr.Owner, ex); } var info = new ProtectionSettingsInfo(); info.Condition = expr; info.Exclude = (attr.Exclude ?? true); info.ApplyToMember = (attr.ApplyToMembers ?? true); info.Settings = attr.FeatureValue; bool ok = true; try { new ObfAttrParser(protections).ParseProtectionString(null, info.Settings); } catch { ok = false; } if (!ok) context.Logger.WarnFormat("Ignoring rule '{0}' in {1}.", info.Settings, attr.Owner); else if (infos != null) infos.Add(info); return info; }
IEnumerable<ProtectionSettingsInfo> ProcessAttributes(IEnumerable<ObfuscationAttributeInfo> attrs) { bool hasAttr = false; ProtectionSettingsInfo info; foreach (var attr in attrs) { info = new ProtectionSettingsInfo(); info.Exclude = (attr.Exclude ?? true); info.ApplyToMember = (attr.ApplyToMembers ?? true); info.Settings = attr.FeatureValue; bool ok = true; try { new ObfAttrParser(protections).ParseProtectionString(null, info.Settings); } catch { ok = false; } if (!ok) { context.Logger.WarnFormat("Ignoring rule '{0}'.", info.Settings); continue; } if (!string.IsNullOrEmpty(attr.FeatureName)) throw new ArgumentException("Feature name must not be set."); if (info.Exclude && (!string.IsNullOrEmpty(attr.FeatureName) || !string.IsNullOrEmpty(attr.FeatureValue))) { throw new ArgumentException("Feature property cannot be set when Exclude is true."); } yield return info; hasAttr = true; } if (!hasAttr) { info = new ProtectionSettingsInfo(); info.Exclude = false; info.ApplyToMember = false; info.Settings = ""; yield return info; } }