public IDisposable Apply(IDnlibDef target, IEnumerable<ProtectionSettingsInfo> infos) {
				ProtectionSettings settings;
				if (this.settings == null)
					settings = new ProtectionSettings();
				else
					settings = new ProtectionSettings(this.settings);

				var infoArray = infos.ToArray();

				if (stack.Count > 0) {
					foreach (var i in stack.Reverse())
						ApplyInfo(target, settings, i.Item2, ApplyInfoType.ParentInfo);
				}

				IDisposable result;
				if (infoArray.Length != 0) {
					var originalSettings = this.settings;

					// the settings that would apply to members
					ApplyInfo(target, settings, infoArray, ApplyInfoType.CurrentInfoInherits);
					this.settings = new ProtectionSettings(settings);

					// the settings that would apply to itself
					ApplyInfo(target, settings, infoArray, ApplyInfoType.CurrentInfoOnly);
					stack.Push(Tuple.Create(originalSettings, infoArray));

					result = new PopHolder(this);
				}
				else
					result = null;

				ProtectionParameters.SetParameters(context, target, settings);
				return result;
			}
Beispiel #2
0
        /// <summary>
        ///     Applies the rules to the target definition.
        /// </summary>
        /// <param name="context">The working context.</param>
        /// <param name="target">The target definition.</param>
        /// <param name="rules">The rules.</param>
        /// <param name="baseSettings">The base settings.</param>
        protected void ApplyRules(ConfuserContext context, IDnlibDef target, Rules rules, ProtectionSettings baseSettings = null)
        {
            var ret = baseSettings == null ? new ProtectionSettings() : new ProtectionSettings(baseSettings);

            foreach (var i in rules)
            {
                if (!(bool)i.Value.Evaluate(target))
                {
                    continue;
                }

                if (!i.Key.Inherit)
                {
                    ret.Clear();
                }

                FillPreset(i.Key.Preset, ret);
                foreach (var prot in i.Key)
                {
                    if (prot.Action == SettingItemAction.Add)
                    {
                        ret[protections[prot.Id]] = new Dictionary <string, string>(prot, StringComparer.OrdinalIgnoreCase);
                    }
                    else
                    {
                        ret.Remove(protections[prot.Id]);
                    }
                }
            }

            ProtectionParameters.SetParameters(context, target, ret);
        }
        /// <summary>
        ///     Applies the rules to the target definition.
        /// </summary>
        /// <param name="context">The working context.</param>
        /// <param name="target">The target definition.</param>
        /// <param name="rules">The rules.</param>
        /// <param name="baseSettings">The base settings.</param>
        // Token: 0x06000196 RID: 406 RVA: 0x0000D45C File Offset: 0x0000B65C
        protected void ApplyRules(ConfuserContext context, IDnlibDef target, Dictionary <Rule, PatternExpression> rules, ProtectionSettings baseSettings = null)
        {
            ProtectionSettings ret = (baseSettings == null) ? new ProtectionSettings() : new ProtectionSettings(baseSettings);

            foreach (KeyValuePair <Rule, PatternExpression> i in rules)
            {
                if ((bool)i.Value.Evaluate(target))
                {
                    if (!i.Key.Inherit)
                    {
                        ret.Clear();
                    }
                    this.FillPreset(i.Key.Preset, ret);
                    foreach (SettingItem <Protection> prot in i.Key)
                    {
                        if (prot.Action == SettingItemAction.Add)
                        {
                            ret[this.protections[prot.Id]] = new Dictionary <string, string>(prot, StringComparer.OrdinalIgnoreCase);
                        }
                        else
                        {
                            ret.Remove(this.protections[prot.Id]);
                        }
                    }
                }
            }
            ProtectionParameters.SetParameters(context, target, ret);
        }
        /// <inheritdoc />
        protected internal override void MarkMember(IDnlibDef member, ConfuserContext context)
        {
            ModuleDef module   = ((IMemberRef)member).Module;
            var       settings = context.Annotations.Get <ProtectionSettings>(module, ModuleSettingsKey);

            ProtectionParameters.SetParameters(context, member, new ProtectionSettings(settings));
        }
            public IDisposable Apply(IDnlibDef target, IEnumerable <ProtectionSettingsInfo> infos)
            {
                ProtectionSettings settings;

                if (this.settings == null)
                {
                    settings = new ProtectionSettings();
                }
                else
                {
                    settings = new ProtectionSettings(this.settings);
                }

                var infoArray = infos.ToArray();

                if (stack.Count > 0)
                {
                    foreach (var i in stack.Skip(1).Reverse())
                    {
                        ApplyInfo(target, settings, i.Item2.Where(info => info.Condition != null), false);
                    }
                    ApplyInfo(target, settings, stack.Peek().Item2, false);
                }

                IDisposable result;

                if (infoArray.Length != 0)
                {
                    var originalSettings = this.settings;

                    // the settings that would apply to members
                    ApplyInfo(target, settings, infoArray, false);
                    this.settings = new ProtectionSettings(settings);

                    // the settings that would apply to itself
                    ApplyInfo(target, settings, infoArray, true);
                    stack.Push(Tuple.Create(originalSettings, infoArray));

                    result = new PopHolder(this);
                }
                else
                {
                    result = null;
                }

                ProtectionParameters.SetParameters(context, target, settings);
                return(result);
            }
Beispiel #6
0
        /// <inheritdoc />
        protected internal override void MarkMember(IDnlibDef member, ConfuserContext context)
        {
            ModuleDef module = ((IMemberRef)member).Module;

            ProtectionParameters.SetParameters(context, member, ProtectionParameters.GetParameters(context, module));
        }