Exemple #1
0
        public MsfDirectory(PdbReader reader, int pageSize, int directorySize, int[] directoryRoot)
        {
            var numPages = reader.PagesFromSize(directorySize);

            var         pages = new int[numPages];
            Span <byte> buf   = MemoryMarshal.Cast <int, byte>(pages);

            var offset       = 0;
            var pagesPerPage = pageSize / 4;
            var pagesToGo    = numPages;

            foreach (var t in directoryRoot)
            {
                var pagesInThisPage = pagesToGo <= pagesPerPage ? pagesToGo : pagesPerPage;
                reader.Seek(t, 0);
                reader.Stream.Read(buf.Slice(offset, pagesInThisPage * 4));
                pagesToGo -= pagesInThisPage;
            }

            using var buffer = new SafeArrayPool <byte>(directorySize);
            var stream = new DataStream(directorySize, pages);

            stream.Read(reader, buffer.Array);

            offset = 0;
            var count = InterpretInt32(buffer.Array, ref offset);

            using var sizesPool = new SafeArrayPool <int>(count);
            int[] sizes = sizesPool.Array;

            for (var i = 0; i < count; ++i)
            {
                sizes[i] = InterpretInt32(buffer.Array, ref offset);
            }

            this.streams = new DataStream[count];

            for (var i = 0; i < count; ++i)
            {
                if (sizes[i] <= 0)
                {
                    this.streams[i] = new DataStream();
                }
                else
                {
                    var dsPagesCount = reader.PagesFromSize(sizes[i]);
                    if (dsPagesCount > 0)
                    {
                        var dsPages = new int[dsPagesCount];

                        for (var j = 0; j < dsPagesCount; ++j)
                        {
                            dsPages[j] = InterpretInt32(buffer.Array, ref offset);
                        }

                        this.streams[i] = new DataStream(sizes[i], dsPages);
                    }
                    else
                    {
                        this.streams[i] = new DataStream(sizes[i], Array.Empty <int>());
                    }
                }
            }
        }