コード例 #1
0
        /// <summary>
        /// Returns the Assembly identity for the assembly name.
        /// </summary>
        /// <param name="assemblyName"></param>
        /// <param name="metadataHost"></param>
        /// <returns></returns>
        public static AssemblyIdentity GetAssemblyIdentity(System.Reflection.AssemblyName assemblyName, IMetadataHost metadataHost)
        {
            Contract.Requires(assemblyName != null);
            Contract.Requires(metadataHost != null);
            Contract.Ensures(Contract.Result <AssemblyIdentity>() != null);

            string culture = assemblyName.CultureInfo == null || assemblyName.CultureInfo == System.Globalization.CultureInfo.InvariantCulture ? "neutral" : assemblyName.CultureInfo.ToString();
            string name    = assemblyName.Name;

            if (name == null)
            {
                name = string.Empty;
            }
            Version version = assemblyName.Version;

            if (version == null)
            {
                version = Dummy.Version;
            }
            byte[] token = assemblyName.GetPublicKeyToken();
            if (token == null)
            {
                token = new byte[0];
            }
            var codeBase = assemblyName.CodeBase;

            if (codeBase == null)
            {
                codeBase = string.Empty;
            }
            return(new AssemblyIdentity(metadataHost.NameTable.GetNameFor(name), culture, version, token, codeBase));
        }
コード例 #2
0
ファイル: AssemblyInfo.cs プロジェクト: dox0/DotNet471RS3
        /*
         * public String SimpleName
         * {
         *  get { return m_SimpleName; }
         * }
         *
         * public String Culture
         * {
         *  get { return m_Culture; }
         * }
         */

        public AssemblyInfo(System.Reflection.AssemblyName AN)
        {
            m_Version = AN.Version;
            m_Flags   = (UInt32)AN.Flags;
            byte[] Token;
            if ((m_Flags & (UInt32)System.Reflection.AssemblyNameFlags.PublicKey) == 0)
            {
                Token = AN.GetPublicKeyToken();
            }
            else
            {
                Token = AN.GetPublicKey();
            }
            if ((Token != null) && (Token.Length == 0))
            {
                m_PublicKey = null;
            }
            else
            {
                m_PublicKey = Token;
            }
            m_SimpleName = AN.Name;
            m_Culture    = AN.CultureInfo.Name;
            if (m_Culture.Length == 0)
            {
                m_Culture = null;
            }
            m_FullName       = null;
            m_PublicKeyToken = null;
        }
コード例 #3
0
ファイル: Redirection.cs プロジェクト: fabrimaciel/colosoft
 /// <summary>
 /// Recupera o nome correto do assembly.
 /// </summary>
 /// <param name="original"></param>
 /// <param name="dic"></param>
 /// <returns></returns>
 public static System.Reflection.AssemblyName GetCorrectAssemblyName(System.Reflection.AssemblyName original, Dictionary <string, List <Redirection> > dic)
 {
     if (dic.ContainsKey(original.Name))
     {
         foreach (Redirection redirection in dic[original.Name])
         {
             if (redirection.BindingRedirection == null)
             {
                 System.Diagnostics.Trace.WriteLine("Redirection data is invalid: " + redirection.AssemblyIdentity);
             }
             else
             {
                 Version redirectVersionMin = redirection.BindingRedirection.OldVersionMin;
                 Version redirectVersionMax = redirection.BindingRedirection.OldVersionMax;
                 if ((original.Version >= redirectVersionMin) && (original.Version <= redirectVersionMax))
                 {
                     var name = new System.Reflection.AssemblyName(original.FullName);
                     name.Version = redirection.BindingRedirection.NewVersion;
                     name.ProcessorArchitecture = original.ProcessorArchitecture;
                     name.SetPublicKeyToken(original.GetPublicKeyToken());
                     return(name);
                 }
             }
         }
     }
     return(original);
 }
コード例 #4
0
        internal DefaultAssemblyName(ReflectionAssemblyName assemblyName)
        {
            _name = assemblyName.Name;
            if (string.IsNullOrEmpty(assemblyName.CultureName))
            {
                _cultureName = "neutral";
            }
            else
            {
                _cultureName = assemblyName.CultureName;
            }

            var pk = assemblyName.GetPublicKey();

            if (pk != null)
            {
                _publicKeyBlob = new Blob(pk);
            }

            pk = assemblyName.GetPublicKeyToken();
            if (pk != null)
            {
                _pkt = new Blob(pk);
            }

            _version = assemblyName.Version;
        }
