private void Analyze2(BuildAssembly assembly)
        {
            if (_removeUnusedMembers)
            {
                StripAnalyzer.Analyze(assembly);
            }

            if (_sealTypes)
            {
                TypeSealer.Analyze(assembly);
            }

            if (CancellationPending)
            {
                return;
            }

            if (_devirtualizeMethods)
            {
                MethodDevirtualizer.Analyze(assembly);
            }

            if (_renameMembers)
            {
                MismatchTypeGenericArgumentAnalyzer.Analyze(assembly);
                MemberRenameHelper.FixExportedTypeNames(assembly, _nameGenerator);
            }

            SaveState();
        }
Пример #2
0
 public void Load(BuildAssembly assembly)
 {
     foreach (BuildModule module in assembly.Modules)
     {
         Load(module);
     }
 }
        public static void FixExportedTypeNames(BuildAssembly assembly, MemberNameGenerator nameGenerator)
        {
            foreach (var module in assembly.Modules)
            {
                if (!module.Image.IsILOnly)
                {
                    continue;
                }

                var exportedTypes = module.ExportedTypes;
                for (int i = 0; i < exportedTypes.Count; i++)
                {
                    var exportedType = exportedTypes[i].GetOutermostType();

                    var type = exportedType.Resolve(module) as BuildType;
                    if (type == null)
                    {
                        continue;
                    }

                    if (object.ReferenceEquals(type.Assembly, module.Assembly))
                    {
                        continue;
                    }

                    if (!type.Rename)
                    {
                        continue;
                    }

                    type.NewName     = nameGenerator.GenerateUniqueString();
                    type.NameChanged = true;
                }
            }
        }
Пример #4
0
        public void Generate(BuildAssembly assembly)
        {
            Reset();

            foreach (BuildModule module in assembly.Modules)
            {
                if (!module.Image.IsILOnly)
                {
                    continue;
                }

                module.MainTypeName = GenerateString();
                GenerateTypes(module.Types);
                GenerateDelegateTypes(module.DelegateTypes);
                GenerateILCryptoInvokeTypes(module.ILCryptoInvokeTypes);
            }

            foreach (BuildModule module in assembly.Modules)
            {
                if (!module.Image.IsILOnly)
                {
                    continue;
                }

                foreach (BuildType type in module.Types)
                {
                    GenerateMembers(type);
                }
            }
        }
		private bool Build(ref AssemblyReference assemblyRef, BuildAssembly assembly)
		{
			bool changed = false;

			// Name
			string name;
			if (assembly.NameChanged)
			{
				name = assembly.NewName;
				changed = true;
			}
			else
			{
				name = assemblyRef.Name;
			}

			// Culture
			string culture;
			if (assembly.CultureChanged)
			{
				culture = assembly.NewCulture;
				changed = true;
			}
			else
			{
				culture = assemblyRef.Culture;
			}

			// Version
			Version version;
			if (assembly.VersionChanged)
			{
				version = assembly.NewVersion;
				changed = true;
			}
			else
			{
				version = assemblyRef.Version;
			}

			// Version
			byte[] publicKeyToken;
			if (assembly.PublicKeyChanged)
			{
				publicKeyToken = assembly.NewPublicKeyToken;
				changed = true;
			}
			else
			{
				publicKeyToken = assemblyRef.PublicKeyToken;
			}

			if (!changed)
				return false;

			assemblyRef = new AssemblyReference(name, culture, version, publicKeyToken);
			return true;
		}
        private DependencyPropertyAnalizer(BuildAssembly assembly)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            _assembly = assembly;
        }
        private CodeAnalizer(BuildAssembly assembly)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            _assembly = assembly;
        }
        public ILCryptoMethodBuilder(BuildAssembly assembly)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            _module = (BuildModule)assembly.Module;
        }
        private void FireTaskCompleted(BuildAssembly assembly, ProjectBuildTaskType taskType)
        {
            var handler = TaskCompleted;

            if (handler != null)
            {
                handler(this, new ProjectBuildTaskEventArgs(assembly, taskType));
            }
        }
