Beispiel #1
0
        /// <summary>
        ///     Loads the assembly and marks the project.
        /// </summary>
        /// <param name="proj">The project.</param>
        /// <param name="context">The working context.</param>
        /// <returns><see cref="MarkerResult" /> storing the marked modules and packer information.</returns>
        protected internal virtual MarkerResult MarkProject(ConfuserProject proj, ConfuserContext context)
        {
            Packer packer = null;
            Dictionary <string, string> packerParams = null;

            if (proj.Packer != null)
            {
                if (!packers.ContainsKey(proj.Packer.Id))
                {
                    context.Logger.ErrorFormat("Cannot find packer with ID '{0}'.", proj.Packer.Id);
                    throw new ConfuserException(null);
                }
                if (proj.Debug)
                {
                    context.Logger.Warn("Generated Debug symbols might not be usable with packers!");
                }

                packer       = packers[proj.Packer.Id];
                packerParams = new Dictionary <string, string>(proj.Packer, StringComparer.OrdinalIgnoreCase);
            }

            var modules = new List <ModuleDefMD>();

            foreach (ProjectModule module in proj)
            {
                context.Logger.InfoFormat("Loading '{0}'...", module.Path);

                ModuleDefMD modDef = module.Resolve(proj.BaseDirectory, context.Resolver.DefaultModuleContext);
                context.CheckCancellation();

                if (proj.Debug)
                {
                    modDef.LoadPdb();
                }

                Rules rules = ParseRules(proj, module, context);

                context.Annotations.Set(modDef, SNKey, LoadSNKey(context, module.SNKeyPath == null ? null : Path.Combine(proj.BaseDirectory, module.SNKeyPath), module.SNKeyPassword));
                context.Annotations.Set(modDef, RulesKey, rules);

                foreach (IDnlibDef def in modDef.FindDefinitions())
                {
                    ApplyRules(context, def, rules);
                    context.CheckCancellation();
                }

                // Packer parameters are stored in modules
                if (packerParams != null)
                {
                    ProtectionParameters.GetParameters(context, modDef)[packer] = packerParams;
                }

                modules.Add(modDef);
            }
            return(new MarkerResult(modules, packer));
        }