コード例 #5
0
        public static bool Equals(IAssembly x, System.Reflection.AssemblyName y, SignatureComparisonFlags flags = SignatureComparisonFlags.None)
        {
            if (x == null || y == null)
            {
                return(false);
            }

            if (x.Name != y.Name)
            {
                return(false);
            }

            if ((flags & SignatureComparisonFlags.IgnoreAssemblyStrongName) != SignatureComparisonFlags.IgnoreAssemblyStrongName)
            {
                string culture = (y.CultureInfo != null) ? y.CultureInfo.Name : null;
                if (x.Culture != culture)
                {
                    return(false);
                }

                if (!Equals(x.Version, y.Version))
                {
                    return(false);
                }

                if (!Equals(x.PublicKeyToken, y.GetPublicKeyToken()))
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #6
0
        /// <summary>
        /// Returns the Assembly identity for the assembly name.
        /// </summary>
        /// <param name="assemblyName"></param>
        /// <param name="metadataHost"></param>
        /// <returns></returns>
        public static AssemblyIdentity GetAssemblyIdentity(System.Reflection.AssemblyName assemblyName, IMetadataHost metadataHost)
        {
            Contract.Requires(assemblyName != null);
            Contract.Requires(metadataHost != null);
            Contract.Ensures(Contract.Result <AssemblyIdentity>() != null);

            string culture = String.IsNullOrEmpty(assemblyName.CultureName) ? "neutral" : assemblyName.CultureName;
            string name    = assemblyName.Name;

            if (name == null)
            {
                name = string.Empty;
            }
            Version version = assemblyName.Version;

            if (version == null)
            {
                version = Dummy.Version;
            }
            byte[] token = assemblyName.GetPublicKeyToken();
            if (token == null)
            {
                token = new byte[0];
            }
#if COREFX_SUBSET
            string codeBase = null;
#else
            string codeBase = assemblyName.CodeBase;
#endif
            if (codeBase == null)
            {
                codeBase = string.Empty;
            }
            return(new AssemblyIdentity(metadataHost.NameTable.GetNameFor(name), culture, version, token, codeBase));
        }
コード例 #7
0
ファイル: MSBuildCompiler.cs プロジェクト: dbremner/specsharp
        public Assembly CompileProject(string projectFileName)
        {
            Assembly existing;
            if (Compilations.TryGetValue(Path.GetFullPath(projectFileName), out existing))
            {
                return existing;
            }

            var project = new Microsoft.Build.BuildEngine.Project();
            project.Load(projectFileName);

            var projectName = Environment.NameTable.GetNameFor(project.EvaluatedProperties["AssemblyName"].Value);
            var projectPath = project.FullFileName;
            var compilerOptions = new SpecSharpOptions();
            var assemblyReferences = new List<IAssemblyReference>();
            var moduleReferences = new List<IModuleReference>();
            var programSources = new List<SpecSharpSourceDocument>();
            var assembly = new SpecSharpAssembly(projectName, projectPath, Environment, compilerOptions, assemblyReferences, moduleReferences, programSources);
            var helper = new SpecSharpCompilationHelper(assembly.Compilation);

            Compilations[Path.GetFullPath(projectFileName)] = assembly;

            assemblyReferences.Add(Environment.LoadAssembly(Environment.CoreAssemblySymbolicIdentity));
            project.Build("ResolveAssemblyReferences");
            foreach (BuildItem item in project.GetEvaluatedItemsByName("ReferencePath"))
            {
                var assemblyName = new System.Reflection.AssemblyName(item.GetEvaluatedMetadata("FusionName"));
                var name = Environment.NameTable.GetNameFor(assemblyName.Name);
                var culture = assemblyName.CultureInfo != null ? assemblyName.CultureInfo.Name : "";
                var version = assemblyName.Version == null ? new Version(0, 0) : assemblyName.Version;
                var token = assemblyName.GetPublicKeyToken();
                if (token == null) token = new byte[0];
                var location = item.FinalItemSpec;
                var identity = new AssemblyIdentity(name, culture, version, token, location);
                var reference = Environment.LoadAssembly(identity);
                assemblyReferences.Add(reference);
            }

            foreach (BuildItem item in project.GetEvaluatedItemsByName("ProjectReference"))
            {
                var name = Environment.NameTable.GetNameFor(Path.GetFileNameWithoutExtension(item.FinalItemSpec));
                var location = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(project.FullFileName), item.FinalItemSpec));
                var reference = CompileProject(location);
                assemblyReferences.Add(reference);
            }

            foreach (BuildItem item in project.GetEvaluatedItemsByName("Compile"))
            {
                var location = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(project.FullFileName), item.FinalItemSpec));
                var name = Environment.NameTable.GetNameFor(location);
                var programSource = new SpecSharpSourceDocument(helper, name, location, File.ReadAllText(location));
                programSources.Add(programSource);
            }

            return assembly;
        }