Пример #10
0
        private SerializationAnalizer(BuildAssembly assembly, bool renameSerializableMembers)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            _assembly = assembly;
            _renameSerializableMembers = renameSerializableMembers;
        }
        public StripAnalyzer(BuildAssembly assembly)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            _assembly = assembly;
            _queue    = new Queue <ICodeNode>();
        }
Пример #12
0
        protected internal BuildModule(BuildAssembly assembly, string filePath)
            : base(assembly, filePath)
        {
            var assemblyManager = (BuildAssemblyManager)assembly.AssemblyManager;

            _builder = assemblyManager.Builder;
            _state   = assemblyManager.GetState(Location);
            _state.Load(this);
            _stateOffset = _state.GetModuleOffset();
        }
Пример #13
0
        private BindableAttributeAnalizer(BuildAssembly assembly, bool renameBindableMembers)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            _assembly = assembly;
            _renameBindableMembers = renameBindableMembers;
        }
        internal ResourceStorage(BuildAssembly assembly)
        {
            _assembly = assembly;

            var random = assembly.RandomGenerator;

            _encryptKey   = random.Next(100, int.MaxValue);
            _resourceName = random.NextString(12);
            _blob         = new Blob();
        }
Пример #15
0
        public ResourceObfuscator(BuildAssembly assembly)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            _assembly = assembly;
            _random   = assembly.RandomGenerator;
        }
        public static void RenameSatelliteAssemblies(BuildAssembly assembly)
        {
            bool changed = false;

            // Name
            string name;

            if (assembly.NameChanged)
            {
                name    = assembly.NewName;
                changed = true;
            }
            else
            {
                name = assembly.Name;
            }

            // Version
            Version version;

            if (assembly.VersionChanged)
            {
                version = assembly.NewVersion;
                changed = true;
            }
            else
            {
                version = assembly.Version;
            }

            // PublicKey
            byte[] publicKey;
            if (assembly.PublicKeyChanged)
            {
                publicKey = assembly.NewPublicKey;
                changed   = true;
            }
            else
            {
                publicKey = assembly.PublicKey;
            }

            if (!changed)
            {
                return;
            }

            foreach (var satelliteAssembly in assembly.SatelliteAssemblies)
            {
                satelliteAssembly.Name        = name + ".resources";
                satelliteAssembly.Module.Name = name + ".resources.dll";
                satelliteAssembly.Version     = version;
                satelliteAssembly.PublicKey   = publicKey;
            }
        }
        public static void MapMemberReferences(BuildAssembly assembly)
        {
            var module      = (BuildModule)assembly.Module;
            var assembler   = module.Assembler;
            var blobBuilder = assembler.Tasks.Get <ILCryptoBlobBuilder>();

            if (blobBuilder != null)
            {
                blobBuilder.MapMemberReferences();
            }
        }
Пример #18
0
        public static void Devirtualize(BuildAssembly assembly)
        {
            foreach (BuildModule module in assembly.Modules)
            {
                if (!module.Image.IsILOnly)
                {
                    continue;
                }

                Devirtualize(module);
            }
        }
        public static void Obfuscate(BuildAssembly assembly, bool ignoreEncryptIL = false)
        {
            foreach (BuildModule module in assembly.Modules)
            {
                if (!module.Image.IsILOnly)
                {
                    continue;
                }

                Obfuscate(module, ignoreEncryptIL);
            }
        }
        public static void Obfuscate(BuildAssembly assembly, MemberNameGenerator nameGenerator)
        {
            foreach (BuildModule module in assembly.Modules)
            {
                if (!module.Image.IsILOnly)
                {
                    continue;
                }

                Obfuscate(module, nameGenerator);
            }
        }
