Exemple #1
0
		public MDTableModel(MDTableHeapModel parent, IMetaData metadata, TablesStream stream, MDTable table) {
			Parent = parent;
			MetaData = metadata;
			Tables = stream;
			MDTable = table;
			Text = string.Format("{0:x2}: {1} (0x{2:x})", (byte)table.Table, table.Name, table.Rows);
		}
Exemple #2
0
        /// <summary>
        /// Dispose method
        /// </summary>
        /// <param name="disposing"><c>true</c> if called by <see cref="Dispose()"/></param>
        protected virtual void Dispose(bool disposing)
        {
            if (!disposing)
            {
                return;
            }
            Dispose(peImage);
            Dispose(stringsStream);
            Dispose(usStream);
            Dispose(blobStream);
            Dispose(guidStream);
            Dispose(tablesStream);
            var as2 = allStreams;

            if (as2 != null)
            {
                foreach (var stream in as2.GetSafeEnumerable())
                {
                    Dispose(stream);
                }
            }
            peImage                   = null;
            cor20Header               = null;
            mdHeader                  = null;
            stringsStream             = null;
            usStream                  = null;
            blobStream                = null;
            guidStream                = null;
            tablesStream              = null;
            allStreams                = null;
            fieldRidToTypeDefRid      = null;
            methodRidToTypeDefRid     = null;
            typeDefRidToNestedClasses = null;
        }
		public TablesStreamTreeNode(HexDocument doc, TablesStream tblStream, IMetaData md)
			: base((ulong)tblStream.StartOffset, (ulong)tblStream.MDTables[0].StartOffset - 1) {
			this.tablesStreamVM = new TablesStreamVM(this, doc, tblStream);

			foreach (var mdTable in tblStream.MDTables) {
				if (mdTable.Rows != 0)
					this.Children.Add(new MetaDataTableTreeNode(doc, mdTable, md));
			}
		}
Exemple #4
0
		public TablesStreamNode(HexBuffer buffer, TablesStream tblStream, IMetaData md)
			: base(HexSpan.FromBounds((ulong)tblStream.StartOffset, (ulong)tblStream.MDTables[0].StartOffset)) {
			tablesStreamVM = new TablesStreamVM(buffer, tblStream);

			newChildren = new List<TreeNodeData>();
			foreach (var mdTable in tblStream.MDTables) {
				if (mdTable.Rows != 0)
					newChildren.Add(new MetaDataTableNode(buffer, mdTable, md));
			}
		}
Exemple #5
0
        public TablesStreamVM(HexDocument doc, TablesStream tblStream)
        {
            ulong startOffset = (ulong)tblStream.StartOffset;
            this.m_ulReservedVM = new UInt32HexField(doc, Name, "m_ulReserved", startOffset + 0);
            this.m_majorVM = new ByteHexField(doc, Name, "m_major", startOffset + 4, true);
            this.m_minorVM = new ByteHexField(doc, Name, "m_minor", startOffset + 5, true);
            this.m_heapsVM = new ByteFlagsHexField(doc, Name, "m_heaps", startOffset + 6);
            this.m_heapsVM.Add(new BooleanHexBitField("BigStrings", 0));
            this.m_heapsVM.Add(new BooleanHexBitField("BigGUID", 1));
            this.m_heapsVM.Add(new BooleanHexBitField("BigBlob", 2));
            this.m_heapsVM.Add(new BooleanHexBitField("Padding", 3));
            this.m_heapsVM.Add(new BooleanHexBitField("Reserved", 4));
            this.m_heapsVM.Add(new BooleanHexBitField("DeltaOnly", 5));
            this.m_heapsVM.Add(new BooleanHexBitField("ExtraData", 6));
            this.m_heapsVM.Add(new BooleanHexBitField("HasDelete", 7));
            this.m_ridVM = new ByteHexField(doc, Name, "m_rid", startOffset + 7);
            this.m_maskvalidVM = new UInt64FlagsHexField(doc, Name, "m_maskvalid", startOffset + 8);
            AddTableFlags(this.m_maskvalidVM);
            this.m_sortedVM = new UInt64FlagsHexField(doc, Name, "m_sorted", startOffset + 0x10);
            AddTableFlags(this.m_sortedVM);

            var list = new List<HexField> {
                m_ulReservedVM,
                m_majorVM,
                m_minorVM,
                m_heapsVM,
                m_ridVM,
                m_maskvalidVM,
                m_sortedVM,
            };

            this.rowsVM = new UInt32HexField[64];
            ulong valid = tblStream.ValidMask;
            ulong offs = startOffset + 0x18;
            for (int i = 0; i < this.rowsVM.Length; i++) {
                this.rowsVM[i] = new UInt32HexField(doc, Name, string.Format("rows[{0:X2}]", i), offs);
                if ((valid & 1) != 0) {
                    list.Add(this.rowsVM[i]);
                    offs += 4;
                }
                else
                    this.rowsVM[i].IsVisible = false;

                valid >>= 1;
            }

            this.m_ulExtraVM = new UInt32HexField(doc, Name, "m_ulExtra", offs);
            this.m_ulExtraVM.IsVisible = tblStream.HasExtraData;
            if (tblStream.HasExtraData)
                list.Add(this.m_ulExtraVM);

            Debug.Assert(offs == (ulong)tblStream.MDTables[0].StartOffset);

            this.hexFields = list.ToArray();
        }