コード例 #8
0
ファイル: UnitHelper.cs プロジェクト: tralivali1234/IL2JS
        /// <summary>
        /// Returns the Assembly identity for the assembly name.
        /// </summary>
        /// <param name="assemblyName"></param>
        /// <param name="metadataHost"></param>
        /// <returns></returns>
        public static AssemblyIdentity GetAssemblyIdentity(System.Reflection.AssemblyName assemblyName, IMetadataHost metadataHost)
        {
            string       culture = assemblyName.CultureInfo == null || assemblyName.CultureInfo == System.Globalization.CultureInfo.InvariantCulture ? "neutral" : assemblyName.CultureInfo.ToString();
            string /*?*/ name    = assemblyName.Name;
            //^ assume name != null;
            Version /*?*/ version = assemblyName.Version;

            //^ assume version != null;
            byte[] /*?*/ token = assemblyName.GetPublicKeyToken();
            //^ assume token != null;
            return(new AssemblyIdentity(metadataHost.NameTable.GetNameFor(name), culture, version, token, assemblyName.CodeBase == null ? "" : assemblyName.CodeBase));
        }
コード例 #9
0
        public static AssemblyIdentity Parse(INameTable nameTable, string formattedName)
        {
            var name = new System.Reflection.AssemblyName(formattedName);
            return new AssemblyIdentity(nameTable.GetNameFor(name.Name),
                                        name.CultureName,
                                        name.Version,
                                        name.GetPublicKeyToken(),
#if COREFX
                                        "");
#else
                                        name.CodeBase);
#endif
        }
コード例 #10
0
        public static AssemblyIdentity Parse(INameTable nameTable, string formattedName)
        {
            var name = new System.Reflection.AssemblyName(formattedName);

            return(new AssemblyIdentity(nameTable.GetNameFor(name.Name),
                                        name.CultureName,
                                        name.Version,
                                        name.GetPublicKeyToken(),
#if COREFX
                                        ""));
#else
                                        name.CodeBase);
#endif
        }
コード例 #11
0
 internal static bool IsAssemblyNameAssignmentSafe(string originalAssemblyName, string newAssemblyName)
 {
     if (originalAssemblyName == newAssemblyName)
     {
         return(true);
     }
     System.Reflection.AssemblyName assemblyName1 = new System.Reflection.AssemblyName(originalAssemblyName);
     System.Reflection.AssemblyName assemblyName2 = new System.Reflection.AssemblyName(newAssemblyName);
     if (string.Equals(assemblyName2.Name, "mscorlib", StringComparison.OrdinalIgnoreCase) || string.Equals(assemblyName2.Name, "mscorlib.dll", StringComparison.OrdinalIgnoreCase))
     {
         return(false);
     }
     return(SerializationInfo.Compare(assemblyName1.GetPublicKeyToken(), assemblyName2.GetPublicKeyToken()));
 }
コード例 #12
0
 static NetstandardAwareAssemblyResolver()
 {
     try
     {
         // To be sure to load information of "real" runtime netstandard implementation
         s_netStandardAssembly = System.Reflection.Assembly.LoadFile(Path.Combine(Path.GetDirectoryName(typeof(object).Assembly.Location), "netstandard.dll"));
         System.Reflection.AssemblyName name = s_netStandardAssembly.GetName();
         s_name               = name.Name;
         s_publicKeyToken     = name.GetPublicKeyToken();
         s_assemblyDefinition = AssemblyDefinition.ReadAssembly(s_netStandardAssembly.Location);
     }
     catch (FileNotFoundException)
     {
         // netstandard not supported
     }
 }
