Beispiel #1
0
        public static void Obfuscate(BuildAssembly assembly)
        {
            var obfuscator = new ResourceObfuscator(assembly);

            obfuscator.Obfuscate();
        }
        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();
        }