Exemplo n.º 1
0
        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]));
                }
            }
        }
Exemplo n.º 2
0
        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]));
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the properties of a given pdb.  Throws IOException on error.
        /// </summary>
        /// <param name="pdbFile">The pdb file to load.</param>
        /// <param name="signature">The signature of pdbFile.</param>
        /// <param name="age">The age of pdbFile.</param>
        public static void GetPdbProperties(string pdbFile, out Guid signature, out int age)
        {
            BitAccess bits = new BitAccess(512 * 1024);
            using (FileStream pdbStream = File.OpenRead(pdbFile))
            {
                PdbFileHeader header = new PdbFileHeader(pdbStream, bits);
                PdbStreamHelper reader = new PdbStreamHelper(pdbStream, header.PageSize);
                MsfDirectory dir = new MsfDirectory(reader, header, bits);

                dir._streams[1].Read(reader, bits);

                int ver, sig;
                bits.ReadInt32(out ver);    //  0..3  Version
                bits.ReadInt32(out sig);    //  4..7  Signature
                bits.ReadInt32(out age);    //  8..11 Age
                bits.ReadGuid(out signature);       // 12..27 GUID
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the properties of a given pdb.  Throws IOException on error.
        /// </summary>
        /// <param name="pdbFile">The pdb file to load.</param>
        /// <param name="signature">The signature of pdbFile.</param>
        /// <param name="age">The age of pdbFile.</param>
        public static void GetPdbProperties(string pdbFile, out Guid signature, out int age)
        {
            BitAccess bits = new BitAccess(512 * 1024);

            using (FileStream pdbStream = File.OpenRead(pdbFile))
            {
                PdbFileHeader   header = new PdbFileHeader(pdbStream, bits);
                PdbStreamHelper reader = new PdbStreamHelper(pdbStream, header.PageSize);
                MsfDirectory    dir    = new MsfDirectory(reader, header, bits);

                dir._streams[1].Read(reader, bits);

                int ver, sig;
                bits.ReadInt32(out ver);      //  0..3  Version
                bits.ReadInt32(out sig);      //  4..7  Signature
                bits.ReadInt32(out age);      //  8..11 Age
                bits.ReadGuid(out signature); // 12..27 GUID
            }
        }
Exemplo n.º 5
0
        internal static PdbFunction[] LoadFunctions(
            Stream read,
            BitAccess bits,
            bool readAllStrings,
            out int ver,
            out int sig,
            out int age,
            out Guid guid,
            out IEnumerable <PdbSource> sources)
        {
            sources = null;
            PdbFileHeader   head   = new PdbFileHeader(read, bits);
            PdbStreamHelper reader = new PdbStreamHelper(read, head.PageSize);
            MsfDirectory    dir    = new MsfDirectory(reader, head, bits);

            DbiModuleInfo[] modules = null;
            DbiDbgHdr       header;

            dir._streams[1].Read(reader, bits);
            Dictionary <string, int> nameIndex = LoadNameIndex(bits, out ver, out sig, out age, out guid);
            int nameStream;

            if (!nameIndex.TryGetValue("/NAMES", out nameStream))
            {
                throw new PdbException("No `name' stream");
            }

            dir._streams[nameStream].Read(reader, bits);
            Dictionary <int, string> names = LoadNameStream(bits);

            dir._streams[3].Read(reader, bits);
            LoadDbiStream(bits, out modules, out header, readAllStrings);

            List <PdbFunction>             funcList         = new List <PdbFunction>();
            Dictionary <string, PdbSource> sourceDictionary = new Dictionary <string, PdbSource>();

            if (modules != null)
            {
                for (int m = 0; m < modules.Length; m++)
                {
                    if (modules[m].stream > 0)
                    {
                        dir._streams[modules[m].stream].Read(reader, bits);
                        LoadFuncsFromDbiModule(
                            bits,
                            modules[m],
                            names,
                            funcList,
                            readAllStrings,
                            dir,
                            nameIndex,
                            reader,
                            sourceDictionary);
                    }
                }
            }

            PdbFunction[] funcs = funcList.ToArray();
            sources = sourceDictionary.Values;

            // After reading the functions, apply the token remapping table if it exists.
            if (header.snTokenRidMap != 0 && header.snTokenRidMap != 0xffff)
            {
                dir._streams[header.snTokenRidMap].Read(reader, bits);
                uint[] ridMap = new uint[dir._streams[header.snTokenRidMap].Length / 4];
                bits.ReadUInt32(ridMap);

                foreach (PdbFunction func in funcs)
                {
                    func.Token = 0x06000000 | ridMap[func.Token & 0xffffff];
                }
            }

            //
            Array.Sort(funcs, PdbFunction.byAddressAndToken);
            //Array.Sort(funcs, PdbFunction.byToken);
            return(funcs);
        }
Exemplo n.º 6
0
        internal static PdbFunction[] LoadFunctions(Stream read,
                                                    BitAccess bits,
                                                    bool readAllStrings,
                                                    out int ver,
                                                    out int sig,
                                                    out int age,
                                                    out Guid guid,
                                                    out IEnumerable<PdbSource> sources)
        {
            sources = null;
            PdbFileHeader head = new PdbFileHeader(read, bits);
            PdbStreamHelper reader = new PdbStreamHelper(read, head.PageSize);
            MsfDirectory dir = new MsfDirectory(reader, head, bits);
            DbiModuleInfo[] modules = null;
            DbiDbgHdr header;

            dir._streams[1].Read(reader, bits);
            Dictionary<string, int> nameIndex = LoadNameIndex(bits, out ver, out sig, out age, out guid);
            int nameStream;
            if (!nameIndex.TryGetValue("/NAMES", out nameStream))
            {
                throw new PdbException("No `name' stream");
            }

            dir._streams[nameStream].Read(reader, bits);
            Dictionary<int, string> names = LoadNameStream(bits);

            dir._streams[3].Read(reader, bits);
            LoadDbiStream(bits, out modules, out header, readAllStrings);

            List<PdbFunction> funcList = new List<PdbFunction>();
            Dictionary<string, PdbSource> sourceDictionary = new Dictionary<string, PdbSource>();
            if (modules != null)
            {
                for (int m = 0; m < modules.Length; m++)
                {
                    if (modules[m].stream > 0)
                    {
                        dir._streams[modules[m].stream].Read(reader, bits);
                        LoadFuncsFromDbiModule(bits, modules[m], names, funcList,
                                               readAllStrings, dir, nameIndex, reader, sourceDictionary);
                    }
                }
            }

            PdbFunction[] funcs = funcList.ToArray();
            sources = sourceDictionary.Values;

            // After reading the functions, apply the token remapping table if it exists.
            if (header.snTokenRidMap != 0 && header.snTokenRidMap != 0xffff)
            {
                dir._streams[header.snTokenRidMap].Read(reader, bits);
                uint[] ridMap = new uint[dir._streams[header.snTokenRidMap].Length / 4];
                bits.ReadUInt32(ridMap);

                foreach (PdbFunction func in funcs)
                {
                    func.Token = 0x06000000 | ridMap[func.Token & 0xffffff];
                }
            }

            //
            Array.Sort(funcs, PdbFunction.byAddressAndToken);
            //Array.Sort(funcs, PdbFunction.byToken);
            return funcs;
        }