Exemple #6
0
 /// <summary>
 /// Dispose method
 /// </summary>
 /// <param name="disposing"><c>true</c> if called by <see cref="Dispose()"/></param>
 protected virtual void Dispose(bool disposing)
 {
     if (!disposing)
     {
         return;
     }
     if (peImage != null)
     {
         peImage.Dispose();
     }
     if (stringsStream != null)
     {
         stringsStream.Dispose();
     }
     if (usStream != null)
     {
         usStream.Dispose();
     }
     if (blobStream != null)
     {
         blobStream.Dispose();
     }
     if (guidStream != null)
     {
         guidStream.Dispose();
     }
     if (tablesStream != null)
     {
         tablesStream.Dispose();
     }
     if (allStreams != null)
     {
         foreach (var stream in allStreams)
         {
             if (stream != null)
             {
                 stream.Dispose();
             }
         }
     }
     peImage                   = null;
     cor20Header               = null;
     mdHeader                  = null;
     stringsStream             = null;
     usStream                  = null;
     blobStream                = null;
     guidStream                = null;
     tablesStream              = null;
     allStreams                = null;
     fieldRidToTypeDefRid      = null;
     methodRidToTypeDefRid     = null;
     typeDefRidToNestedClasses = null;
 }
        /// <summary>
        /// Dispose method
        /// </summary>
        /// <param name="disposing"><c>true</c> if called by <see cref="Dispose()"/></param>
        protected virtual void Dispose(bool disposing)
        {
            if (!disposing)
            {
                return;
            }
            peImage?.Dispose();
            stringsStream?.Dispose();
            usStream?.Dispose();
            blobStream?.Dispose();
            guidStream?.Dispose();
            tablesStream?.Dispose();
            var as2 = allStreams;

            if (as2 != null)
            {
                foreach (var stream in as2)
                {
                    stream?.Dispose();
                }
            }
            mdReaderFactoryToDisposeLater?.Dispose();
            peImage                       = null;
            cor20Header                   = null;
            mdHeader                      = null;
            stringsStream                 = null;
            usStream                      = null;
            blobStream                    = null;
            guidStream                    = null;
            tablesStream                  = null;
            allStreams                    = null;
            fieldRidToTypeDefRid          = null;
            methodRidToTypeDefRid         = null;
            typeDefRidToNestedClasses     = null;
            mdReaderFactoryToDisposeLater = null;
        }
		public MDTablesStreamModel(dnModule module, TablesStream stream) {
			Module = module;
			Stream = stream;
			Text = stream.Name;
		}
Exemple #9
0
		public TablesStreamVM(object owner, HexBuffer buffer, TablesStream tblStream)
			: base(owner) {
			var startOffset = new HexPosition((ulong)tblStream.StartOffset);
			M_ulReservedVM = new UInt32HexField(buffer, Name, "m_ulReserved", startOffset + 0);
			M_majorVM = new ByteHexField(buffer, Name, "m_major", startOffset + 4, true);
			M_minorVM = new ByteHexField(buffer, Name, "m_minor", startOffset + 5, true);
			M_heapsVM = new ByteFlagsHexField(buffer, Name, "m_heaps", startOffset + 6);
			M_heapsVM.Add(new BooleanHexBitField("BigStrings", 0));
			M_heapsVM.Add(new BooleanHexBitField("BigGUID", 1));
			M_heapsVM.Add(new BooleanHexBitField("BigBlob", 2));
			M_heapsVM.Add(new BooleanHexBitField("Padding", 3));
			M_heapsVM.Add(new BooleanHexBitField("Reserved", 4));
			M_heapsVM.Add(new BooleanHexBitField("DeltaOnly", 5));
			M_heapsVM.Add(new BooleanHexBitField("ExtraData", 6));
			M_heapsVM.Add(new BooleanHexBitField("HasDelete", 7));
			M_ridVM = new ByteHexField(buffer, Name, "m_rid", startOffset + 7);
			M_maskvalidVM = new UInt64FlagsHexField(buffer, Name, "m_maskvalid", startOffset + 8);
			AddTableFlags(M_maskvalidVM);
			M_sortedVM = new UInt64FlagsHexField(buffer, Name, "m_sorted", startOffset + 0x10);
			AddTableFlags(M_sortedVM);

			var list = new List<HexField> {
				M_ulReservedVM,
				M_majorVM,
				M_minorVM,
				M_heapsVM,
				M_ridVM,
				M_maskvalidVM,
				M_sortedVM,
			};

			rowsVM = new UInt32HexField[64];
			ulong valid = tblStream.ValidMask;
			var offs = startOffset + 0x18;
			for (int i = 0; i < rowsVM.Length; i++) {
				rowsVM[i] = new UInt32HexField(buffer, Name, string.Format("rows[{0:X2}]", i), offs);
				if ((valid & 1) != 0) {
					list.Add(rowsVM[i]);
					offs += 4;
				}
				else
					rowsVM[i].IsVisible = false;

				valid >>= 1;
			}

			M_ulExtraVM = new UInt32HexField(buffer, Name, "m_ulExtra", offs);
			M_ulExtraVM.IsVisible = tblStream.HasExtraData;
			if (tblStream.HasExtraData)
				list.Add(M_ulExtraVM);

			Debug.Assert(offs == (ulong)tblStream.MDTables[0].StartOffset);

			hexFields = list.ToArray();
		}
