public MsfDirectory(PdbReader reader, PdbFileHeader head, BitAccess bits)
        {
            bits.MinCapacity(head.directorySize);
            int pages = reader.PagesFromSize(head.directorySize);

            // 0..n in page of directory pages.
            reader.Seek(head.directoryRoot, 0);
            bits.FillBuffer(reader.reader, pages * 4);

            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]));
                }
            }
        }
Пример #2
0
        public void WriteMeta(DataStream[] streams, BitAccess bits)
        {
            PdbFileHeader head = new PdbFileHeader(pageSize);

            WriteDirectory(streams,
                           out head.directoryRoot,
                           out head.directorySize,
                           bits);
            WriteFreeMap();

            head.freePageMap = 2;
            head.pagesUsed = usedBytes / pageSize;

            writer.Seek(0, SeekOrigin.Begin);
            head.Write(writer, bits);
        }
Пример #3
0
        private void WriteDirectory(DataStream[] streams,
                                    out int directoryRoot,
                                    out int directorySize,
                                    BitAccess bits)
        {
            DataStream directory = new DataStream();

            int pages = 0;
            for (int s = 0; s < streams.Length; s++) {
                if (streams[s].Length > 0) {
                    pages += streams[s].Pages;
                }
            }

            int use = 4 * (1 + streams.Length + pages);
            bits.MinCapacity(use);
            bits.WriteInt32(streams.Length);
            for (int s = 0; s < streams.Length; s++) {
                bits.WriteInt32(streams[s].Length);
            }
            for (int s = 0; s < streams.Length; s++) {
                if (streams[s].Length > 0) {
                    bits.WriteInt32(streams[s].pages);
                }
            }
            directory.Write(this, bits.Buffer, use);
            directorySize = directory.Length;

            use = 4 * directory.Pages;
            bits.MinCapacity(use);
            bits.WriteInt32(directory.pages);

            DataStream ddir = new DataStream();
            ddir.Write(this, bits.Buffer, use);

            directoryRoot = ddir.pages[0];
        }
Пример #4
0
        static void DumpVerbose(DataStream stream, PdbReader reader)
        {
            byte[] bytes = new byte[reader.PageSize];

            if (stream.Length <= 0) {
                return;
            }

            int left = stream.Length;
            int pos = 0;

            for (int page = 0; left > 0; page++) {
                int todo = bytes.Length;
                if (todo > left) {
                    todo = left;
                }

                stream.Read(reader, pos, bytes, 0, todo);

                for (int i = 0; i < todo; i += 16) {
                    Console.Write("{0,7}:", pos + i);
                    DumpLineExt(bytes, i, todo);
                    Console.WriteLine();
                }

                left -= todo;
                pos += todo;
            }
        }
Пример #5
0
 public static void Dump(DataStream d)
 {
     Console.Write("DataStream({0} bytes", d.Length);
     for (int i = 0; i < d.Pages; i++) {
         Console.Write(",{0}", d.GetPage(i));
     }
     Console.WriteLine(")");
 }
Пример #6
0
        static void SplitStreams(Stream read, string split)
        {
            BitAccess bits = new BitAccess(4096);

            // Read the header and directory from the old file.
            // System.Diagnostics.Debugger.Break();
            PdbFileHeader head = new PdbFileHeader(read, bits);
            PdbReader reader = new PdbReader(read, head.pageSize);
            MsfDirectory dir = new MsfDirectory(reader, head, bits);

            byte[] buffer = new byte[head.pageSize];

            // Copy the streams.
            DataStream[] streams = new DataStream [dir.streams.Length];
            for (int i = 0; i < dir.streams.Length; i++) {
                streams[i] = new DataStream();

                DataStream source = dir.streams[i];
                if (source.Length <= 0) {
                    continue;
                }

                string name = String.Format("{0}.{1:d4}", split, i);
                Console.WriteLine("{0,4}: --> {1}", i, name);

                FileStream writer = new FileStream(name,
                                                   FileMode.Create,
                                                   FileAccess.Write);

                int left = source.Length;
                int pos = 0;

                for (int page = 0; left > 0; page++) {
                    int todo = buffer.Length;
                    if (todo > left) {
                        todo = left;
                    }

                    dir.streams[i].Read(reader, pos, buffer, 0, todo);
                    writer.Write(buffer, 0, todo);

                    left -= todo;
                    pos += todo;
                }
                writer.Close();
            }
        }
Пример #7
0
        static void CopyFile(Stream read, PdbWriter writer)
        {
            BitAccess bits = new BitAccess(4096);

            // Read the header and directory from the old file.
            // System.Diagnostics.Debugger.Break();
            PdbFileHeader head = new PdbFileHeader(read, bits);
            PdbReader reader = new PdbReader(read, head.pageSize);
            MsfDirectory dir = new MsfDirectory(reader, head, bits);

            byte[] buffer = new byte[head.pageSize];

            // Copy the streams.
            DataStream[] streams = new DataStream [dir.streams.Length];
            for (int i = 0; i < dir.streams.Length; i++) {
                streams[i] = new DataStream();

                DataStream source = dir.streams[i];
                if (source.Length <= 0) {
                    continue;
                }

                int left = source.Length;
                int pos = 0;

                for (int page = 0; left > 0; page++) {
                    int todo = buffer.Length;
                    if (todo > left) {
                        todo = left;
                    }

                    dir.streams[i].Read(reader, pos, buffer, 0, todo);
                    streams[i].Write(writer, buffer, todo);

                    left -= todo;
                    pos += todo;
                }
            }

            writer.WriteMeta(streams, bits);
        }