Пример #21
0
        public static void Seal(BuildAssembly assembly)
        {
            foreach (BuildModule module in assembly.Modules)
            {
                if (!module.Image.IsILOnly)
                {
                    continue;
                }

                Seal(module);
            }
        }
Пример #22
0
        public StringLoaderGenerator(BuildAssembly assembly, IReadOnlyList <string> strings)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            if (strings == null)
            {
                throw new ArgumentNullException("strings");
            }

            _assembly = assembly;
            _module   = (BuildModule)assembly.Module;
            _strings  = strings;
        }
        public static void RenameWpfResource(BuildAssembly assembly)
        {
            if (!assembly.NameChanged)
            {
                return;
            }

            var resource = assembly.GetWpfResource();

            foreach (var satelliteResource in resource.SatelliteResources)
            {
                satelliteResource.Name = BamlUtils.GetWpfResourceName(assembly.NewName, satelliteResource.Assembly.Culture);
            }

            resource.Name = BamlUtils.GetWpfResourceName(assembly.NewName);
        }
Пример #24
0
        public ExplicitMethodOverrideBuilder(BuildAssembly assembly, MemberNameGenerator nameGenerator)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            if (nameGenerator == null)
            {
                throw new ArgumentNullException("nameGenerator");
            }

            _assembly      = assembly;
            _nameGenerator = nameGenerator;
            _state         = new BuildState();
        }
        private void Analyze3(BuildAssembly assembly)
        {
            if (assembly.RemoveUnusedMembers)
            {
                StripUnmarker.Unmark(assembly);
            }

            if (assembly.EncryptIL)
            {
                ILCryptoMethodBuilder.Build(assembly);
            }

            _nameGenerator.Generate(assembly);

            SaveState();
        }
        public ILCryptoBlobBuilder(BuildAssembly assembly, HashList <string> strings)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            if (strings == null)
            {
                throw new ArgumentNullException("strings");
            }

            _module  = (BuildModule)assembly.Module;
            _strings = strings;
            _storage = assembly.ResourceStorage;
        }
        private void Analyze(BuildAssembly assembly, ProjectAssembly projectAssembly)
        {
            ConfigurationAnalizer.Analyze(assembly, projectAssembly.RenameConfigurationMembers);

            SerializationAnalizer.Analyze(assembly, projectAssembly.RenameSerializableMembers);

            BindableAttributeAnalizer.Analyze(assembly, projectAssembly.RenameBindableMembers);

            DependencyPropertyAnalizer.Analyze(assembly);

            CodeAnalizer.Analyze(assembly);

            BamlAnalyzer.Analyze(assembly);

            SaveState();
        }
        public static void Strip(BuildAssembly assembly)
        {
            if (assembly.StripObfuscationAttribute)
            {
                CA.ObfuscationAttribute.RemoveMarkedAsStrip(assembly.CustomAttributes);
            }

            foreach (BuildModule module in assembly.Modules)
            {
                if (!module.Image.IsILOnly)
                {
                    continue;
                }

                Strip(module);
            }
        }
        public BamlMemberReferenceMapper(BuildAssembly assembly, BuildLog log)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            if (log == null)
            {
                throw new ArgumentNullException("log");
            }

            _assembly          = assembly;
            _log               = log;
            _mainTypeNamespace = assembly.MainTypeNamespace;
            _random            = assembly.RandomGenerator;
        }
        public static void BuildRenamedAssemblyResolver(BuildAssembly assembly, List <TupleStruct <string, string> > renamedAssemblyNames)
        {
            if (renamedAssemblyNames.Count == 0)
            {
                return;
            }

            foreach (BuildModule module in assembly.Modules)
            {
                if (!module.Image.IsILOnly)
                {
                    continue;
                }

                var generator = new RenamedAssemblyResolverGenerator(module);

                foreach (var renamedName in renamedAssemblyNames)
                {
                    generator.AddAssembly(renamedName.Item1, renamedName.Item2);
                }

                generator.Generate();
            }
        }