コード例 #13
0
 private static System.Reflection.Assembly Load(string assemblyNameVal) {
     System.Reflection.AssemblyName assemblyName = new System.Reflection.AssemblyName(assemblyNameVal);
     byte[] publicKeyToken = assemblyName.GetPublicKeyToken();
     System.Reflection.Assembly asm = null;
     try {
         asm = System.Reflection.Assembly.Load(assemblyName.FullName);
     }
     catch (System.Exception ) {
         System.Reflection.AssemblyName shortName = new System.Reflection.AssemblyName(assemblyName.Name);
         if ((publicKeyToken != null)) {
             shortName.SetPublicKeyToken(publicKeyToken);
         }
         asm = System.Reflection.Assembly.Load(shortName);
     }
     return asm;
 }
コード例 #14
0
 private static System.Reflection.Assembly Load(string assemblyNameVal) {
     System.Reflection.AssemblyName assemblyName = new System.Reflection.AssemblyName(assemblyNameVal);
     byte[] publicKeyToken = assemblyName.GetPublicKeyToken();
     System.Reflection.Assembly asm = null;
     try {
         asm = System.Reflection.Assembly.Load(assemblyName.FullName);
     }
     catch (System.Exception ) {
         System.Reflection.AssemblyName shortName = new System.Reflection.AssemblyName(assemblyName.Name);
         if ((publicKeyToken != null)) {
             shortName.SetPublicKeyToken(publicKeyToken);
         }
         asm = System.Reflection.Assembly.Load(shortName);
     }
     return asm;
 }
コード例 #15
0
        /// <summary>
        /// Returns the Assembly identity for the assembly name.
        /// </summary>
        /// <param name="assemblyName"></param>
        /// <param name="metadataHost"></param>
        /// <returns></returns>
        public static AssemblyIdentity GetAssemblyIdentity(System.Reflection.AssemblyName assemblyName, IMetadataHost metadataHost)
        {
            Contract.Requires(assemblyName != null);
            Contract.Requires(metadataHost != null);
            Contract.Ensures(Contract.Result <AssemblyIdentity>() != null);

            string culture = assemblyName.CultureInfo == null || assemblyName.CultureInfo == System.Globalization.CultureInfo.InvariantCulture ? "neutral" : assemblyName.CultureInfo.ToString();
            string name    = assemblyName.Name;

            Contract.Assume(name != null);
            Version version = assemblyName.Version;

            Contract.Assume(version != null);
            byte[] token = assemblyName.GetPublicKeyToken();
            Contract.Assume(token != null);
            return(new AssemblyIdentity(metadataHost.NameTable.GetNameFor(name), culture, version, token, assemblyName.CodeBase == null ? "" : assemblyName.CodeBase));
        }
        public static AssemblyIdentity Parse(INameTable nameTable, string formattedName)
        {
            var name = new System.Reflection.AssemblyName(formattedName);

            return(new AssemblyIdentity(nameTable.GetNameFor(name.Name),
#if FEATURE_ASSEMBLYNAME_CULTUREINFO
                                        name.CultureInfo.Name,
#else
                                        name.CultureName,
#endif
                                        name.Version,
                                        name.GetPublicKeyToken(),
#if FEATURE_ASSEMBLYNAME_CODEBASE
                                        name.CodeBase));
#else
                                        string.Empty);
#endif
        }
コード例 #17
0
        private static AssemblyInfo GetAssemblyInfo(string fileName)
        {
            AssemblyInfo result = null;

            try
            {
                System.Reflection.AssemblyName testAssembly =
                    System.Reflection.AssemblyName.GetAssemblyName(fileName);

                result = new AssemblyInfo(testAssembly.Name, testAssembly.Version.ToString(), Path.GetDirectoryName(fileName));

                if (testAssembly.CultureName == string.Empty)
                {
                    result.Culture = "neutral";
                }
                else
                {
                    result.Culture = testAssembly.CultureName;
                }

                result.FullName = testAssembly.FullName;

                result.PublicKeyToken = GetAssemblyPublickKeyToken(testAssembly.GetPublicKeyToken());

                Debug.WriteLine("File {0} was found and it is an assembly.", fileName);
            }

            catch (System.IO.FileNotFoundException)
            {
                Debug.WriteLine("The file {0} cannot be found.", fileName);
            }

            catch (System.BadImageFormatException)
            {
                Debug.WriteLine("The file {0} is not an assembly.", fileName);
            }

            catch (System.IO.FileLoadException)
            {
                Debug.WriteLine("The assembly {0} has already been loaded.", fileName);
            }

            return(result);
        }
