コード例 #1
0
        /// <summary>
        ///     Returns only the targets with the specified type and used by specified component.
        /// </summary>
        /// <param name="context">The working context.</param>
        /// <param name="targets">List of targets.</param>
        /// <param name="phase">The component phase.</param>
        /// <returns>Filtered targets.</returns>
        static IList <IDnlibDef> Filter(DotProtectContext context, IList <IDnlibDef> targets, ProtectionPhase phase)
        {
            ProtectionTargets targetType = phase.Targets;

            IEnumerable <IDnlibDef> filter = targets;

            if ((targetType & ProtectionTargets.Modules) == 0)
            {
                filter = filter.Where(def => !(def is ModuleDef));
            }
            if ((targetType & ProtectionTargets.Types) == 0)
            {
                filter = filter.Where(def => !(def is TypeDef));
            }
            if ((targetType & ProtectionTargets.Methods) == 0)
            {
                filter = filter.Where(def => !(def is MethodDef));
            }
            if ((targetType & ProtectionTargets.Fields) == 0)
            {
                filter = filter.Where(def => !(def is FieldDef));
            }
            if ((targetType & ProtectionTargets.Properties) == 0)
            {
                filter = filter.Where(def => !(def is PropertyDef));
            }
            if ((targetType & ProtectionTargets.Events) == 0)
            {
                filter = filter.Where(def => !(def is EventDef));
            }

            if (phase.ProcessAll)
            {
                return(filter.ToList());
            }
            return(filter.Where(def => {
                ProtectionSettings parameters = ProtectionParameters.GetParameters(context, def);
                Debug.Assert(parameters != null);
                if (parameters == null)
                {
                    context.Logger.ErrorFormat("'{0}' not marked for obfuscation, possibly a bug.", def);
                    throw new DotProtectception(null);
                }
                return parameters.ContainsKey(phase.Parent);
            }).ToList());
        }
コード例 #2
0
 /// <summary>
 ///     Fills the protection settings with the specified preset.
 /// </summary>
 /// <param name="preset">The preset.</param>
 /// <param name="settings">The settings.</param>
 void FillPreset(ProtectionPreset preset, ProtectionSettings settings)
 {
     foreach (Protection prot in protections.Values)
     {
         if (prot.Preset != ProtectionPreset.None && prot.Preset <= preset && !settings.ContainsKey(prot))
         {
             settings.Add(prot, new Dictionary <string, string>());
         }
     }
 }