Example #1
0
 public void InitializeFrom(ModuleWriterOptionsBase options)
 {
     if (options is ModuleWriterOptions)
     {
         InitializeFrom((ModuleWriterOptions)options);
     }
     else
     {
         InitializeFrom((NativeModuleWriterOptions)options);
     }
 }
        /// <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.");
            }
        }
Example #3
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)ModuleKind.SelectedItem;
        }
Example #4
0
 /// <summary>
 /// Writes the module, using the given options.
 /// </summary>
 /// <param name="moduleWriterOptionsBase">The module writer options base.</param>
 /// <exception cref="InvalidOperationException"></exception>
 private void WriteModule(ModuleWriterOptionsBase moduleWriterOptionsBase)
 {
     if (moduleWriterOptionsBase is ModuleWriterOptions moduleWriterOptions)
     {
         Module.Write(_assemblyPath, moduleWriterOptions);
     }
     else if (moduleWriterOptionsBase is NativeModuleWriterOptions nativeModuleWriterOptions)
     {
         Module.NativeWrite(_assemblyPath, nativeModuleWriterOptions);
     }
     else
     {
         throw new InvalidOperationException();
     }
 }
Example #5
0
        void InitializeFromInternal(ModuleWriterOptionsBase options)
        {
            // Writing to it triggers a write to Subsystem so write it first
            ModuleKind.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;
        }
        /// <summary>
        ///     Runs the protection pipeline.
        /// </summary>
        /// <param name="pipeline">The protection pipeline.</param>
        /// <param name="context">The context.</param>
        // Token: 0x0600010B RID: 267 RVA: 0x00009030 File Offset: 0x00007230
        private static void RunPipeline(ProtectionPipeline pipeline, ConfuserContext context)
        {
            Func <IList <IDnlibDef> >            getAllDefs    = () => context.Modules.SelectMany((ModuleDefMD module) => module.FindDefinitions()).ToList <IDnlibDef>();
            Func <ModuleDef, IList <IDnlibDef> > getModuleDefs = (ModuleDef module) => module.FindDefinitions().ToList <IDnlibDef>();

            context.CurrentModuleIndex = -1;
            pipeline.ExecuteStage(PipelineStage.Inspection, new Action <ConfuserContext>(ConfuserEngine.Inspection), () => getAllDefs(), context);
            ModuleWriterOptionsBase[] options   = new ModuleWriterOptionsBase[context.Modules.Count];
            ModuleWriterListener[]    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, new Action <ConfuserContext>(ConfuserEngine.BeginModule), () => getModuleDefs(context.CurrentModule), context);
                pipeline.ExecuteStage(PipelineStage.ProcessModule, new Action <ConfuserContext>(ConfuserEngine.ProcessModule), () => getModuleDefs(context.CurrentModule), context);
                pipeline.ExecuteStage(PipelineStage.OptimizeMethods, new Action <ConfuserContext>(ConfuserEngine.OptimizeMethods), () => getModuleDefs(context.CurrentModule), context);
                pipeline.ExecuteStage(PipelineStage.EndModule, new Action <ConfuserContext>(ConfuserEngine.EndModule), () => getModuleDefs(context.CurrentModule), context);
                options[i]   = context.CurrentModuleWriterOptions;
                listeners[i] = context.CurrentModuleWriterListener;
            }
            for (int j = 0; j < context.Modules.Count; j++)
            {
                context.CurrentModuleIndex          = j;
                context.CurrentModuleWriterOptions  = options[j];
                context.CurrentModuleWriterListener = listeners[j];
                pipeline.ExecuteStage(PipelineStage.WriteModule, new Action <ConfuserContext>(ConfuserEngine.WriteModule), () => getModuleDefs(context.CurrentModule), context);
                context.OutputModules[j]            = context.CurrentModuleOutput;
                context.OutputSymbols[j]            = context.CurrentModuleSymbol;
                context.CurrentModuleWriterOptions  = null;
                context.CurrentModuleWriterListener = null;
                context.CurrentModuleOutput         = null;
                context.CurrentModuleSymbol         = null;
            }
            context.CurrentModuleIndex = -1;
            pipeline.ExecuteStage(PipelineStage.Debug, new Action <ConfuserContext>(ConfuserEngine.Debug), () => getAllDefs(), context);
            pipeline.ExecuteStage(PipelineStage.Pack, new Action <ConfuserContext>(ConfuserEngine.Pack), () => getAllDefs(), context);
            pipeline.ExecuteStage(PipelineStage.SaveModules, new Action <ConfuserContext>(ConfuserEngine.SaveModules), () => getAllDefs(), context);
            if (!context.PackerInitiated)
            {
                context.Logger.Info("Done.");
            }
        }
Example #7
0
        static void Main(string[] args)
        {
            Console.Title = "Phoenix Protector Strings Decryptor by illuZion";
            Console.WriteAscii("Phoenix Protector", Color.Red);
            Console.WriteAscii("Strings Decryptor", Color.Orange);
            Console.WriteLine("v1.0 by illuZion ", Color.Blue);

            var targetFilePath = string.Empty;

            if (args.Length < 1)
            {
                while (targetFilePath == string.Empty || !File.Exists(targetFilePath))
                {
                    Console.Write("Path of the file: ");
                    targetFilePath = Path.GetFullPath(Console.ReadLine().Replace("\"", string.Empty));
                }
            }
            else
            {
                targetFilePath = Path.GetFullPath(args[0]);
            }

            ModuleDefMD module = null;

            try
            {
                module = ModuleDefMD.Load(targetFilePath);
            }
            catch (Exception ex)
            {
                throw new BadImageFormatException("Module couldn't have been loaded.", ex);
            }
            if (module == null)
            {
                throw new BadImageFormatException("Module couldn't have been loaded.");
            }

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            int decryptedCount = StringsDecryptor.DecryptStrings(module);

            stopwatch.Stop();
            Console.WriteLine($"\n[+] Decrypted {decryptedCount} strings ! Elapsed time: {stopwatch.Elapsed.TotalSeconds}", Color.Green);
            Console.WriteLine("[$] Saving the file...", Color.Aqua);

            string outputFilePath = $"{Path.GetDirectoryName(targetFilePath)}\\{Path.GetFileNameWithoutExtension(targetFilePath)}-decrypted{Path.GetExtension(targetFilePath)}";
            ModuleWriterOptionsBase moduleWriterOptionsBase = module.IsILOnly
                ? new ModuleWriterOptions(module)
                : (ModuleWriterOptionsBase) new NativeModuleWriterOptions(module, true);

            moduleWriterOptionsBase.MetadataOptions.Flags |= MetadataFlags.PreserveAll;
            // Prevents dnlib from throwing non-important errors.
            moduleWriterOptionsBase.Logger         = DummyLogger.NoThrowInstance;
            moduleWriterOptionsBase.MetadataLogger = DummyLogger.NoThrowInstance;

            // Saves the output (unpacked) module.
            if (moduleWriterOptionsBase is NativeModuleWriterOptions nativeModuleWriterOptions)
            {
                module.NativeWrite(outputFilePath, nativeModuleWriterOptions);
            }
            else
            {
                module.Write(outputFilePath, moduleWriterOptionsBase as ModuleWriterOptions);
            }

            Console.WriteLine($"[+] File saved at {outputFilePath}", Color.Green);

            Console.ReadKey();
            Environment.Exit(0);
        }