コード例 #18
0
        private void InitializeScopeReference(AssemblyName assemblyName, ScopeReference scopeReference)
        {
            scopeReference.Name           = HandleString(assemblyName.Name);
            scopeReference.Culture        = HandleString(assemblyName.CultureName);
            scopeReference.MajorVersion   = checked ((ushort)assemblyName.Version.Major);
            scopeReference.MinorVersion   = checked ((ushort)assemblyName.Version.Minor);
            scopeReference.BuildNumber    = checked ((ushort)assemblyName.Version.Build);
            scopeReference.RevisionNumber = checked ((ushort)assemblyName.Version.Revision);

            Debug.Assert((int)AssemblyFlags.PublicKey == (int)AssemblyNameFlags.PublicKey);
            Debug.Assert((int)AssemblyFlags.Retargetable == (int)AssemblyNameFlags.Retargetable);

            // References use a public key token instead of full public key.
            scopeReference.Flags = (AssemblyFlags)(assemblyName.Flags & ~AssemblyNameFlags.PublicKey);

            if (assemblyName.ContentType == AssemblyContentType.WindowsRuntime)
            {
                scopeReference.Flags |= (AssemblyFlags)((int)AssemblyContentType.WindowsRuntime << 9);
            }

            scopeReference.PublicKeyOrToken = assemblyName.GetPublicKeyToken();
        }
コード例 #19
0
ファイル: Host.cs プロジェクト: edgar-pek/VCDryad
 internal HostEnvironment(int pointerSizeInBits)
     : base(new NameTable(), new InternFactory(), (byte)(pointerSizeInBits / 8), null, false)
 {
     Debug.Assert(pointerSizeInBits == 32 || pointerSizeInBits == 64);
       this.peReader = new PeReader(this);
       string loc = typeof(object).Assembly.Location;
       System.Reflection.AssemblyName mscorlibName = new System.Reflection.AssemblyName(typeof(object).Assembly.FullName);
       var tempMscorlibIdentity = new AssemblyIdentity(this.NameTable.GetNameFor(mscorlibName.Name), "", mscorlibName.Version, mscorlibName.GetPublicKeyToken(), loc);
       this.RegisterAsLatest(this.peReader.OpenAssembly(BinaryDocument.GetBinaryDocumentForFile(tempMscorlibIdentity.Location, this), out this.mscorlibIdentity));
       loc = typeof(Microsoft.Research.Vcc.Runtime).Assembly.Location;
       System.Reflection.AssemblyName runtimeName = new System.Reflection.AssemblyName(typeof(Microsoft.Research.Vcc.Runtime).Assembly.FullName);
       var tempVccRuntimeAssemblyIdentity = new AssemblyIdentity(this.NameTable.GetNameFor(runtimeName.Name), "", runtimeName.Version, runtimeName.GetPublicKeyToken(), loc);
       this.RegisterAsLatest(this.peReader.OpenAssembly(BinaryDocument.GetBinaryDocumentForFile(tempVccRuntimeAssemblyIdentity.Location, this), out this.vccRuntimeAssemblyIdentity));
 }
