示例#1
0
 private MetadataReader GetSystemModuleMetadataReader()
 {
     if (_systemModuleReader == null)
     {
         if (_assemblyResolver != null)
         {
             _systemModuleReader = _assemblyResolver.FindAssembly(SystemModuleName, Filename);
         }
     }
     return(_systemModuleReader);
 }
示例#2
0
        /// <summary>
        /// Open a given reference assembly (relative to this ECMA metadata file).
        /// </summary>
        /// <param name="refAsmIndex">Reference assembly index</param>
        /// <returns>EcmaMetadataReader instance representing the reference assembly</returns>
        public EcmaMetadataReader OpenReferenceAssembly(int refAsmIndex)
        {
            if (refAsmIndex == 0)
            {
                return(this);
            }

            int    assemblyRefCount = MetadataReader.GetTableRowCount(TableIndex.AssemblyRef);
            string name;

            if (refAsmIndex <= assemblyRefCount)
            {
                AssemblyReference asmRef = MetadataReader.GetAssemblyReference(MetadataTokens.AssemblyReferenceHandle(refAsmIndex));
                name = MetadataReader.GetString(asmRef.Name);
            }
            else
            {
                name = ManifestReferenceAssemblies[refAsmIndex - assemblyRefCount - 2];
            }

            EcmaMetadataReader ecmaReader;

            if (!_assemblyCache.TryGetValue(name, out ecmaReader))
            {
                string assemblyPath = _assemblyResolver.FindAssembly(name, Filename);
                if (assemblyPath == null)
                {
                    throw new Exception($"Missing reference assembly: {name}");
                }
                ecmaReader = new EcmaMetadataReader(_assemblyResolver, assemblyPath, ManifestReferenceAssemblies);
                _assemblyCache.Add(name, ecmaReader);
            }
            return(ecmaReader);
        }
示例#3
0
        /// <summary>
        /// Open a given reference assembly (relative to this ECMA metadata file).
        /// </summary>
        /// <param name="refAsmIndex">Reference assembly index</param>
        /// <returns>MetadataReader instance representing the reference assembly</returns>
        internal MetadataReader OpenReferenceAssembly(int refAsmIndex)
        {
            if (refAsmIndex == 0)
            {
                return(this.MetadataReader);
            }

            MetadataReader result;

            if (!_assemblyCache.TryGetValue(refAsmIndex, out result))
            {
                AssemblyReferenceHandle assemblyReferenceHandle = GetAssemblyAtIndex(refAsmIndex, out MetadataReader metadataReader);

                result = _assemblyResolver.FindAssembly(metadataReader, assemblyReferenceHandle, Filename);
                if (result == null)
                {
                    string name = metadataReader.GetString(metadataReader.GetAssemblyReference(assemblyReferenceHandle).Name);
                    throw new Exception($"Missing reference assembly: {name}");
                }
                _assemblyCache.Add(refAsmIndex, result);
            }
            return(result);
        }
示例#4
0
        /// <summary>
        /// Open a given reference assembly (relative to this ECMA metadata file).
        /// </summary>
        /// <param name="refAsmIndex">Reference assembly index</param>
        /// <returns>MetadataReader instance representing the reference assembly</returns>
        internal MetadataReader OpenReferenceAssembly(int refAsmIndex)
        {
            if (refAsmIndex == 0)
            {
                return(this.MetadataReader);
            }

            int                     assemblyRefCount = MetadataReader.GetTableRowCount(TableIndex.AssemblyRef);
            MetadataReader          metadataReader;
            AssemblyReferenceHandle assemblyReferenceHandle;

            if (refAsmIndex <= assemblyRefCount)
            {
                metadataReader          = MetadataReader;
                assemblyReferenceHandle = MetadataTokens.AssemblyReferenceHandle(refAsmIndex);
            }
            else
            {
                metadataReader          = _manifestReader;
                assemblyReferenceHandle = _manifestReferences[refAsmIndex - assemblyRefCount - 2];
            }


            MetadataReader result;

            if (!_assemblyCache.TryGetValue(refAsmIndex, out result))
            {
                result = _assemblyResolver.FindAssembly(metadataReader, assemblyReferenceHandle, Filename);
                if (result == null)
                {
                    string name = metadataReader.GetString(metadataReader.GetAssemblyReference(assemblyReferenceHandle).Name);
                    throw new Exception($"Missing reference assembly: {name}");
                }
                _assemblyCache.Add(refAsmIndex, result);
            }
            return(result);
        }
