コード例 #1
0
ファイル: Marker.cs プロジェクト: EmilZhou/ConfuserEx
		/// <summary>
		///     Parses the rules' patterns.
		/// </summary>
		/// <param name="proj">The project.</param>
		/// <param name="module">The module description.</param>
		/// <param name="context">The working context.</param>
		/// <returns>Parsed rule patterns.</returns>
		/// <exception cref="System.ArgumentException">
		///     One of the rules has invalid pattern.
		/// </exception>
		protected Rules ParseRules(ConfuserProject proj, ProjectModule module, ConfuserContext context) {
			var ret = new Rules();
			var parser = new PatternParser();
			foreach (Rule rule in proj.Rules.Concat(module.Rules)) {
				try {
					ret.Add(rule, parser.Parse(rule.Pattern));
				}
				catch (InvalidPatternException ex) {
					context.Logger.ErrorFormat("Invalid rule pattern: " + rule.Pattern + ".", ex);
					throw new ConfuserException(ex);
				}
				foreach (var setting in rule) {
					if (!protections.ContainsKey(setting.Id)) {
						context.Logger.ErrorFormat("Cannot find protection with ID '{0}'.", setting.Id);
						throw new ConfuserException(null);
					}
				}
			}
			return ret;
		}
コード例 #2
0
        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;
        }