public unsafe static MetadataScope Load(PEImage pe, out CorHeader corHeader)
        {
            var dd = pe.Directories[DataDirectories.CLIHeader];

            if (dd.IsNull)
            {
                throw new BadImageFormatException(string.Format(SR.MetadataImageNotValid, pe.Location));
            }

            var metadata = new MetadataScope();

            using (var accessor = pe.OpenImageToSectionData(dd.RVA))
            {
                fixed(byte *pBuff = accessor.ReadBytes(sizeof(CorHeader)))
                {
                    corHeader = *(CorHeader *)pBuff;
                }

                if (corHeader.Cb != MetadataConstants.CorHeaderSignature)
                {
                    throw new BadImageFormatException(string.Format(SR.MetadataImageNotValid, pe.Location));
                }

                accessor.Position = pe.ResolvePositionToSectionData(corHeader.Metadata.RVA);
                metadata.Read(accessor);
            }

            return(metadata);
        }
Пример #2
0
 private static void LoadTableIndexSizes(TableCompressionInfo info, MetadataScope metadata, int[] rowCounts)
 {
     for (int i = 0; i < MetadataConstants.TableCount; i++)
     {
         info.TableRowIndexSize4[i] = (rowCounts[i] >= (1 << 16));
     }
 }
        internal MetadataTableStream(MetadataScope metadata)
        {
            _metadata    = metadata;
            _isOptimized = true;
            _sortMask    = 0xffffffffffffffff;

            InitializeTables();
        }
Пример #4
0
        private static void LoadCodedTokenDataSizes(TableCompressionInfo info, MetadataScope metadata, int[] rowCounts)
        {
            for (int i = 0; i < MetadataConstants.CodedTokenCount; i++)
            {
                int maxRowCount    = 0;
                int codedTokenType = i + CodedTokenType.TypeDefOrRef;
                var token          = CodedTokenInfo.Get(codedTokenType);

                for (int j = 0; j < token.TokenTypes.Length; j++)
                {
                    int tableType = MetadataToken.GetTableTypeByTokenType(token.TokenTypes[j]);

                    int rowCount = rowCounts[tableType];
                    if (maxRowCount < rowCount)
                    {
                        maxRowCount = rowCount;
                    }
                }

                info.CodedTokenDataSize4[i] = (maxRowCount >= (1 << (16 - token.Tag)));
            }
        }
Пример #5
0
        public static TableCompressionInfo Create(MetadataScope metadata)
        {
            var info = new TableCompressionInfo();

            var tables = metadata.Tables;

            int[] rowCounts = new int[MetadataConstants.TableCount];
            for (int i = 0; i < MetadataConstants.TableCount; i++)
            {
                rowCounts[i] = tables[i].Count;
            }

            // Heap offset sizes.
            LoadHeapOffsetSizes(info, metadata);

            // Table row index sizes.
            LoadTableIndexSizes(info, metadata, rowCounts);

            // Coded token data sizes.
            LoadCodedTokenDataSizes(info, metadata, rowCounts);

            return(info);
        }
Пример #6
0
        public static TableCompressionInfo Create(MetadataScope metadata, int[] rowCounts, byte heapFlags)
        {
            var info = new TableCompressionInfo();

            var tables = metadata.Tables;

            // Heap offset sizes.
            info.StringHeapOffsetSize4 =
                ((heapFlags & HeapOffsetFlags.StringHeap4) == HeapOffsetFlags.StringHeap4);

            info.GuidHeapOffsetSize4 =
                ((heapFlags & HeapOffsetFlags.GuidHeap4) == HeapOffsetFlags.GuidHeap4);

            info.BlobHeapOffsetSize4 =
                ((heapFlags & HeapOffsetFlags.BlobHeap4) == HeapOffsetFlags.BlobHeap4);

            // Table row index sizes.
            LoadTableIndexSizes(info, metadata, rowCounts);

            // Coded token data sizes.
            LoadCodedTokenDataSizes(info, metadata, rowCounts);

            return(info);
        }
Пример #7
0
 private static void LoadHeapOffsetSizes(TableCompressionInfo info, MetadataScope metadata)
 {
     info.StringHeapOffsetSize4 = (metadata.Strings.Length >= (1 << 16));
     info.GuidHeapOffsetSize4   = (metadata.Guids.Length >= (1 << 16));
     info.BlobHeapOffsetSize4   = (metadata.Blobs.Length >= (1 << 16));
 }