示例#1
0
        public AssemblyBinaryProperties InferAssemblyBinaryProperties()
        {
            AssemblyBinaryProperties binaryProperties = Utilities.CreateAssemblyInspector((IInputValues)this).GetAssemblyBinaryProperties(this.InputFileName);

            if (this.Cpu == CpuPlatform.None && binaryProperties.BinaryWasScanned)
            {
                this.Cpu = binaryProperties.CpuPlatform;
            }
            return(binaryProperties);
        }
        public AssemblyBinaryProperties GetAssemblyBinaryProperties(string assemblyFileName)
        {
            if (!File.Exists(assemblyFileName))
            {
                return(AssemblyBinaryProperties.GetEmpty());
            }

            AssemblyDefinition assemblyDefinition = LoadAssembly(assemblyFileName);
            ModuleDefinition   mainModule         = assemblyDefinition.MainModule;

            string keyFileName  = null;
            string keyContainer = null;

            foreach (CustomAttribute customAttribute in assemblyDefinition.CustomAttributes)
            {
                switch (customAttribute.Constructor.DeclaringType.FullName)
                {
                case "System.Reflection.AssemblyKeyFileAttribute":
                    keyFileName = Convert.ToString(customAttribute.ConstructorArguments[0], CultureInfo.InvariantCulture);
                    break;

                case "System.Reflection.AssemblyKeyNameAttribute":
                    keyContainer = Convert.ToString(customAttribute.ConstructorArguments[0], CultureInfo.InvariantCulture);
                    break;
                }

                if (!string.IsNullOrEmpty(keyFileName) && !string.IsNullOrEmpty(keyContainer))
                {
                    break;
                }
            }

            try
            {
                return(new AssemblyBinaryProperties
                       (
                           mainModule.Attributes,
                           mainModule.Architecture,
                           assemblyDefinition.Name.HasPublicKey,
                           keyFileName,
                           keyContainer
                       ));
            }
            finally
            {
                assemblyDefinition.Dispose(); // 0.10.x
            }
        }
        public AssemblyBinaryProperties GetAssemblyBinaryProperties(
            string assemblyFileName)
        {
            AssemblyBinaryProperties binaryProperties;

            if (!File.Exists(assemblyFileName))
            {
                binaryProperties = AssemblyBinaryProperties.GetEmpty();
            }
            else
            {
                AssemblyDefinition assemblyDefinition = this.LoadAssembly(assemblyFileName);
                ModuleDefinition   mainModule         = assemblyDefinition.MainModule;
                string             keyFileName        = (string)null;
                string             keyContainer       = (string)null;
                foreach (CustomAttribute customAttribute in assemblyDefinition.CustomAttributes)
                {
                    switch (customAttribute.Constructor.DeclaringType.FullName)
                    {
                    case "System.Reflection.AssemblyKeyFileAttribute":
                        keyFileName = Convert.ToString((object)customAttribute.ConstructorArguments[0], (IFormatProvider)CultureInfo.InvariantCulture);
                        break;

                    case "System.Reflection.AssemblyKeyNameAttribute":
                        keyContainer = Convert.ToString((object)customAttribute.ConstructorArguments[0], (IFormatProvider)CultureInfo.InvariantCulture);
                        break;
                    }
                    if (!string.IsNullOrEmpty(keyFileName))
                    {
                        if (!string.IsNullOrEmpty(keyContainer))
                        {
                            break;
                        }
                    }
                }
                binaryProperties = new AssemblyBinaryProperties(mainModule.Attributes, mainModule.Architecture, assemblyDefinition.Name.HasPublicKey, keyFileName, keyContainer);
            }
            return(binaryProperties);
        }