/// <summary> /// Initializes a new instance of the <see cref="PdbReader"/> class. /// </summary> /// <param name="stream">The stream.</param> /// <exception cref="System.ArgumentNullException"><paramref name="stream"/> is null.</exception> /// <exception cref="System.ArgumentException"><paramref name="stream"/> must be readable and seekable.</exception> public PdbReader(Stream stream) { if (stream == null) { throw new ArgumentNullException(@"stream"); } if (stream.CanRead == false) { throw new ArgumentException(@"Stream is not readable", @"stream"); } if (stream.CanSeek == false) { throw new ArgumentException(@"Stream must be seekable.", @"stream"); } this.stream = stream; reader = new BinaryReader(stream); // Read the file header if (PdbFileHeader.Read(reader, out header) == false) { throw new InvalidDataException(@"Not a Microsoft program database v7.0 file."); } LoadRootStream(); }
/// <summary> /// Reads the PDB file header from the given reader. /// </summary> /// <param name="reader">The reader to read From.</param> /// <param name="header">The header to populate.</param> /// <returns><c>true</c> if reading was successful, otherwise <c>false</c>.</returns> public static bool Read(BinaryReader reader, out PdbFileHeader header) { if (reader == null) throw new ArgumentNullException(@"reader"); // Read & compare the signature header.signature = reader.ReadBytes(0x20); if (ArrayCompare(header.signature, PdbFileHeader.PdbSignature) == true) { header.dwPageSize = reader.ReadInt32(); header.dwBitmapPage = reader.ReadInt32(); header.dwFilePages = reader.ReadInt32(); header.dwRootBytes = reader.ReadInt32(); header.dwReserved = reader.ReadInt32(); header.dwIndexPage = reader.ReadInt32(); string sig = Encoding.ASCII.GetString(header.signature); sig = sig.Substring(0, sig.IndexOf('\r')); Debug.WriteLine(String.Format("PdbFileHeader:\n\tSignature={0}\n\tPageSize={1}\n\tBitmapPage={2} (at offset {3})\n\tFilePages={4}\n\tRootBytes={5}\n\tReserved={6}\n\tIndexPage={7} (at offset {8})", sig, header.dwPageSize, header.dwBitmapPage, header.dwBitmapPage * header.dwPageSize, header.dwFilePages, header.dwRootBytes, header.dwReserved, header.dwIndexPage, header.dwIndexPage * header.dwPageSize)); // Some more sanity checks at the end if (reader.BaseStream.Length == (header.dwPageSize * header.dwFilePages)) return true; } // Clear what we've read header = new PdbFileHeader(); return false; }
/// <summary> /// Reads the PDB file header from the given reader. /// </summary> /// <param name="reader">The reader to read From.</param> /// <param name="header">The header to populate.</param> /// <returns><c>true</c> if reading was successful, otherwise <c>false</c>.</returns> public static bool Read(BinaryReader reader, out PdbFileHeader header) { if (reader == null) { throw new ArgumentNullException(@"reader"); } // Read & compare the signature header.signature = reader.ReadBytes(0x20); if (ArrayCompare(header.signature, PdbFileHeader.PdbSignature) == true) { header.dwPageSize = reader.ReadInt32(); header.dwBitmapPage = reader.ReadInt32(); header.dwFilePages = reader.ReadInt32(); header.dwRootBytes = reader.ReadInt32(); header.dwReserved = reader.ReadInt32(); header.dwIndexPage = reader.ReadInt32(); string sig = Encoding.ASCII.GetString(header.signature); sig = sig.Substring(0, sig.IndexOf('\r')); Debug.WriteLine(String.Format("PdbFileHeader:\n\tSignature={0}\n\tPageSize={1}\n\tBitmapPage={2} (at offset {3})\n\tFilePages={4}\n\tRootBytes={5}\n\tReserved={6}\n\tIndexPage={7} (at offset {8})", sig, header.dwPageSize, header.dwBitmapPage, header.dwBitmapPage * header.dwPageSize, header.dwFilePages, header.dwRootBytes, header.dwReserved, header.dwIndexPage, header.dwIndexPage * header.dwPageSize)); // Some more sanity checks at the end if (reader.BaseStream.Length == (header.dwPageSize * header.dwFilePages)) { return(true); } } // Clear what we've read header = new PdbFileHeader(); return(false); }