示例#1
0
        internal MetadataInfo(InternalMetadataInfo metadataInfo)
        {
            if (metadataInfo is null)
            {
                throw new ArgumentNullException(nameof(metadataInfo));
            }

            IntPtr moduleHandle;

            moduleHandle = Marshal.GetHINSTANCE(metadataInfo.Module);
            if (!(metadataInfo.TableStream is null))
            {
                TableStream = new MetadataStreamInfo(metadataInfo.TableStream, moduleHandle);
            }
            if (!(metadataInfo.StringHeap is null))
            {
                StringHeap = new MetadataStreamInfo(metadataInfo.StringHeap, moduleHandle);
            }
            if (!(metadataInfo.UserStringHeap is null))
            {
                UserStringHeap = new MetadataStreamInfo(metadataInfo.UserStringHeap, moduleHandle);
            }
            if (!(metadataInfo.GuidHeap is null))
            {
                GuidHeap = new MetadataStreamInfo(metadataInfo.GuidHeap, moduleHandle);
            }
            if (!(metadataInfo.BlobHeap is null))
            {
                BlobHeap = new MetadataStreamInfo(metadataInfo.BlobHeap, moduleHandle);
            }
            PEInfo = new DotNetPEInfo(metadataInfo.PEInfo, moduleHandle);
        }
示例#2
0
        private static MetadataStreamInfo GetGuidHeap(MetadataInfo metadataInfo)
        {
            ThrowOnError(metadataInfo.MetaDataTables.GetGuidHeapSize(out uint streamSize));
            if (streamSize == 1)
            {
                return(null);
            }
            int result = metadataInfo.MetaDataTables.GetGuid(1, out void *pData);

            return(result == 0 ? new MetadataStreamInfo {
                Address = pData,
                Length = AlignUp(streamSize, 4)
            } : null);
        }
示例#3
0
        private static MetadataStreamInfo GetBlobHeap(MetadataInfo metadataInfo)
        {
            ThrowOnError(metadataInfo.MetaDataTables.GetBlobHeapSize(out uint streamSize));
            if (streamSize == 1)
            {
                return(null);
            }
            int result = metadataInfo.MetaDataTables.GetBlob(1, out uint dataSize, out void *pData);

            return(result == 0 ? new MetadataStreamInfo {
                Address = (byte *)pData - GetCompressedUInt32Length(dataSize) - 1,
                Length = AlignUp(streamSize, 4)
            } : null);
        }
示例#4
0
        private static MetadataStreamInfo GetUserStringHeap(MetadataInfo metadataInfo)
        {
            ThrowOnError(metadataInfo.MetaDataTables.GetUserStringHeapSize(out uint streamSize));
            if (streamSize == 1)
            {
                return(null);
            }
            int result = metadataInfo.MetaDataTables.GetUserString(1, out uint dataSize, out void *pData);

            // #US与#Blob堆传入ixXXX=0都会导致获取到的pData不是真实地址,所以获取第2个数据的地址
            return(result == 0 ? new MetadataStreamInfo {
                Address = (byte *)pData - GetCompressedUInt32Length(dataSize) - 1,
                Length = AlignUp(streamSize, 4)
            } : null);
        }
        private static MetadataStreamInfo GetStringHeap(MetadataInfo metadataInfo)
        {
            int   result;
            uint  streamSize;
            void *pData;

            ThrowOnError(metadataInfo.MetaDataTables.GetStringHeapSize(out streamSize));
            if (streamSize == 1)
            {
                // 表示流不存在,1只是用来占位
                return(null);
            }
            result = metadataInfo.MetaDataTables.GetString(0, out pData);
            return(result == 0 ? new MetadataStreamInfo {
                Address = pData,
                Length = AlignUp(streamSize, 4)
            } : null);
        }
示例#6
0
        private static MetadataStreamInfo GetTableStream(MetadataInfo metadataInfo)
        {
            ThrowOnError(metadataInfo.MetaDataTables.GetNumTables(out uint tableCount));
            uint tablesSize      = 0;
            uint validTableCount = 0;

            for (uint i = 0; i < tableCount; i++)
            {
                ThrowOnError(metadataInfo.MetaDataTables.GetTableInfo(i, out uint rowSize, out uint rowCount, out _, out _, out _));
                if (rowCount == 0)
                {
                    continue;
                }
                tablesSize += rowSize * rowCount;
                validTableCount++;
            }
            uint headerSize = 0x18 + (validTableCount * 4);

            ThrowOnError(metadataInfo.MetaDataTables.GetRow(0, 1, out void *address));
            return(new MetadataStreamInfo {
                Address = (byte *)address - headerSize,
                Length = AlignUp(headerSize + tablesSize, 4)
            });
        }