internal void Read(PdbStreamHelper reader, int position, byte[] bytes, int offset, int data) { if (position + data > _contentSize) { throw new PdbException("DataStream can't read off end of stream. " + "(pos={0},siz={1})", position, data); } if (position == _contentSize) { return; } int left = data; int page = position / reader.PageSize; int rema = position % reader.PageSize; // First get remained of first page. if (rema != 0) { int todo = reader.PageSize - rema; if (todo > left) { todo = left; } reader.Seek(_pages[page], rema); reader.Read(bytes, offset, todo); offset += todo; left -= todo; page++; } // Now get the remaining pages. while (left > 0) { int todo = reader.PageSize; if (todo > left) { todo = left; } reader.Seek(_pages[page], 0); reader.Read(bytes, offset, todo); offset += todo; left -= todo; page++; } }
internal MsfDirectory(PdbStreamHelper reader, PdbFileHeader head, BitAccess bits) { int pages = reader.PagesFromSize(head.DirectorySize); // 0..n in page of directory pages. bits.MinCapacity(head.DirectorySize); int directoryRootPages = head.DirectoryRoot.Length; int pagesPerPage = head.PageSize / 4; int pagesToGo = pages; for (int i = 0; i < directoryRootPages; i++) { int pagesInThisPage = pagesToGo <= pagesPerPage ? pagesToGo : pagesPerPage; reader.Seek(head.DirectoryRoot[i], 0); bits.Append(reader.Reader, pagesInThisPage * 4); pagesToGo -= pagesInThisPage; } bits.Position = 0; DataStream stream = new DataStream(head.DirectorySize, bits, pages); bits.MinCapacity(head.DirectorySize); stream.Read(reader, bits); // 0..3 in directory pages int count; bits.ReadInt32(out count); // 4..n int[] sizes = new int[count]; bits.ReadInt32(sizes); // n..m _streams = new DataStream[count]; for (int i = 0; i < count; i++) { if (sizes[i] <= 0) { _streams[i] = new DataStream(); } else { _streams[i] = new DataStream(sizes[i], bits, reader.PagesFromSize(sizes[i])); } } }