Beispiel #1
0
        /// <summary>
        ///     Runs the protection pipeline.
        /// </summary>
        /// <param name="pipeline">The protection pipeline.</param>
        /// <param name="context">The context.</param>
        static void RunPipeline(ProtectionPipeline pipeline, ConfuserContext context)
        {
            Func<IList<IDnlibDef>> getAllDefs = () => context.Modules.SelectMany(module => module.FindDefinitions()).ToList();
            Func<ModuleDef, IList<IDnlibDef>> getModuleDefs = module => module.FindDefinitions().ToList();

            context.CurrentModuleIndex = -1;

            pipeline.ExecuteStage(PipelineStage.Inspection, Inspection, () => getAllDefs(), context);

            var options = new ModuleWriterOptionsBase[context.Modules.Count];
            var listeners = new ModuleWriterListener[context.Modules.Count];
            for (int i = 0; i < context.Modules.Count; i++) {
                context.CurrentModuleIndex = i;
                context.CurrentModuleWriterOptions = null;
                context.CurrentModuleWriterListener = null;

                pipeline.ExecuteStage(PipelineStage.BeginModule, BeginModule, () => getModuleDefs(context.CurrentModule), context);
                pipeline.ExecuteStage(PipelineStage.ProcessModule, ProcessModule, () => getModuleDefs(context.CurrentModule), context);
                pipeline.ExecuteStage(PipelineStage.OptimizeMethods, OptimizeMethods, () => getModuleDefs(context.CurrentModule), context);
                pipeline.ExecuteStage(PipelineStage.EndModule, EndModule, () => getModuleDefs(context.CurrentModule), context);

                options[i] = context.CurrentModuleWriterOptions;
                listeners[i] = context.CurrentModuleWriterListener;
            }

            for (int i = 0; i < context.Modules.Count; i++) {
                context.CurrentModuleIndex = i;
                context.CurrentModuleWriterOptions = options[i];
                context.CurrentModuleWriterListener = listeners[i];

                pipeline.ExecuteStage(PipelineStage.WriteModule, WriteModule, () => getModuleDefs(context.CurrentModule), context);

                context.OutputModules[i] = context.CurrentModuleOutput;
                context.OutputSymbols[i] = context.CurrentModuleSymbol;
                context.CurrentModuleWriterOptions = null;
                context.CurrentModuleWriterListener = null;
                context.CurrentModuleOutput = null;
                context.CurrentModuleSymbol = null;
            }

            context.CurrentModuleIndex = -1;

            pipeline.ExecuteStage(PipelineStage.Debug, Debug, () => getAllDefs(), context);
            pipeline.ExecuteStage(PipelineStage.Pack, Pack, () => getAllDefs(), context);
            pipeline.ExecuteStage(PipelineStage.SaveModules, SaveModules, () => getAllDefs(), context);

            if (!context.PackerInitiated)
                context.Logger.Info("Done.");
        }
Beispiel #2
0
		public void InitializeFrom(ModuleWriterOptionsBase options) {
			if (options is ModuleWriterOptions)
				InitializeFrom((ModuleWriterOptions)options);
			else
				InitializeFrom((NativeModuleWriterOptions)options);
		}
Beispiel #3
0
		void InitializeFromInternal(ModuleWriterOptionsBase options) {
			// Writing to it triggers a write to Subsystem so write it first
			moduleKindVM.SelectedItem = options.ModuleKind;

			peHeadersOptions.InitializeFrom(options.PEHeadersOptions);
			cor20HeaderOptions.InitializeFrom(options.Cor20HeaderOptions);
			metaDataOptions.InitializeFrom(options.MetaDataOptions);

			WritePdb = options.WritePdb;
			ShareMethodBodies = options.ShareMethodBodies;
			AddCheckSum = options.AddCheckSum;
			Win32Resources = options.Win32Resources;

			// Writing to Machine and ModuleKind triggers code that updates Characteristics
			peHeadersOptions.Characteristics = options.PEHeadersOptions.Characteristics;
		}
Beispiel #4
0
		void CopyTo(ModuleWriterOptionsBase options) {
			peHeadersOptions.CopyTo(options.PEHeadersOptions);
			cor20HeaderOptions.CopyTo(options.Cor20HeaderOptions);
			metaDataOptions.CopyTo(options.MetaDataOptions);

			options.WritePdb = WritePdb;
			options.ShareMethodBodies = ShareMethodBodies;
			options.AddCheckSum = AddCheckSum;
			options.Win32Resources = Win32Resources;
			options.ModuleKind = (dnlib.DotNet.ModuleKind)moduleKindVM.SelectedItem;
		}