示例#1
0
        internal static AssemblyReference LoadRef(Module module, int rid)
        {
            var image = module.Image;

            var assemblyRef = image.AssemblyRefSignatures[rid - 1];

            if (assemblyRef != null)
            {
                return(assemblyRef);
            }

            AssemblyRefRow row;

            image.GetAssemblyRef(rid, out row);

            assemblyRef          = new AssemblyReference();
            assemblyRef._name    = image.GetString(row.Name);
            assemblyRef._culture = image.GetString(row.Locale);
            assemblyRef._processorArchitecture = (ProcessorArchitecture)((int)(row.Flags & AssemblyFlags.PA_Mask) >> (int)AssemblyFlags.PA_Shift);
            assemblyRef._version = new Version(row.MajorVersion, row.MinorVersion, row.BuildNumber, row.RevisionNumber);

            byte[] publicKeyToken = image.GetBlob(row.PublicKeyOrToken).NullIfEmpty();
            if ((row.Flags & AssemblyFlags.PublicKey) == AssemblyFlags.PublicKey &&
                publicKeyToken != null && publicKeyToken.Length > 0)
            {
                try
                {
                    publicKeyToken = StrongNameUtils.CreateTokenFromPublicKey(publicKeyToken);
                }
                catch (InvalidOperationException)
                {
                    publicKeyToken = null;
                }
            }

            assemblyRef._publicKeyToken = publicKeyToken;

            module.AddSignature(ref assemblyRef);
            image.AssemblyRefSignatures[rid - 1] = assemblyRef;

            return(assemblyRef);
        }
示例#2
0
        private void Initialize(Version version)
        {
            _version          = version;
            _mscorlibAssembly = new AssemblyReference("mscorlib", null, version, CodeModelUtils.EcmaPublicKeyToken);
            _systemAssembly   = new AssemblyReference("System", null, version, CodeModelUtils.EcmaPublicKeyToken);

            if (_isFrameworkInstalled)
            {
                string versionKey = version.Major + "." + version.Minor;
                foreach (string installPath in Directory.GetDirectories(_installRootPath))
                {
                    if (installPath.Contains(versionKey))
                    {
                        _isInstalled = true;
                        _installPath = installPath;
                        break;
                    }
                }
            }
        }
示例#3
0
        private void Initialize(Version version)
        {
            _version          = version;
            _mscorlibAssembly = new AssemblyReference("mscorlib", null, version, CodeModelUtils.EcmaPublicKeyToken);
            _systemAssembly   = new AssemblyReference("System", null, version, CodeModelUtils.EcmaPublicKeyToken);

            if (_isFrameworkInstalled)
            {
                string versionString = GetCurrentVersionString();
                if (!string.IsNullOrEmpty(versionString))
                {
                    string installPath = Path.Combine(_installRootPath, versionString);
                    if (Directory.Exists(installPath))
                    {
                        _isInstalled = true;
                        _installPath = installPath;
                    }
                }
            }
        }
示例#4
0
        protected void Load()
        {
            var image = _module.Image;

            ManifestResourceRow row;

            image.GetManifestResource(_rid, out row);

            _name       = image.GetString(row.Name);
            _visibility = (ResourceVisibilityFlags)row.Flags;
            _offset     = row.Offset;

            int implementationToken = MetadataToken.DecompressImplementation(row.Implementation);

            switch (MetadataToken.GetType(implementationToken))
            {
            case MetadataTokenType.AssemblyRef:
            {
                int rid = MetadataToken.GetRID(implementationToken);
                _owner = AssemblyReference.LoadRef(_module, rid);
            }
            break;

            case MetadataTokenType.File:
            {
                int rid = MetadataToken.GetRID(implementationToken);
                _owner = FileReference.Load(_module, rid);
            }
            break;

            default:
            {
                _opFlags = _opFlags.SetBitAtIndex(LoadDataFromImageFlag, true);
            }
            break;
            }
        }
示例#5
0
        public static AssemblyReference GetAssemblyName(PEImage pe)
        {
            var metadata = MemoryMappedMetadata.Load(pe);

            AssemblyRow row;

            metadata.GetAssembly(1, out row);

            var assemblyRef = new AssemblyReference();

            assemblyRef._name    = metadata.GetString(row.Name);
            assemblyRef._culture = metadata.GetString(row.Locale);
            assemblyRef._processorArchitecture = (ProcessorArchitecture)((int)(row.Flags & AssemblyFlags.PA_Mask) >> (int)AssemblyFlags.PA_Shift);
            assemblyRef._version = new Version(row.MajorVersion, row.MinorVersion, row.BuildNumber, row.RevisionNumber);

            var publicKey = metadata.GetBlob(row.PublicKey);

            if (publicKey != null && publicKey.Length > 0)
            {
                assemblyRef._publicKeyToken = StrongNameUtils.CreateTokenFromPublicKey(publicKey);
            }

            return(assemblyRef);
        }
示例#6
0
        private static Signature LoadExportedTypeImplementation(Module module, int token)
        {
            int rid = MetadataToken.GetRID(token);

            if (rid == 0)
            {
                return(null);
            }

            switch (MetadataToken.GetType(token))
            {
            case MetadataTokenType.File:
                return(ModuleReference.LoadFile(module, rid));

            case MetadataTokenType.AssemblyRef:
                return(AssemblyReference.LoadRef(module, rid));

            case MetadataTokenType.ExportedType:
                return(LoadExportedType(module, rid));

            default:
                throw new AssemblyLoadException(string.Format(SR.AssemblyLoadError, module.Location));
            }
        }
示例#7
0
 public virtual bool Build(ref AssemblyReference assemblyRef)
 {
     return(false);
 }
 public virtual void Visit(AssemblyReference assemblyRef)
 {
 }
示例#9
0
 public virtual bool Predicate(AssemblyReference assemblyRef)
 {
     return(_defaultValue);
 }