Пример #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(ConfuserContext 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 ConfuserException(null);
				}
				return parameters.ContainsKey(phase.Parent);
			}).ToList();
		}
Пример #2
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>
        // Token: 0x060002FE RID: 766 RVA: 0x00012B84 File Offset: 0x00010D84
        private static IList <IDnlibDef> Filter(ConfuserContext context, IList <IDnlibDef> targets, ProtectionPhase phase)
        {
            ProtectionTargets       targetType = phase.Targets;
            IEnumerable <IDnlibDef> filter     = targets;

            if ((targetType & ProtectionTargets.Modules) == (ProtectionTargets)0)
            {
                filter = from def in filter
                         where !(def is ModuleDef)
                         select def;
            }
            if ((targetType & ProtectionTargets.Types) == (ProtectionTargets)0)
            {
                filter = from def in filter
                         where !(def is TypeDef)
                         select def;
            }
            if ((targetType & ProtectionTargets.Methods) == (ProtectionTargets)0)
            {
                filter = from def in filter
                         where !(def is MethodDef)
                         select def;
            }
            if ((targetType & ProtectionTargets.Fields) == (ProtectionTargets)0)
            {
                filter = from def in filter
                         where !(def is FieldDef)
                         select def;
            }
            if ((targetType & ProtectionTargets.Properties) == (ProtectionTargets)0)
            {
                filter = from def in filter
                         where !(def is PropertyDef)
                         select def;
            }
            if ((targetType & ProtectionTargets.Events) == (ProtectionTargets)0)
            {
                filter = from def in filter
                         where !(def is EventDef)
                         select def;
            }
            if (phase.ProcessAll)
            {
                return(filter.ToList <IDnlibDef>());
            }
            return(filter.Where(delegate(IDnlibDef def)
            {
                ProtectionSettings parameters = ProtectionParameters.GetParameters(context, def);
                if (parameters == null)
                {
                    context.Logger.ErrorFormat("'{0}' not marked for obfuscation, possibly a bug.", new object[]
                    {
                        def
                    });
                    throw new ConfuserException(null);
                }
                return parameters.ContainsKey(phase.Parent);
            }).ToList <IDnlibDef>());
        }
Пример #3
0
 public override void Execute(ProtectionTargets targets)
 {
     foreach (var def in targets)
     {
         _logger.Info($"Processing {def.Name}");
     }
     k
 }
Пример #4
0
     internal INameProvider GetRenamer(IMDTokenProvider def, ProtectionTargets targets)
     {
         return targets.GetOption(def, "mode", "ascii").ToUpperInvariant() switch
         {
             "FILESIZESAVING" => Factory.CreateFileSizeSaving(),
             _ => Factory.CreateAscii()
         };
     }
 }
Пример #5
0
        public ProtectionTargets Build(string protName, IDictionary <IDnlibDef, OptionList> dict)
        {
            var obj = new ProtectionTargets();

            foreach (var pair in dict)
            {
                foreach (var option in pair.Value)
                {
                    if (!option.Apply || !Compare(protName, option.Name))
                    {
                        continue;
                    }

                    obj.Add(pair.Key);
                    obj.Options[pair.Key] = option.Parameters;
                }
            }

            return(obj);
        }
Пример #6
0
        public override void Execute(ProtectionTargets targets)
        {
            var ctx = new RenamerContext
            {
                Logger = _logger
            };
            var phase = Factory.CreateAnalysePhase();

            foreach (var d in targets.Where(d => !(d is AssemblyDef) && !(d is ModuleDef)))
            {
                ctx.Add(d);
            }

            foreach (var def in targets)
            {
                phase.Analyse(def, ctx);
            }

            CommenceRename(ctx, targets);
        }
Пример #7
0
 internal DefinitionProcessor(RenamerContext ctx, ProtectionTargets targets)
 {
     _ctx     = ctx;
     _targets = targets;
 }
Пример #8
0
 static void CommenceRename(RenamerContext ctx, ProtectionTargets targets)
 {
     Factory.CreateDefinitionProcessor(ctx, targets).ProcessDefinitions();
 }
Пример #9
0
 internal static IDefinitionProcessor CreateDefinitionProcessor(RenamerContext ctx, ProtectionTargets targets)
 {
     return(new DefinitionProcessor(ctx, targets));
 }
Пример #10
0
 public abstract void Execute(ProtectionTargets targets); //TODO: Maybe do separate stages for better extensibility?
Пример #11
0
 public static IEnumerable <MetadataMember> Purify(this ProtectionTargets NeededTargets, IEnumerable <MetadataMember> Targets)
 => NeededTargets switch
 {