コード例 #20
0
        public Assembly CompileProject(string projectFileName)
        {
            Assembly existing;

            if (Compilations.TryGetValue(Path.GetFullPath(projectFileName), out existing))
            {
                return(existing);
            }

            var project = new Microsoft.Build.BuildEngine.Project();

            project.Load(projectFileName);

            var projectName        = Environment.NameTable.GetNameFor(project.EvaluatedProperties["AssemblyName"].Value);
            var projectPath        = project.FullFileName;
            var compilerOptions    = new SpecSharpOptions();
            var assemblyReferences = new List <IAssemblyReference>();
            var moduleReferences   = new List <IModuleReference>();
            var programSources     = new List <SpecSharpSourceDocument>();
            var assembly           = new SpecSharpAssembly(projectName, projectPath, Environment, compilerOptions, assemblyReferences, moduleReferences, programSources);
            var helper             = new SpecSharpCompilationHelper(assembly.Compilation);

            Compilations[Path.GetFullPath(projectFileName)] = assembly;

            assemblyReferences.Add(Environment.LoadAssembly(Environment.CoreAssemblySymbolicIdentity));
            project.Build("ResolveAssemblyReferences");
            foreach (BuildItem item in project.GetEvaluatedItemsByName("ReferencePath"))
            {
                var assemblyName = new System.Reflection.AssemblyName(item.GetEvaluatedMetadata("FusionName"));
                var name         = Environment.NameTable.GetNameFor(assemblyName.Name);
                var culture      = assemblyName.CultureInfo != null ? assemblyName.CultureInfo.Name : "";
                var version      = assemblyName.Version == null ? new Version(0, 0) : assemblyName.Version;
                var token        = assemblyName.GetPublicKeyToken();
                if (token == null)
                {
                    token = new byte[0];
                }
                var location  = item.FinalItemSpec;
                var identity  = new AssemblyIdentity(name, culture, version, token, location);
                var reference = Environment.LoadAssembly(identity);
                assemblyReferences.Add(reference);
            }

            foreach (BuildItem item in project.GetEvaluatedItemsByName("ProjectReference"))
            {
                var name      = Environment.NameTable.GetNameFor(Path.GetFileNameWithoutExtension(item.FinalItemSpec));
                var location  = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(project.FullFileName), item.FinalItemSpec));
                var reference = CompileProject(location);
                assemblyReferences.Add(reference);
            }

            foreach (BuildItem item in project.GetEvaluatedItemsByName("Compile"))
            {
                var location      = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(project.FullFileName), item.FinalItemSpec));
                var name          = Environment.NameTable.GetNameFor(location);
                var programSource = new SpecSharpSourceDocument(helper, name, location, File.ReadAllText(location));
                programSources.Add(programSource);
            }

            return(assembly);
        }
コード例 #21
0
ファイル: MiniAssembly.cs プロジェクト: JianwenSun/cc
        public MiniAssembly ResolveAssemblyRef(MetadataToken token, bool throwOnError)
        {
            System.Diagnostics.Contracts.Contract.Requires(token.Table == MDTables.Tables.AssemblyRef);
            PEFileReader peFile = this.PEFileReader;
            MDTables metaData = peFile.MetaData;

            metaData.SeekToMDToken(token);
            peFile.B.ReadUInt64();  // Skip 4 parts of the version number.
            peFile.B.ReadUInt32();  // AssemblyFlags
            byte[] publicKeyOrToken = metaData.ReadBlob(); // Public key or token
            String assemblySimpleName = metaData.ReadString(); // simple name
            String cultureName = metaData.ReadString();  // assembly culture
            if (!String.IsNullOrEmpty(cultureName))
                throw new BadImageFormatException(Res.UnexpectedlyLoadingASatellite, FullName);

            if (assemblySimpleName == "mscorlib" && (cultureName.Length == 0 || cultureName == "neutral"))
                return new MiniAssembly(typeof(Object).Assembly);

            MiniAssembly loadedAssembly = Open(assemblySimpleName, _dependencyDirs, throwOnError);

            if (loadedAssembly != null)
            {
                // Check whether the reference to the assembly matches what we actually loaded.
                // We don't respect the "throwOnError" parameter here because if someone does
                // violate this, they've either severely messed up their deployment, or they're
                // attempting a security exploit.
                System.Reflection.AssemblyName loadedAssemblyName = 
                    new System.Reflection.AssemblyName(loadedAssembly.FullName);

                if (!Utils.PublicKeyMatches(loadedAssemblyName, publicKeyOrToken))
                {
                    throw new FileLoadException(String.Format(CultureInfo.CurrentCulture, Res.AssemblyLoadRefDefMismatch, 
                        assemblySimpleName, publicKeyOrToken, loadedAssemblyName.GetPublicKeyToken()));
                }

                if (!String.IsNullOrEmpty(loadedAssemblyName.CultureInfo.Name))
                {
                    throw new FileLoadException(String.Format(CultureInfo.CurrentCulture, Res.AssemblyLoadRefDefMismatch,
                        assemblySimpleName, String.Empty, loadedAssemblyName.CultureInfo.Name));
                }
            }
            return loadedAssembly;
        }