Exemple #10
0
        /// <inheritdoc/>
        protected override void InitializeInternal(DataReaderFactory mdReaderFactory, uint metadataBaseOffset)
        {
            DotNetStream dns = null;

            try {
                if (runtime == CLRRuntimeReaderKind.Mono)
                {
                    var newAllStreams = new List <DotNetStream>(allStreams);
                    for (int i = mdHeader.StreamHeaders.Count - 1; i >= 0; i--)
                    {
                        var sh = mdHeader.StreamHeaders[i];
                        switch (sh.Name)
                        {
                        case "#Strings":
                            if (stringsStream is null)
                            {
                                stringsStream = new StringsStream(mdReaderFactory, metadataBaseOffset, sh);
                                newAllStreams.Add(stringsStream);
                                continue;
                            }
                            break;

                        case "#US":
                            if (usStream is null)
                            {
                                usStream = new USStream(mdReaderFactory, metadataBaseOffset, sh);
                                newAllStreams.Add(usStream);
                                continue;
                            }
                            break;

                        case "#Blob":
                            if (blobStream is null)
                            {
                                blobStream = new BlobStream(mdReaderFactory, metadataBaseOffset, sh);
                                newAllStreams.Add(blobStream);
                                continue;
                            }
                            break;

                        case "#GUID":
                            if (guidStream is null)
                            {
                                guidStream = new GuidStream(mdReaderFactory, metadataBaseOffset, sh);
                                newAllStreams.Add(guidStream);
                                continue;
                            }
                            break;

                        case "#~":
                        case "#-":
                            if (tablesStream is null)
                            {
                                tablesStream = new TablesStream(mdReaderFactory, metadataBaseOffset, sh, runtime);
                                newAllStreams.Add(tablesStream);
                                continue;
                            }
                            break;

                        case "#Pdb":
                            if (isStandalonePortablePdb && pdbStream is null)
                            {
                                pdbStream = new PdbStream(mdReaderFactory, metadataBaseOffset, sh);
                                newAllStreams.Add(pdbStream);
                                continue;
                            }
                            break;
                        }
                        dns = new CustomDotNetStream(mdReaderFactory, metadataBaseOffset, sh);
                        newAllStreams.Add(dns);
                        dns = null;
                    }
                    newAllStreams.Reverse();
                    allStreams = newAllStreams;
                }
                else
                {
                    Debug.Assert(runtime == CLRRuntimeReaderKind.CLR);
                    foreach (var sh in mdHeader.StreamHeaders)
                    {
                        switch (sh.Name.ToUpperInvariant())
                        {
                        case "#STRINGS":
                            if (stringsStream is null)
                            {
                                stringsStream = new StringsStream(mdReaderFactory, metadataBaseOffset, sh);
                                allStreams.Add(stringsStream);
                                continue;
                            }
                            break;

                        case "#US":
                            if (usStream is null)
                            {
                                usStream = new USStream(mdReaderFactory, metadataBaseOffset, sh);
                                allStreams.Add(usStream);
                                continue;
                            }
                            break;

                        case "#BLOB":
                            if (blobStream is null)
                            {
                                blobStream = new BlobStream(mdReaderFactory, metadataBaseOffset, sh);
                                allStreams.Add(blobStream);
                                continue;
                            }
                            break;

                        case "#GUID":
                            if (guidStream is null)
                            {
                                guidStream = new GuidStream(mdReaderFactory, metadataBaseOffset, sh);
                                allStreams.Add(guidStream);
                                continue;
                            }
                            break;

                        case "#~":                          // Only if #Schema is used
                        case "#-":
                            if (tablesStream is null)
                            {
                                tablesStream = new TablesStream(mdReaderFactory, metadataBaseOffset, sh, runtime);
                                allStreams.Add(tablesStream);
                                continue;
                            }
                            break;

                        case "#PDB":
                            // Case sensitive comparison since it's a stream that's not read by the CLR,
                            // only by other libraries eg. System.Reflection.Metadata.
                            if (isStandalonePortablePdb && pdbStream is null && sh.Name == "#Pdb")
                            {
                                pdbStream = new PdbStream(mdReaderFactory, metadataBaseOffset, sh);
                                allStreams.Add(pdbStream);
                                continue;
                            }
                            break;
                        }
                        dns = new CustomDotNetStream(mdReaderFactory, metadataBaseOffset, sh);
                        allStreams.Add(dns);
                        dns = null;
                    }
                }
            }
            finally {
                dns?.Dispose();
            }

            if (tablesStream is null)
            {
                throw new BadImageFormatException("Missing MD stream");
            }

            if (!(pdbStream is null))
            {
                tablesStream.Initialize(pdbStream.TypeSystemTableRows);
            }
Exemple #11
0
		/// <inheritdoc/>
		protected override void InitializeInternal() {
			var hotHeapVersion = GetHotHeapVersion(peImage.FileName, mdHeader.VersionString);

			IImageStream imageStream = null, fullStream = null;
			DotNetStream dns = null;
			List<HotStream> hotStreams = null;
			HotStream hotStream = null;
			var newAllStreams = new List<DotNetStream>(allStreams);
			try {
				var mdRva = cor20Header.MetaData.VirtualAddress;
				for (int i = mdHeader.StreamHeaders.Count - 1; i >= 0; i--) {
					var sh = mdHeader.StreamHeaders[i];
					var rva = mdRva + sh.Offset;
					var fileOffset = peImage.ToFileOffset(rva);
					imageStream = peImage.CreateStream(fileOffset, sh.StreamSize);
					switch (sh.Name) {
					case "#Strings":
						if (stringsStream == null) {
							stringsStream = new StringsStream(imageStream, sh);
							imageStream = null;
							newAllStreams.Add(stringsStream);
							continue;
						}
						break;

					case "#US":
						if (usStream == null) {
							usStream = new USStream(imageStream, sh);
							imageStream = null;
							newAllStreams.Add(usStream);
							continue;
						}
						break;

					case "#Blob":
						if (blobStream == null) {
							blobStream = new BlobStream(imageStream, sh);
							imageStream = null;
							newAllStreams.Add(blobStream);
							continue;
						}
						break;

					case "#GUID":
						if (guidStream == null) {
							guidStream = new GuidStream(imageStream, sh);
							imageStream = null;
							newAllStreams.Add(guidStream);
							continue;
						}
						break;

					case "#~":
						if (tablesStream == null) {
							tablesStream = new TablesStream(imageStream, sh);
							imageStream = null;
							newAllStreams.Add(tablesStream);
							continue;
						}
						break;

					case "#!":
						if (hotStreams == null)
							hotStreams = new List<HotStream>();
						fullStream = peImage.CreateFullStream();
						hotStream = HotStream.Create(hotHeapVersion, imageStream, sh, fullStream, fileOffset);
						fullStream = null;
						hotStreams.Add(hotStream);
						newAllStreams.Add(hotStream);
						hotStream = null;
						imageStream = null;
						continue;
					}
					dns = new DotNetStream(imageStream, sh);
					imageStream = null;
					newAllStreams.Add(dns);
					dns = null;
				}
			}
			finally {
				if (imageStream != null)
					imageStream.Dispose();
				if (fullStream != null)
					fullStream.Dispose();
				if (dns != null)
					dns.Dispose();
				if (hotStream != null)
					hotStream.Dispose();
				newAllStreams.Reverse();
				allStreams = ThreadSafeListCreator.MakeThreadSafe(newAllStreams);
			}

			if (tablesStream == null)
				throw new BadImageFormatException("Missing MD stream");

			if (hotStreams != null) {
				hotStreams.Reverse();
				InitializeHotStreams(hotStreams);
			}

			tablesStream.Initialize(peImage);
		}
Exemple #12
0
 /// <summary>
 /// Dispose method
 /// </summary>
 /// <param name="disposing"><c>true</c> if called by <see cref="Dispose()"/></param>
 protected virtual void Dispose(bool disposing)
 {
     if (!disposing)
         return;
     Dispose(peImage);
     Dispose(stringsStream);
     Dispose(usStream);
     Dispose(blobStream);
     Dispose(guidStream);
     Dispose(tablesStream);
     var as2 = allStreams;
     if (as2 != null) {
         foreach (var stream in as2.GetSafeEnumerable())
             Dispose(stream);
     }
     peImage = null;
     cor20Header = null;
     mdHeader = null;
     stringsStream = null;
     usStream = null;
     blobStream = null;
     guidStream = null;
     tablesStream = null;
     allStreams = null;
     fieldRidToTypeDefRid = null;
     methodRidToTypeDefRid = null;
     typeDefRidToNestedClasses = null;
 }
		/// <inheritdoc/>
		protected override void Initialize2() {
			IImageStream imageStream = null;
			DotNetStream dns = null;
			try {
				var mdRva = cor20Header.MetaData.VirtualAddress;
				for (int i = mdHeader.StreamHeaders.Count - 1; i >= 0; i--) {
					var sh = mdHeader.StreamHeaders[i];
					var rva = mdRva + sh.Offset;
					imageStream = peImage.CreateStream(rva, sh.StreamSize);
					switch (sh.Name) {
					case "#Strings":
						if (stringsStream == null) {
							stringsStream = new StringsStream(imageStream, sh);
							imageStream = null;
							allStreams.Add(stringsStream);
							continue;
						}
						break;

					case "#US":
						if (usStream == null) {
							usStream = new USStream(imageStream, sh);
							imageStream = null;
							allStreams.Add(usStream);
							continue;
						}
						break;

					case "#Blob":
						if (blobStream == null) {
							blobStream = new BlobStream(imageStream, sh);
							imageStream = null;
							allStreams.Add(blobStream);
							continue;
						}
						break;

					case "#GUID":
						if (guidStream == null) {
							guidStream = new GuidStream(imageStream, sh);
							imageStream = null;
							allStreams.Add(guidStream);
							continue;
						}
						break;

					case "#~":
						if (tablesStream == null) {
							tablesStream = new TablesStream(imageStream, sh);
							imageStream = null;
							allStreams.Add(tablesStream);
							continue;
						}
						break;
					}
					dns = new DotNetStream(imageStream, sh);
					imageStream = null;
					allStreams.Add(dns);
					dns = null;
				}
			}
			finally {
				if (imageStream != null)
					imageStream.Dispose();
				if (dns != null)
					dns.Dispose();
			}

			allStreams.Reverse();

			if (tablesStream == null)
				throw new BadImageFormatException("Missing MD stream");
			tablesStream.Initialize(peImage);
		}
        /// <inheritdoc/>
        protected override void InitializeInternal()
        {
            var hotHeapVersion = GetHotHeapVersion(peImage.FileName, mdHeader.VersionString);

            IImageStream     imageStream = null, fullStream = null;
            DotNetStream     dns        = null;
            List <HotStream> hotStreams = null;
            HotStream        hotStream  = null;
            var newAllStreams           = new List <DotNetStream>(allStreams);

            try {
                var mdRva = cor20Header.MetaData.VirtualAddress;
                for (int i = mdHeader.StreamHeaders.Count - 1; i >= 0; i--)
                {
                    var sh         = mdHeader.StreamHeaders[i];
                    var rva        = mdRva + sh.Offset;
                    var fileOffset = peImage.ToFileOffset(rva);
                    imageStream = peImage.CreateStream(fileOffset, sh.StreamSize);
                    switch (sh.Name)
                    {
                    case "#Strings":
                        if (stringsStream == null)
                        {
                            stringsStream = new StringsStream(imageStream, sh);
                            imageStream   = null;
                            newAllStreams.Add(stringsStream);
                            continue;
                        }
                        break;

                    case "#US":
                        if (usStream == null)
                        {
                            usStream    = new USStream(imageStream, sh);
                            imageStream = null;
                            newAllStreams.Add(usStream);
                            continue;
                        }
                        break;

                    case "#Blob":
                        if (blobStream == null)
                        {
                            blobStream  = new BlobStream(imageStream, sh);
                            imageStream = null;
                            newAllStreams.Add(blobStream);
                            continue;
                        }
                        break;

                    case "#GUID":
                        if (guidStream == null)
                        {
                            guidStream  = new GuidStream(imageStream, sh);
                            imageStream = null;
                            newAllStreams.Add(guidStream);
                            continue;
                        }
                        break;

                    case "#~":
                        if (tablesStream == null)
                        {
                            tablesStream = new TablesStream(imageStream, sh);
                            imageStream  = null;
                            newAllStreams.Add(tablesStream);
                            continue;
                        }
                        break;

                    case "#!":
                        if (hotStreams == null)
                        {
                            hotStreams = new List <HotStream>();
                        }
                        fullStream = peImage.CreateFullStream();
                        hotStream  = HotStream.Create(hotHeapVersion, imageStream, sh, fullStream, fileOffset);
                        fullStream = null;
                        hotStreams.Add(hotStream);
                        newAllStreams.Add(hotStream);
                        hotStream   = null;
                        imageStream = null;
                        continue;
                    }
                    dns         = new DotNetStream(imageStream, sh);
                    imageStream = null;
                    newAllStreams.Add(dns);
                    dns = null;
                }
            }
            finally {
                if (imageStream != null)
                {
                    imageStream.Dispose();
                }
                if (fullStream != null)
                {
                    fullStream.Dispose();
                }
                if (dns != null)
                {
                    dns.Dispose();
                }
                if (hotStream != null)
                {
                    hotStream.Dispose();
                }
                newAllStreams.Reverse();
                allStreams = ThreadSafeListCreator.MakeThreadSafe(newAllStreams);
            }

            if (tablesStream == null)
            {
                throw new BadImageFormatException("Missing MD stream");
            }

            if (hotStreams != null)
            {
                hotStreams.Reverse();
                InitializeHotStreams(hotStreams);
            }

            tablesStream.Initialize(peImage);
        }
		/// <inheritdoc/>
		protected override void InitializeInternal() {
			IImageStream imageStream = null;
			DotNetStream dns = null;
			try {
				var mdRva = cor20Header.MetaData.VirtualAddress;
				foreach (var sh in mdHeader.StreamHeaders) {
					var rva = mdRva + sh.Offset;
					imageStream = peImage.CreateStream(rva, sh.StreamSize);
					switch (sh.Name.ToUpperInvariant()) {
					case "#STRINGS":
						if (stringsStream == null) {
							stringsStream = new StringsStream(imageStream, sh);
							imageStream = null;
							allStreams.Add(stringsStream);
							continue;
						}
						break;

					case "#US":
						if (usStream == null) {
							usStream = new USStream(imageStream, sh);
							imageStream = null;
							allStreams.Add(usStream);
							continue;
						}
						break;

					case "#BLOB":
						if (blobStream == null) {
							blobStream = new BlobStream(imageStream, sh);
							imageStream = null;
							allStreams.Add(blobStream);
							continue;
						}
						break;

					case "#GUID":
						if (guidStream == null) {
							guidStream = new GuidStream(imageStream, sh);
							imageStream = null;
							allStreams.Add(guidStream);
							continue;
						}
						break;

					case "#~":	// Only if #Schema is used
					case "#-":
						if (tablesStream == null) {
							tablesStream = new TablesStream(imageStream, sh);
							imageStream = null;
							allStreams.Add(tablesStream);
							continue;
						}
						break;
					}
					dns = new DotNetStream(imageStream, sh);
					imageStream = null;
					allStreams.Add(dns);
					dns = null;
				}
			}
			finally {
				if (imageStream != null)
					imageStream.Dispose();
				if (dns != null)
					dns.Dispose();
			}

			if (tablesStream == null)
				throw new BadImageFormatException("Missing MD stream");
			tablesStream.Initialize(peImage);

			// The pointer tables are used iff row count != 0
			hasFieldPtr = !tablesStream.FieldPtrTable.IsEmpty;
			hasMethodPtr = !tablesStream.MethodPtrTable.IsEmpty;
			hasParamPtr = !tablesStream.ParamPtrTable.IsEmpty;
			hasEventPtr = !tablesStream.EventPtrTable.IsEmpty;
			hasPropertyPtr = !tablesStream.PropertyPtrTable.IsEmpty;
			hasDeletedRows = tablesStream.HasDelete;
		}
        /// <inheritdoc/>
        protected override void InitializeInternal(DataReaderFactory mdReaderFactory, uint metadataBaseOffset)
        {
            DotNetStream dns = null;

            try {
                foreach (var sh in mdHeader.StreamHeaders)
                {
                    switch (sh.Name.ToUpperInvariant())
                    {
                    case "#STRINGS":
                        if (stringsStream == null)
                        {
                            stringsStream = new StringsStream(mdReaderFactory, metadataBaseOffset, sh);
                            allStreams.Add(stringsStream);
                            continue;
                        }
                        break;

                    case "#US":
                        if (usStream == null)
                        {
                            usStream = new USStream(mdReaderFactory, metadataBaseOffset, sh);
                            allStreams.Add(usStream);
                            continue;
                        }
                        break;

                    case "#BLOB":
                        if (blobStream == null)
                        {
                            blobStream = new BlobStream(mdReaderFactory, metadataBaseOffset, sh);
                            allStreams.Add(blobStream);
                            continue;
                        }
                        break;

                    case "#GUID":
                        if (guidStream == null)
                        {
                            guidStream = new GuidStream(mdReaderFactory, metadataBaseOffset, sh);
                            allStreams.Add(guidStream);
                            continue;
                        }
                        break;

                    case "#~":                          // Only if #Schema is used
                    case "#-":
                        if (tablesStream == null)
                        {
                            tablesStream = new TablesStream(mdReaderFactory, metadataBaseOffset, sh);
                            allStreams.Add(tablesStream);
                            continue;
                        }
                        break;

                    case "#PDB":
                        // Case sensitive comparison since it's a stream that's not read by the CLR,
                        // only by other libraries eg. System.Reflection.Metadata.
                        if (isStandalonePortablePdb && pdbStream == null && sh.Name == "#Pdb")
                        {
                            pdbStream = new PdbStream(mdReaderFactory, metadataBaseOffset, sh);
                            allStreams.Add(pdbStream);
                            continue;
                        }
                        break;
                    }
                    dns = new CustomDotNetStream(mdReaderFactory, metadataBaseOffset, sh);
                    allStreams.Add(dns);
                    dns = null;
                }
            }
            finally {
                dns?.Dispose();
            }

            if (tablesStream == null)
            {
                throw new BadImageFormatException("Missing MD stream");
            }

            if (pdbStream != null)
            {
                tablesStream.Initialize(pdbStream.TypeSystemTableRows);
            }
            else
            {
                tablesStream.Initialize(null);
            }

            // The pointer tables are used iff row count != 0
            hasFieldPtr    = !tablesStream.FieldPtrTable.IsEmpty;
            hasMethodPtr   = !tablesStream.MethodPtrTable.IsEmpty;
            hasParamPtr    = !tablesStream.ParamPtrTable.IsEmpty;
            hasEventPtr    = !tablesStream.EventPtrTable.IsEmpty;
            hasPropertyPtr = !tablesStream.PropertyPtrTable.IsEmpty;
            hasDeletedRows = tablesStream.HasDelete;
        }
Exemple #17
0
        /// <inheritdoc/>
        protected override void InitializeInternal(IImageStream mdStream)
        {
            bool         disposeOfMdStream = false;
            IImageStream imageStream       = null;
            DotNetStream dns = null;

            try {
                if (peImage != null)
                {
                    Debug.Assert(mdStream == null);
                    Debug.Assert(cor20Header != null);
                    var mdOffset = peImage.ToFileOffset(cor20Header.MetaData.VirtualAddress);
                    mdStream          = peImage.CreateStream(mdOffset, cor20Header.MetaData.Size);
                    disposeOfMdStream = true;
                }
                else
                {
                    Debug.Assert(mdStream != null);
                }
                foreach (var sh in mdHeader.StreamHeaders)
                {
                    imageStream = mdStream.Create((FileOffset)sh.Offset, sh.StreamSize);
                    switch (sh.Name.ToUpperInvariant())
                    {
                    case "#STRINGS":
                        if (stringsStream == null)
                        {
                            stringsStream = new StringsStream(imageStream, sh);
                            imageStream   = null;
                            allStreams.Add(stringsStream);
                            continue;
                        }
                        break;

                    case "#US":
                        if (usStream == null)
                        {
                            usStream    = new USStream(imageStream, sh);
                            imageStream = null;
                            allStreams.Add(usStream);
                            continue;
                        }
                        break;

                    case "#BLOB":
                        if (blobStream == null)
                        {
                            blobStream  = new BlobStream(imageStream, sh);
                            imageStream = null;
                            allStreams.Add(blobStream);
                            continue;
                        }
                        break;

                    case "#GUID":
                        if (guidStream == null)
                        {
                            guidStream  = new GuidStream(imageStream, sh);
                            imageStream = null;
                            allStreams.Add(guidStream);
                            continue;
                        }
                        break;

                    case "#~":                          // Only if #Schema is used
                    case "#-":
                        if (tablesStream == null)
                        {
                            tablesStream = new TablesStream(imageStream, sh);
                            imageStream  = null;
                            allStreams.Add(tablesStream);
                            continue;
                        }
                        break;

                    case "#PDB":
                        // Case sensitive comparison since it's a stream that's not read by the CLR,
                        // only by other libraries eg. System.Reflection.Metadata.
                        if (isStandalonePortablePdb && pdbStream == null && sh.Name == "#Pdb")
                        {
                            pdbStream   = new PdbStream(imageStream, sh);
                            imageStream = null;
                            allStreams.Add(pdbStream);
                            continue;
                        }
                        break;
                    }
                    dns         = new DotNetStream(imageStream, sh);
                    imageStream = null;
                    allStreams.Add(dns);
                    dns = null;
                }
            }
            finally {
                if (disposeOfMdStream)
                {
                    mdStream.Dispose();
                }
                if (imageStream != null)
                {
                    imageStream.Dispose();
                }
                if (dns != null)
                {
                    dns.Dispose();
                }
            }

            if (tablesStream == null)
            {
                throw new BadImageFormatException("Missing MD stream");
            }

            if (pdbStream != null)
            {
                tablesStream.Initialize(pdbStream.TypeSystemTableRows);
            }
            else
            {
                tablesStream.Initialize(null);
            }

            // The pointer tables are used iff row count != 0
            hasFieldPtr    = !tablesStream.FieldPtrTable.IsEmpty;
            hasMethodPtr   = !tablesStream.MethodPtrTable.IsEmpty;
            hasParamPtr    = !tablesStream.ParamPtrTable.IsEmpty;
            hasEventPtr    = !tablesStream.EventPtrTable.IsEmpty;
            hasPropertyPtr = !tablesStream.PropertyPtrTable.IsEmpty;
            hasDeletedRows = tablesStream.HasDelete;
        }
Exemple #18
0
        /// <inheritdoc/>
        protected override void Initialize2()
        {
            IImageStream imageStream = null;
            DotNetStream dns         = null;

            try {
                var mdRva = cor20Header.MetaData.VirtualAddress;
                for (int i = mdHeader.StreamHeaders.Count - 1; i >= 0; i--)
                {
                    var sh  = mdHeader.StreamHeaders[i];
                    var rva = mdRva + sh.Offset;
                    imageStream = peImage.CreateStream(rva, sh.StreamSize);
                    switch (sh.Name)
                    {
                    case "#Strings":
                        if (stringsStream == null)
                        {
                            stringsStream = new StringsStream(imageStream, sh);
                            imageStream   = null;
                            allStreams.Add(stringsStream);
                            continue;
                        }
                        break;

                    case "#US":
                        if (usStream == null)
                        {
                            usStream    = new USStream(imageStream, sh);
                            imageStream = null;
                            allStreams.Add(usStream);
                            continue;
                        }
                        break;

                    case "#Blob":
                        if (blobStream == null)
                        {
                            blobStream  = new BlobStream(imageStream, sh);
                            imageStream = null;
                            allStreams.Add(blobStream);
                            continue;
                        }
                        break;

                    case "#GUID":
                        if (guidStream == null)
                        {
                            guidStream  = new GuidStream(imageStream, sh);
                            imageStream = null;
                            allStreams.Add(guidStream);
                            continue;
                        }
                        break;

                    case "#~":
                        if (tablesStream == null)
                        {
                            tablesStream = new TablesStream(imageStream, sh);
                            imageStream  = null;
                            allStreams.Add(tablesStream);
                            continue;
                        }
                        break;
                    }
                    dns         = new DotNetStream(imageStream, sh);
                    imageStream = null;
                    allStreams.Add(dns);
                    dns = null;
                }
            }
            finally {
                if (imageStream != null)
                {
                    imageStream.Dispose();
                }
                if (dns != null)
                {
                    dns.Dispose();
                }
            }

            allStreams.Reverse();

            if (tablesStream == null)
            {
                throw new BadImageFormatException("Missing MD stream");
            }
            tablesStream.Initialize(peImage);
        }
		/// <summary>
		/// Dispose method
		/// </summary>
		/// <param name="disposing"><c>true</c> if called by <see cref="Dispose()"/></param>
		protected virtual void Dispose(bool disposing) {
			if (!disposing)
				return;
			if (peImage != null)
				peImage.Dispose();
			if (stringsStream != null)
				stringsStream.Dispose();
			if (usStream != null)
				usStream.Dispose();
			if (blobStream != null)
				blobStream.Dispose();
			if (guidStream != null)
				guidStream.Dispose();
			if (tablesStream != null)
				tablesStream.Dispose();
			if (allStreams != null) {
				foreach (var stream in allStreams) {
					if (stream != null)
						stream.Dispose();
				}
			}
			peImage = null;
			cor20Header = null;
			mdHeader = null;
			stringsStream = null;
			usStream = null;
			blobStream = null;
			guidStream = null;
			tablesStream = null;
			allStreams = null;
			fieldRidToTypeDefRid = null;
			methodRidToTypeDefRid = null;
			typeDefRidToNestedClasses = null;
		}
        /// <inheritdoc/>
        protected override void Initialize2()
        {
            IImageStream imageStream = null;
            DotNetStream dns         = null;

            try {
                var mdRva = cor20Header.MetaData.VirtualAddress;
                foreach (var sh in mdHeader.StreamHeaders)
                {
                    var rva = mdRva + sh.Offset;
                    imageStream = peImage.CreateStream(rva, sh.StreamSize);
                    switch (sh.Name.ToUpperInvariant())
                    {
                    case "#STRINGS":
                        if (stringsStream == null)
                        {
                            stringsStream = new StringsStream(imageStream, sh);
                            imageStream   = null;
                            allStreams.Add(stringsStream);
                            continue;
                        }
                        break;

                    case "#US":
                        if (usStream == null)
                        {
                            usStream    = new USStream(imageStream, sh);
                            imageStream = null;
                            allStreams.Add(usStream);
                            continue;
                        }
                        break;

                    case "#BLOB":
                        if (blobStream == null)
                        {
                            blobStream  = new BlobStream(imageStream, sh);
                            imageStream = null;
                            allStreams.Add(blobStream);
                            continue;
                        }
                        break;

                    case "#GUID":
                        if (guidStream == null)
                        {
                            guidStream  = new GuidStream(imageStream, sh);
                            imageStream = null;
                            allStreams.Add(guidStream);
                            continue;
                        }
                        break;

                    case "#-":
                        if (tablesStream == null)
                        {
                            tablesStream = new TablesStream(imageStream, sh);
                            imageStream  = null;
                            allStreams.Add(tablesStream);
                            continue;
                        }
                        break;
                    }
                    dns         = new DotNetStream(imageStream, sh);
                    imageStream = null;
                    allStreams.Add(dns);
                    dns = null;
                }
            }
            finally {
                if (imageStream != null)
                {
                    imageStream.Dispose();
                }
                if (dns != null)
                {
                    dns.Dispose();
                }
            }

            if (tablesStream == null)
            {
                throw new BadImageFormatException("Missing MD stream");
            }
            tablesStream.Initialize(peImage);

            // The pointer tables are used iff row count != 0
            hasFieldPtr    = !tablesStream.FieldPtrTable.IsEmpty;
            hasMethodPtr   = !tablesStream.MethodPtrTable.IsEmpty;
            hasParamPtr    = !tablesStream.ParamPtrTable.IsEmpty;
            hasEventPtr    = !tablesStream.EventPtrTable.IsEmpty;
            hasPropertyPtr = !tablesStream.PropertyPtrTable.IsEmpty;
            hasDeletedRows = tablesStream.HasDelete;
        }
Exemple #21
0
        /// <inheritdoc/>
        protected override void InitializeInternal(DataReaderFactory mdReaderFactory, uint metadataBaseOffset)
        {
            DotNetStream dns           = null;
            var          newAllStreams = new List <DotNetStream>(allStreams);
            bool         forceAllBig   = false;

            try {
                for (int i = mdHeader.StreamHeaders.Count - 1; i >= 0; i--)
                {
                    var sh = mdHeader.StreamHeaders[i];
                    switch (sh.Name)
                    {
                    case "#Strings":
                        if (stringsStream is null)
                        {
                            stringsStream = new StringsStream(mdReaderFactory, metadataBaseOffset, sh);
                            newAllStreams.Add(stringsStream);
                            continue;
                        }
                        break;

                    case "#US":
                        if (usStream is null)
                        {
                            usStream = new USStream(mdReaderFactory, metadataBaseOffset, sh);
                            newAllStreams.Add(usStream);
                            continue;
                        }
                        break;

                    case "#Blob":
                        if (blobStream is null)
                        {
                            blobStream = new BlobStream(mdReaderFactory, metadataBaseOffset, sh);
                            newAllStreams.Add(blobStream);
                            continue;
                        }
                        break;

                    case "#GUID":
                        if (guidStream is null)
                        {
                            guidStream = new GuidStream(mdReaderFactory, metadataBaseOffset, sh);
                            newAllStreams.Add(guidStream);
                            continue;
                        }
                        break;

                    case "#~":
                        if (tablesStream is null)
                        {
                            tablesStream = new TablesStream(mdReaderFactory, metadataBaseOffset, sh, runtime);
                            newAllStreams.Add(tablesStream);
                            continue;
                        }
                        break;

                    case "#Pdb":
                        if (isStandalonePortablePdb && pdbStream is null)
                        {
                            pdbStream = new PdbStream(mdReaderFactory, metadataBaseOffset, sh);
                            newAllStreams.Add(pdbStream);
                            continue;
                        }
                        break;

                    case "#JTD":
                        if (runtime == CLRRuntimeReaderKind.Mono)
                        {
                            forceAllBig = true;
                            continue;
                        }
                        break;
                    }
                    dns = new CustomDotNetStream(mdReaderFactory, metadataBaseOffset, sh);
                    newAllStreams.Add(dns);
                    dns = null;
                }
            }
            finally {
                dns?.Dispose();
                newAllStreams.Reverse();
                allStreams = newAllStreams;
            }

            if (tablesStream is null)
            {
                throw new BadImageFormatException("Missing MD stream");
            }

            if (pdbStream is not null)
            {
                tablesStream.Initialize(pdbStream.TypeSystemTableRows, forceAllBig);
            }
            else
            {
                tablesStream.Initialize(null, forceAllBig);
            }
        }
Exemple #22
0
        /// <inheritdoc/>
        protected override void InitializeInternal(DataReaderFactory mdReaderFactory, uint metadataBaseOffset)
        {
            DotNetStream dns         = null;
            bool         forceAllBig = false;

            try {
                if (runtime == CLRRuntimeReaderKind.Mono)
                {
                    var newAllStreams = new List <DotNetStream>(allStreams);
                    for (int i = mdHeader.StreamHeaders.Count - 1; i >= 0; i--)
                    {
                        var sh = mdHeader.StreamHeaders[i];
                        switch (sh.Name)
                        {
                        case "#Strings":
                            if (stringsStream is null)
                            {
                                stringsStream = new StringsStream(mdReaderFactory, metadataBaseOffset, sh);
                                newAllStreams.Add(stringsStream);
                                continue;
                            }
                            break;

                        case "#US":
                            if (usStream is null)
                            {
                                usStream = new USStream(mdReaderFactory, metadataBaseOffset, sh);
                                newAllStreams.Add(usStream);
                                continue;
                            }
                            break;

                        case "#Blob":
                            if (blobStream is null)
                            {
                                blobStream = new BlobStream(mdReaderFactory, metadataBaseOffset, sh);
                                newAllStreams.Add(blobStream);
                                continue;
                            }
                            break;

                        case "#GUID":
                            if (guidStream is null)
                            {
                                guidStream = new GuidStream(mdReaderFactory, metadataBaseOffset, sh);
                                newAllStreams.Add(guidStream);
                                continue;
                            }
                            break;

                        case "#~":
                        case "#-":
                            if (tablesStream is null)
                            {
                                tablesStream = new TablesStream(mdReaderFactory, metadataBaseOffset, sh, runtime);
                                newAllStreams.Add(tablesStream);
                                continue;
                            }
                            break;

                        case "#Pdb":
                            if (isStandalonePortablePdb && pdbStream is null)
                            {
                                pdbStream = new PdbStream(mdReaderFactory, metadataBaseOffset, sh);
                                newAllStreams.Add(pdbStream);
                                continue;
                            }
                            break;

                        case "#JTD":
                            forceAllBig = true;
                            continue;
                        }
                        dns = new CustomDotNetStream(mdReaderFactory, metadataBaseOffset, sh);
                        newAllStreams.Add(dns);
                        dns = null;
                    }
                    newAllStreams.Reverse();
                    allStreams = newAllStreams;
                }
                else
                {
                    Debug.Assert(runtime == CLRRuntimeReaderKind.CLR);
                    foreach (var sh in mdHeader.StreamHeaders)
                    {
                        switch (sh.Name.ToUpperInvariant())
                        {
                        case "#STRINGS":
                            if (stringsStream is null)
                            {
                                stringsStream = new StringsStream(mdReaderFactory, metadataBaseOffset, sh);
                                allStreams.Add(stringsStream);
                                continue;
                            }
                            break;

                        case "#US":
                            if (usStream is null)
                            {
                                usStream = new USStream(mdReaderFactory, metadataBaseOffset, sh);
                                allStreams.Add(usStream);
                                continue;
                            }
                            break;

                        case "#BLOB":
                            if (blobStream is null)
                            {
                                blobStream = new BlobStream(mdReaderFactory, metadataBaseOffset, sh);
                                allStreams.Add(blobStream);
                                continue;
                            }
                            break;

                        case "#GUID":
                            if (guidStream is null)
                            {
                                guidStream = new GuidStream(mdReaderFactory, metadataBaseOffset, sh);
                                allStreams.Add(guidStream);
                                continue;
                            }
                            break;

                        case "#~":                          // Only if #Schema is used
                        case "#-":
                            if (tablesStream is null)
                            {
                                tablesStream = new TablesStream(mdReaderFactory, metadataBaseOffset, sh, runtime);
                                allStreams.Add(tablesStream);
                                continue;
                            }
                            break;

                        case "#PDB":
                            // Case sensitive comparison since it's a stream that's not read by the CLR,
                            // only by other libraries eg. System.Reflection.Metadata.
                            if (isStandalonePortablePdb && pdbStream is null && sh.Name == "#Pdb")
                            {
                                pdbStream = new PdbStream(mdReaderFactory, metadataBaseOffset, sh);
                                allStreams.Add(pdbStream);
                                continue;
                            }
                            break;

                        case "#JTD":
                            forceAllBig = true;
                            continue;
                        }
                        dns = new CustomDotNetStream(mdReaderFactory, metadataBaseOffset, sh);
                        allStreams.Add(dns);
                        dns = null;
                    }
                }
            }
            finally {
                dns?.Dispose();
            }

            if (tablesStream is null)
            {
                throw new BadImageFormatException("Missing MD stream");
            }

            if (pdbStream is not null)
            {
                tablesStream.Initialize(pdbStream.TypeSystemTableRows, forceAllBig);
            }
            else
            {
                tablesStream.Initialize(null, forceAllBig);
            }

            // The pointer tables are used iff row count != 0
            hasFieldPtr    = !tablesStream.FieldPtrTable.IsEmpty;
            hasMethodPtr   = !tablesStream.MethodPtrTable.IsEmpty;
            hasParamPtr    = !tablesStream.ParamPtrTable.IsEmpty;
            hasEventPtr    = !tablesStream.EventPtrTable.IsEmpty;
            hasPropertyPtr = !tablesStream.PropertyPtrTable.IsEmpty;

            switch (runtime)
            {
            case CLRRuntimeReaderKind.CLR:
                hasDeletedFields    = tablesStream.HasDelete;
                hasDeletedNonFields = tablesStream.HasDelete;
                break;

            case CLRRuntimeReaderKind.Mono:
                hasDeletedFields    = true;
                hasDeletedNonFields = false;
                break;

            default:
                throw new InvalidOperationException();
            }
        }
Exemple #23
0
        /// <inheritdoc/>
        protected override void InitializeInternal(IImageStream mdStream)
        {
            var hotHeapVersion = peImage == null ? HotHeapVersion.CLR20 : GetHotHeapVersion(peImage.FileName, mdHeader.VersionString);

            bool             disposeOfMdStream = false;
            IImageStream     imageStream = null, fullStream = null;
            DotNetStream     dns = null;
            List <HotStream> hotStreams = null;
            HotStream        hotStream  = null;
            var newAllStreams = new List <DotNetStream>(allStreams);

            try {
                if (peImage != null)
                {
                    Debug.Assert(mdStream == null);
                    Debug.Assert(cor20Header != null);
                    var mdOffset = peImage.ToFileOffset(cor20Header.MetaData.VirtualAddress);
                    mdStream          = peImage.CreateStream(mdOffset, cor20Header.MetaData.Size);
                    disposeOfMdStream = true;
                }
                else
                {
                    Debug.Assert(mdStream != null);
                }
                for (int i = mdHeader.StreamHeaders.Count - 1; i >= 0; i--)
                {
                    var sh = mdHeader.StreamHeaders[i];
                    imageStream = mdStream.Create((FileOffset)sh.Offset, sh.StreamSize);
                    switch (sh.Name)
                    {
                    case "#Strings":
                        if (stringsStream == null)
                        {
                            stringsStream = new StringsStream(imageStream, sh);
                            imageStream   = null;
                            newAllStreams.Add(stringsStream);
                            continue;
                        }
                        break;

                    case "#US":
                        if (usStream == null)
                        {
                            usStream    = new USStream(imageStream, sh);
                            imageStream = null;
                            newAllStreams.Add(usStream);
                            continue;
                        }
                        break;

                    case "#Blob":
                        if (blobStream == null)
                        {
                            blobStream  = new BlobStream(imageStream, sh);
                            imageStream = null;
                            newAllStreams.Add(blobStream);
                            continue;
                        }
                        break;

                    case "#GUID":
                        if (guidStream == null)
                        {
                            guidStream  = new GuidStream(imageStream, sh);
                            imageStream = null;
                            newAllStreams.Add(guidStream);
                            continue;
                        }
                        break;

                    case "#~":
                        if (tablesStream == null)
                        {
                            tablesStream = new TablesStream(imageStream, sh);
                            imageStream  = null;
                            newAllStreams.Add(tablesStream);
                            continue;
                        }
                        break;

                    case "#!":
                        if (peImage == null)
                        {
                            break;
                        }
                        if (hotStreams == null)
                        {
                            hotStreams = new List <HotStream>();
                        }
                        fullStream = peImage.CreateFullStream();
                        hotStream  = HotStream.Create(hotHeapVersion, imageStream, sh, fullStream, mdStream.FileOffset + sh.Offset);
                        fullStream = null;
                        hotStreams.Add(hotStream);
                        newAllStreams.Add(hotStream);
                        hotStream   = null;
                        imageStream = null;
                        continue;

                    case "#Pdb":
                        if (isStandalonePortablePdb && pdbStream == null)
                        {
                            pdbStream   = new PdbStream(imageStream, sh);
                            imageStream = null;
                            allStreams.Add(pdbStream);
                            continue;
                        }
                        break;
                    }
                    dns         = new DotNetStream(imageStream, sh);
                    imageStream = null;
                    newAllStreams.Add(dns);
                    dns = null;
                }
            }
            finally {
                if (disposeOfMdStream)
                {
                    mdStream.Dispose();
                }
                if (imageStream != null)
                {
                    imageStream.Dispose();
                }
                if (fullStream != null)
                {
                    fullStream.Dispose();
                }
                if (dns != null)
                {
                    dns.Dispose();
                }
                if (hotStream != null)
                {
                    hotStream.Dispose();
                }
                newAllStreams.Reverse();
                allStreams = ThreadSafeListCreator.MakeThreadSafe(newAllStreams);
            }

            if (tablesStream == null)
            {
                throw new BadImageFormatException("Missing MD stream");
            }

            if (hotStreams != null)
            {
                hotStreams.Reverse();
                InitializeHotStreams(hotStreams);
            }

            if (pdbStream != null)
            {
                tablesStream.Initialize(pdbStream.TypeSystemTableRows);
            }
            else
            {
                tablesStream.Initialize(null);
            }
        }
		public MDTableHeapModel(dnModule module, TablesStream stream) {
			Module = module;
			Stream = stream;
			Text = "Tables";
		}