/// <summary> /// Reads the specified reader. /// </summary> /// <param name="reader">The reader.</param> /// <param name="pageSize">Holds the size of a single page in the file.</param> /// <param name="rootStream">The root stream.</param> /// <returns></returns> public static bool Read(BinaryReader reader, int pageSize, out PdbRootStream rootStream) { rootStream.streams = reader.ReadInt32(); Debug.WriteLine(String.Format(@"PdbRootStream: PDB file contains {0} streams.", rootStream.streams)); rootStream.streamLength = new int[rootStream.streams]; rootStream.streamPages = new int[rootStream.streams][]; for (int i = 0; i < rootStream.streams; i++) { rootStream.streamLength[i] = reader.ReadInt32(); } for (int i = 0; i < rootStream.streams; i++) { Debug.WriteLine(String.Format("\tPDB Stream #{0} (Length {1} bytes)", i, rootStream.streamLength[i])); if (rootStream.streamLength[i] > 0) { rootStream.streamPages[i] = new int[(rootStream.streamLength[i] / pageSize) + 1]; for (int j = 0; j < rootStream.streamPages[i].Length; j++) { rootStream.streamPages[i][j] = reader.ReadInt32(); Debug.WriteLine(String.Format("\t\tPage {0} (at offset {1})", rootStream.streamPages[i][j], rootStream.streamPages[i][j] * pageSize)); } } } return(true); }
/// <summary> /// Reads the specified reader. /// </summary> /// <param name="reader">The reader.</param> /// <param name="pageSize">Holds the size of a single page in the file.</param> /// <param name="rootStream">The root stream.</param> /// <returns></returns> public static bool Read(BinaryReader reader, int pageSize, out PdbRootStream rootStream) { rootStream.streams = reader.ReadInt32(); Debug.WriteLine(String.Format(@"PdbRootStream: PDB file contains {0} streams.", rootStream.streams)); rootStream.streamLength = new int[rootStream.streams]; rootStream.streamPages = new int[rootStream.streams][]; for (int i = 0; i < rootStream.streams; i++) rootStream.streamLength[i] = reader.ReadInt32(); for (int i = 0; i < rootStream.streams; i++) { Debug.WriteLine(String.Format("\tPDB Stream #{0} (Length {1} bytes)", i, rootStream.streamLength[i])); if (rootStream.streamLength[i] > 0) { rootStream.streamPages[i] = new int[(rootStream.streamLength[i] / pageSize) + 1]; for (int j = 0; j < rootStream.streamPages[i].Length; j++) { rootStream.streamPages[i][j] = reader.ReadInt32(); Debug.WriteLine(String.Format("\t\tPage {0} (at offset {1})", rootStream.streamPages[i][j], rootStream.streamPages[i][j] * pageSize)); } } } return true; }
/// <summary> /// Loads the root stream. /// </summary> private void LoadRootStream() { // The root stream length int dwStreamLength = header.dwRootBytes; // Calculate the number of pages of the root stream int pageCount = (dwStreamLength / header.dwPageSize) + 1; // Allocate page list int[] pages = new int[pageCount]; // Read the pages stream.Position = header.dwIndexPage * header.dwPageSize; for (int i = 0; i < pageCount; i++) { pages[i] = reader.ReadInt32(); Debug.WriteLine(String.Format(@"PdbReader: Root stream page {0} (at offset {1})", pages[i], pages[i] * header.dwPageSize)); } using (var pdbStream = GetStream(pages, dwStreamLength)) { using (var rootReader = new BinaryReader(pdbStream)) { PdbRootStream.Read(rootReader, header.dwPageSize, out root); } } }