示例#5
0
        /// <summary>
        /// Initialize generic method instances with argument types and runtime function indices from InstanceMethodEntrypoints
        /// </summary>
        private void ParseInstanceMethodEntrypoints(bool[] isEntryPoint)
        {
            if (!ReadyToRunHeader.Sections.TryGetValue(ReadyToRunSectionType.InstanceMethodEntryPoints, out ReadyToRunSection instMethodEntryPointSection))
            {
                return;
            }
            int             instMethodEntryPointsOffset = GetOffset(instMethodEntryPointSection.RelativeVirtualAddress);
            NativeParser    parser = new NativeParser(Image, (uint)instMethodEntryPointsOffset);
            NativeHashtable instMethodEntryPoints = new NativeHashtable(Image, parser, (uint)(instMethodEntryPointsOffset + instMethodEntryPointSection.Size));

            NativeHashtable.AllEntriesEnumerator allEntriesEnum = instMethodEntryPoints.EnumerateAllEntries();
            NativeParser curParser = allEntriesEnum.GetNext();

            while (!curParser.IsNull())
            {
                SignatureDecoder decoder  = new SignatureDecoder(_assemblyResolver, this, (int)curParser.Offset);
                MetadataReader   mdReader = _composite ? null : _assemblyCache[0];

                string owningType = null;

                uint methodFlags = decoder.ReadUInt();
                if ((methodFlags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType) != 0)
                {
                    mdReader = decoder.GetMetadataReaderFromModuleOverride();
                    if (mdReader == null)
                    {
                        // The only types that don't have module overrides on them in composite images are primitive types within System.Private.CoreLib
                        mdReader = _assemblyResolver.FindAssembly("System.Private.CoreLib", Filename);
                    }
                    owningType = decoder.ReadTypeSignatureNoEmit();
                }
                if ((methodFlags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_SlotInsteadOfToken) != 0)
                {
                    throw new NotImplementedException();
                }
                EntityHandle methodHandle;
                int          rid = (int)decoder.ReadUInt();
                if ((methodFlags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_MemberRefToken) != 0)
                {
                    methodHandle = MetadataTokens.MemberReferenceHandle(rid);
                }
                else
                {
                    methodHandle = MetadataTokens.MethodDefinitionHandle(rid);
                }
                string[] methodTypeArgs = null;
                if ((methodFlags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_MethodInstantiation) != 0)
                {
                    uint typeArgCount = decoder.ReadUInt();
                    methodTypeArgs = new string[typeArgCount];
                    for (int typeArgIndex = 0; typeArgIndex < typeArgCount; typeArgIndex++)
                    {
                        methodTypeArgs[typeArgIndex] = decoder.ReadTypeSignatureNoEmit();
                    }
                }

                string constrainedType = null;
                if ((methodFlags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_Constrained) != 0)
                {
                    constrainedType = decoder.ReadTypeSignatureNoEmit();
                }

                int runtimeFunctionId;
                int?fixupOffset;
                GetRuntimeFunctionIndexFromOffset((int)decoder.Offset, out runtimeFunctionId, out fixupOffset);
                ReadyToRunMethod method = new ReadyToRunMethod(
                    this,
                    Methods.Count,
                    mdReader,
                    methodHandle,
                    runtimeFunctionId,
                    owningType,
                    constrainedType,
                    methodTypeArgs,
                    fixupOffset);
                if (method.EntryPointRuntimeFunctionId >= 0 && method.EntryPointRuntimeFunctionId < isEntryPoint.Length)
                {
                    isEntryPoint[method.EntryPointRuntimeFunctionId] = true;
                }
                Methods.Add(method);
                InstanceMethods.Add(new InstanceMethod(curParser.LowHashcode, method));
                curParser = allEntriesEnum.GetNext();
            }
        }
示例#6
0
 private MetadataReader GetSystemModuleMetadataReader() =>
 _systemModuleReader ??= _assemblyResolver.FindAssembly(SystemModuleName, Filename);