コード例 #22
0
        public MiniAssembly ResolveAssemblyRef(MetadataToken token, bool throwOnError)
        {
            System.Diagnostics.Contracts.Contract.Requires(token.Table == MDTables.Tables.AssemblyRef);
            PEFileReader peFile   = this.PEFileReader;
            MDTables     metaData = peFile.MetaData;

            metaData.SeekToMDToken(token);
            peFile.B.ReadUInt64();                             // Skip 4 parts of the version number.
            peFile.B.ReadUInt32();                             // AssemblyFlags
            byte[] publicKeyOrToken   = metaData.ReadBlob();   // Public key or token
            String assemblySimpleName = metaData.ReadString(); // simple name
            String cultureName        = metaData.ReadString(); // assembly culture

            if (!String.IsNullOrEmpty(cultureName))
            {
                throw new BadImageFormatException(Res.UnexpectedlyLoadingASatellite, FullName);
            }

            if (assemblySimpleName == "mscorlib" && (cultureName.Length == 0 || cultureName == "neutral"))
            {
                return(new MiniAssembly(typeof(Object).Assembly));
            }

            MiniAssembly loadedAssembly = Open(assemblySimpleName, _dependencyDirs, throwOnError);

            if (loadedAssembly != null)
            {
                // Check whether the reference to the assembly matches what we actually loaded.
                // We don't respect the "throwOnError" parameter here because if someone does
                // violate this, they've either severely messed up their deployment, or they're
                // attempting a security exploit.
                System.Reflection.AssemblyName loadedAssemblyName =
                    new System.Reflection.AssemblyName(loadedAssembly.FullName);

                if (!Utils.PublicKeyMatches(loadedAssemblyName, publicKeyOrToken))
                {
                    throw new FileLoadException(String.Format(CultureInfo.CurrentCulture, Res.AssemblyLoadRefDefMismatch,
                                                              assemblySimpleName, publicKeyOrToken, loadedAssemblyName.GetPublicKeyToken()));
                }

                if (!String.IsNullOrEmpty(loadedAssemblyName.CultureInfo.Name))
                {
                    throw new FileLoadException(String.Format(CultureInfo.CurrentCulture, Res.AssemblyLoadRefDefMismatch,
                                                              assemblySimpleName, String.Empty, loadedAssemblyName.CultureInfo.Name));
                }
            }
            return(loadedAssembly);
        }
コード例 #23
0
 public byte[] GetPublicKeyToken()
 {
     return(name.GetPublicKeyToken());
 }
コード例 #24
0
ファイル: Host.cs プロジェクト: tupipa/vcc
        internal HostEnvironment(int pointerSizeInBits)
            : base(new NameTable(), new InternFactory(), (byte)(pointerSizeInBits / 8), null, false)
        {
            Debug.Assert(pointerSizeInBits == 32 || pointerSizeInBits == 64);
            this.peReader = new PeReader(this);
            string loc = typeof(object).Assembly.Location;

            System.Reflection.AssemblyName mscorlibName = new System.Reflection.AssemblyName(typeof(object).Assembly.FullName);
            var tempMscorlibIdentity = new AssemblyIdentity(this.NameTable.GetNameFor(mscorlibName.Name), "", mscorlibName.Version, mscorlibName.GetPublicKeyToken(), loc);

            this.RegisterAsLatest(this.peReader.OpenAssembly(BinaryDocument.GetBinaryDocumentForFile(tempMscorlibIdentity.Location, this), out this.mscorlibIdentity));
            loc = typeof(Microsoft.Research.Vcc.Runtime).Assembly.Location;
            System.Reflection.AssemblyName runtimeName = new System.Reflection.AssemblyName(typeof(Microsoft.Research.Vcc.Runtime).Assembly.FullName);
            var tempVccRuntimeAssemblyIdentity         = new AssemblyIdentity(this.NameTable.GetNameFor(runtimeName.Name), "", runtimeName.Version, runtimeName.GetPublicKeyToken(), loc);

            this.RegisterAsLatest(this.peReader.OpenAssembly(BinaryDocument.GetBinaryDocumentForFile(tempVccRuntimeAssemblyIdentity.Location, this), out this.vccRuntimeAssemblyIdentity));
        }
