public static void Obfuscate(BuildMethod method, bool ignoreEncryptIL)
        {
            if (!method.ObfuscateControlFlow)
            {
                return;
            }

            if (ignoreEncryptIL && method.EncryptIL)
            {
                return;
            }

            if (!MethodBody.IsValid(method))
            {
                return;
            }

            var methodBody = MethodBody.Load(method);

            var ilBody = ILBody.Load(methodBody);

            // Obfuscate
            var obfuscator = new ControlFlowObfuscator(ilBody, method);

            obfuscator.Obfuscate();

            // Save
            methodBody = ilBody.Build();

            methodBody.Build(method);
        }
        private void ObfuscateControlFlowInitMethod(BuildMethod method)
        {
            if (!MethodBody.IsValid(method))
            {
                return;
            }

            var methodBody = MethodBody.Load(method);

            var ilBody = ILBody.Load(methodBody);

            // Obfuscate
            var obfuscator = new ControlFlowObfuscator(ilBody, method);

            obfuscator.DoNotUseFieldNumber = true;
            obfuscator.Obfuscate();

            // Calculate max stack size
            ilBody.CalculateMaxStackSize(method);

            // Save
            methodBody = ilBody.Build();

            methodBody.Build(method);
        }
        private void ObfuscateControlFlow(BuildMethod method)
        {
            if (!MethodBody.IsValid(method))
            {
                return;
            }

            var methodBody = MethodBody.Load(method);

            var ilBody = ILBody.Load(methodBody);

            // Call proxy
            if (_callProxyBuilder != null)
            {
                _callProxyBuilder.Build(ilBody);
            }

            // Function pointers
            if (_functionPointerBuilder != null)
            {
                _functionPointerBuilder.Build(ilBody);
            }

            // Obfuscate
            var obfuscator = new ControlFlowObfuscator(ilBody, method);

            obfuscator.Obfuscate();

            // Calculate max stack size
            ilBody.CalculateMaxStackSize(method);

            // Save
            methodBody = ilBody.Build();

            methodBody.Build(method);
        }
        private void Change(BuildAssembly assembly)
        {
            var module  = (BuildModule)assembly.Module;
            var strings = new HashList <string>();

            MainType.Create(assembly);

            if (assembly.EncryptIL)
            {
                strings.Add(".");                 // Dot is at index 0
            }
            if (_evaluationPeriodInDays > 0)
            {
                module.MainType.GenerateCheckForExpiredEvaluation(_evaluationPeriodInDays);
            }

            if (assembly.StripObfuscationAttributeExists)
            {
                ObfuscationAttributeStripper.Strip(assembly);
            }

            if (assembly.SuppressILdasm)
            {
                CA.SuppressIldasmAttribute.AddIfNotExists(assembly.CustomAttributes);
            }

            if (assembly.RenameMembers || assembly.DevirtualizeMethods)
            {
                ExplicitMethodCallBuilder.Build(assembly);
            }

            if (CancellationPending)
            {
                return;
            }

            if (_renameAssemblies)
            {
                MemberRenameHelper.BuildRenamedAssemblyResolver(assembly, _renamedAssemblyNames);
            }

            if (assembly.HasWpfResource && (_renameAssemblies || _renameMembers))
            {
                BamlMemberReferenceMapper.Map(assembly, _log);
            }

            if (assembly.HasWpfResource && _renameAssemblies)
            {
                ResourceHelper.RenameWpfResource(assembly);
            }

            if (_renameAssemblies)
            {
                ResourceHelper.RenameSatelliteAssemblies(assembly);
            }

            if (assembly.ObfuscateResources)
            {
                ResourceObfuscator.Obfuscate(assembly);
            }

            if (_obfuscateResources)
            {
                ResourceResolverGenerator.Generate(assembly);
            }

            if (assembly.ObfuscateStrings)
            {
                StringObfuscator.Obfuscate(assembly, strings);
            }

            if (CancellationPending)
            {
                return;
            }

            if (assembly.SealTypes)
            {
                TypeSealer.Seal(assembly);
            }

            if (assembly.DevirtualizeMethods)
            {
                MethodDevirtualizer.Devirtualize(assembly);
            }

            if (CancellationPending)
            {
                return;
            }

            if (_renameMembers)
            {
                ExplicitMethodOverrideBuilder.Build(assembly, _nameGenerator);
            }

            if (_encryptIL)
            {
                ILCryptoMapper.Map(assembly);
            }

            if (assembly.EncryptIL)
            {
                ILCryptoObfuscator.Obfuscate(assembly, strings);
            }

            if (CancellationPending)
            {
                return;
            }

            if (assembly.RemoveUnusedMembers)
            {
                Stripper.Strip(assembly);
            }

            if (assembly.ObfuscateControlFlow)
            {
                ControlFlowObfuscator.Obfuscate(assembly, true);
            }

            if (strings.Count > 0)
            {
                StringLoaderGenerator.Generate(assembly, strings);
            }

            if (CancellationPending)
            {
                return;
            }

            // From this point no more code can be added.

            MainType.Generate(assembly);
            DelegateTypeGenerator.Generate(assembly);
            GeneratedCodeObfuscator.Obfuscate(assembly, _nameGenerator);

            if (CancellationPending)
            {
                return;
            }

            ILCryptoBlobBuilder.MapMemberReferences(assembly);
            MemberReferenceMapper.Map(assembly);
            MemberNameChanger.Change(assembly);

            if (CancellationPending)
            {
                return;
            }

            assembly.Compile();

            Scavenge();
        }