Example #1
0
 private static int OrderStreamsByLengthForPdbPartial(PdbPartialStream leftStream, PdbPartialStream rightStream)
 {
     //TODO Make A Static Sorter Class And Move Into It
     return(rightStream.DecompossedPartialStream.Length.CompareTo(leftStream.DecompossedPartialStream.Length));
 }
Example #2
0
        /// <summary>
        /// This Method Reads The Root Byte Pages, Composes The Root Stream, Extracts The Streams From The RootStream And Composes And Exposes Them Out.
        /// </summary>
        /// <param name="mainStream">The PdbStream That Will Be Extracted</param>
        /// <param name="adIndexPages"></param>
        /// <param name="sizeForRootIndexBytes"></param>
        /// <remarks>
        /// </remarks>
        /// <returns></returns>
        private bool BuildUpRootStream(System.IO.Stream mainStream,
                                       List <uint> adIndexPages,
                                       uint sizeForRootIndexBytes)
        {
            // There seems to be a bug, will be fixed now
            //Reads Whole Bytes That Buildup The Root Stream
            System.IO.MemoryStream rootStream =
                ReadBlockBytesFromStream(mainStream,
                                         adIndexPages,
                                         sizeForRootIndexBytes);

            System.IO.MemoryStream rootStreamComposed =
                new System.IO.MemoryStream();

            UInt32 totalSizes = this.m_dRootBytes;

            int totalCount = 0;

            using (BinaryReader rootStreamReader =
                       new BinaryReader(rootStream))
            {
                //Composes The Root Stream From The Found Out Pages
                while ((rootStream.Position + 1) < rootStream.Length)
                {
                    totalCount++;
                    byte[] firstPageData2 =
                        new byte[m_dPageBytes];

                    uint targetPage =
                        rootStreamReader.ReadUInt32();

                    m_rootStreamTargetPages.Add(targetPage * m_dPageBytes);

                    mainStream.Seek((targetPage * m_dPageBytes), SeekOrigin.Begin);

                    int tempReadedAmount =
                        mainStream.Read(firstPageData2, 0, (int)m_dPageBytes);

                    uint currentPosition =
                        BitConverter.ToUInt32(firstPageData2, 0);

                    if (totalSizes < tempReadedAmount)
                    {
                        tempReadedAmount = (int)totalSizes;
                    }
                    else
                    {
                        totalSizes -= (uint)tempReadedAmount;
                    }

                    rootStreamComposed.Write(firstPageData2, 0, tempReadedAmount);
                }
            }

            rootStreamComposed.Position = 0;

            m_rootStream =
                new MemoryStream(rootStreamComposed.ToArray());

            m_rootStreamContainer =
                new MemoryStream();

            rootStreamComposed.WriteTo(m_rootStreamContainer);

            Debug.Assert(m_dRootBytes == rootStreamComposed.Length, "Base Transfer Failed");

            //   Ok Now We have the root directory stream
            //   Go Read Each Of The ChildStreams And Compose Them To MemoryStreams :)
            using (BinaryReader testReader = new BinaryReader(rootStreamComposed))
            {
                //Ok First DWORD In The Stream Is The Count Of The Whole Streams Including BaseStream
                StreamCount = testReader.ReadUInt32();

                Debug.WriteLine("Total Streams Contained:", StreamCount.ToString());

                ///Here are the sizes for each of the separated stream sizes
                for (uint streamCounter = 0;
                     streamCounter < StreamCount;
                     streamCounter++)
                {
                    PdbPartialStream partialStream =
                        new PdbPartialStream(this.m_dPageBytes);

                    partialStream.InitialSize =
                        testReader.ReadUInt32();

                    partialStream.StreamLocation =
                        streamCounter;

                    StreamLengths.Add(streamCounter,
                                      partialStream.InitialSize);

                    m_partialStreamDirectory.Add(streamCounter,
                                                 partialStream);
                }
                ///Build up the streams using the pages located here
                for (uint subDetailCounter = 0;
                     subDetailCounter < StreamCount;
                     subDetailCounter++)
                {
                    uint streamLength =
                        StreamLengths[subDetailCounter];

                    PdbPartialStream partialStream =
                        m_partialStreamDirectory[subDetailCounter];

                    uint pageCountToBeReaded =
                        CalculateDWORDCountForRootIndex(streamLength);

                    List <uint> wholeAddresses =
                        new List <uint>();

                    System.IO.MemoryStream finalStream =
                        new System.IO.MemoryStream();

                    if (streamLength == 0 || streamLength == pdbEmptyStreamHeader)
                    {
                        pageCountToBeReaded = 0;
                    }

                    partialStream.RootStreamBeginIndex =
                        (uint)testReader.BaseStream.Position;

                    bool shouldExit = false;

                    if ((testReader.BaseStream.Position + 1) < testReader.BaseStream.Length)
                    {
                        for (int pageCounter = 0;
                             pageCounter < pageCountToBeReaded;
                             pageCounter++)
                        {
                            byte[] finalStreamDataContainer =
                                new byte[m_dPageBytes];

                            uint currentStreamSourcePage =
                                testReader.ReadUInt32();

                            partialStream.PagesUsedByStream.Add(currentStreamSourcePage);

                            mainStream.Seek((currentStreamSourcePage * m_dPageBytes),
                                            SeekOrigin.Begin);

                            int streamSourcePagesRead =
                                mainStream.Read(finalStreamDataContainer, 0, (int)m_dPageBytes);

                            uint currentPositionStreamBegin =
                                BitConverter.ToUInt32(finalStreamDataContainer, 0);

                            if (streamLength < streamSourcePagesRead)
                            {
                                streamSourcePagesRead = (int)streamLength;
                                shouldExit            = true;
                            }
                            else
                            {
                                streamLength -= (uint)streamSourcePagesRead;
                            }

                            finalStream.Write(finalStreamDataContainer, 0, streamSourcePagesRead);

                            if (shouldExit)
                            {
                                break;
                            }
                        }
                    }
                    partialStream.BuildUpDecomposedPartialStream(mainStream);
                    if (InternalStreams.Count == 1)
                    {
                        m_Reader =
                            new PdbInfoStreamReader(partialStream.DecompossedPartialStream);
                        m_Reader.ParseStream();
                    }
                    InternalStreams.Add(partialStream.DecompossedPartialStream);

                    StreamDictionary.Add(subDetailCounter, partialStream.DecompossedPartialStream);
                }
            }

            return(true);
        }