コード例 #25
0
    internal HostEnvironment()
      : base(new NameTable(), new InternFactory(), 0, null, true) {
      this.peReader = new PeReader(this);
      string/*?*/ loc = typeof(object).Assembly.Location;
      if (loc == null) loc = "";
      System.Reflection.AssemblyName coreAssemblyName = new System.Reflection.AssemblyName(typeof(object).Assembly.FullName);
      this.coreAssemblySymbolicIdentity =
        new AssemblyIdentity(this.NameTable.GetNameFor(coreAssemblyName.Name), "", coreAssemblyName.Version, coreAssemblyName.GetPublicKeyToken(), loc);
      this.RegisterAsLatest(this.peReader.OpenAssembly(BinaryDocument.GetBinaryDocumentForFile(loc, this)));
      loc = typeof(Microsoft.SmallBasic.Library.ConsoleTextColor).Assembly.Location;
      if (loc == null) loc = "";
      //System.Reflection.AssemblyName runtimeName = new System.Reflection.AssemblyName(typeof(Microsoft.SmallBasic.Library.ConsoleTextColor).Assembly.FullName);
      //this.smallBasicRuntimeAssemblyIdentity =
      //  new AssemblyIdentity(this.NameTable.GetNameFor(runtimeName.Name), "", runtimeName.Version, runtimeName.GetPublicKeyToken(), loc);
      this.RegisterAsLatest(this.peReader.OpenAssembly(BinaryDocument.GetBinaryDocumentForFile(loc, this)));

    }
コード例 #26
0
ファイル: AboutDialog.cs プロジェクト: abdullah-19/megaide
        /// <summary>
        /// Required designer variable.
        /// </summary>

        private AboutDialogClass()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            userNameLabel.Text     = System.Environment.UserName;
            computerNameLabel.Text = System.Environment.MachineName;

            OperatingSystem osInfo = Environment.OSVersion;
            string          osName = "UNKNOWN";

            switch (osInfo.Platform)
            {
            case PlatformID.Win32Windows:
            {
                switch (osInfo.Version.Minor)
                {
                case 0:
                {
                    osName = "Windows 95";
                    break;
                }

                case 10:
                {
                    if (osInfo.Version.Revision.ToString() == "2222A")
                    {
                        osName = "Windows 98 SE";
                    }
                    else
                    {
                        osName = "Windows 98";
                    }
                    break;
                }

                case 90:
                {
                    osName = "Windows Me";
                    break;
                }
                }
                break;
            }

            case PlatformID.Win32NT:
            {
                switch (osInfo.Version.Major)
                {
                case 3:
                {
                    osName = "Windows NT 3.51";
                    break;
                }

                case 4:
                {
                    osName = "Windows NT 4.0";
                    break;
                }

                case 5:
                {
                    if (osInfo.Version.Minor == 0)
                    {
                        osName = "Windows 2000";
                    }
                    else if (osInfo.Version.Minor == 1)
                    {
                        osName = "Windows XP";
                    }
                    else if (osInfo.Version.Minor == 2)
                    {
                        osName = "Windows Server 2003";
                    }
                    break;
                }

                case 6:
                {
                    osName = "Windows Vista";
                    break;
                }
                }
                break;
            }
            }
            osLabel.Text = "Operating System : " + osName;
            NETXP.Win32.API.MEMORYSTATUS memoryStatus = new NETXP.Win32.API.MEMORYSTATUS();
            NETXP.Win32.API.GlobalMemoryStatus(memoryStatus);
            memoryLabel.Text   = "Physical Memory : " + (memoryStatus.dwTotalPhys / (1023 * 1023)).ToString("0 MB");
            assemblyLabel.Text = "Total " + AppDomain.CurrentDomain.GetAssemblies().Length + " assemblies loaded !";
            foreach (System.Reflection.Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                System.Reflection.AssemblyName assemblyName = assembly.GetName();
                ListViewItem assemblyItem;
                if (assemblyName.Name == "MegaIDE")
                {
                    versionLabel.Text = "Version : " + assemblyName.Version.Major + "." + assemblyName.Version.Minor + "    Build : " + assemblyName.Version.Build.ToString() + "    Revision : " + assemblyName.Version.Revision;
                }
                if (assemblyName.GetPublicKeyToken() != null)
                {
                    assemblyItem = new ListViewItem(new String[] { assemblyName.Name, assemblyName.Version.ToString(), ToHexString(assemblyName.GetPublicKeyToken()) }, 0);
                }
                else
                {
                    assemblyItem = new ListViewItem(new String[] { assemblyName.Name, assemblyName.Version.ToString(), "null" }, 0);
                }
                assemblyList.Items.Add(assemblyItem);
            }
            assemblyList.Columns[0].Width = -1;
            assemblyList.Columns[1].Width = -1;
            assemblyList.Columns[2].Width = -2;
        }
コード例 #27
0
 public static string PublicKeyToken(this System.Reflection.AssemblyName assemblyName) => string.Join("", assemblyName.GetPublicKeyToken().Select(b => b.ToString("x2")));