Example #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PdbStream"/> class.
 /// </summary>
 /// <param name="blocks">Array of block indexes in the parent stream.</param>
 /// <param name="length">Length of this stream in bytes.</param>
 /// <param name="file">PDB file that contains this stream.</param>
 public PdbStream(uint[] blocks, uint length, PdbFile file)
 {
     Blocks = blocks;
     Length = length;
     File   = file;
     Reader = new MappedBlockBinaryReader(blocks, file.SuperBlock.BlockSize, length, file.Reader);
 }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PublicsStream"/> class.
        /// </summary>
        /// <param name="file">PDB file containing this stream.</param>
        /// <param name="reader">Binary stream reader.</param>
        public PublicsStream(PdbFile file, IBinaryReader reader)
        {
            if (reader.BytesRemaining < PublicsStreamHeader.Size)
            {
                throw new Exception("Publics Stream does not contain a header.");
            }

            // Read header
            Header = PublicsStreamHeader.Read(reader);

            // Read globals hash table
            if (reader.BytesRemaining < Header.SymbolHashStreamSize)
            {
                throw new Exception("Publics Stream does not contain a header.");
            }
            GlobalsStream = new GlobalsStream(file, reader.ReadSubstream(Header.SymbolHashStreamSize));

            // Read address map
            if (reader.BytesRemaining < Header.AddressMapSize)
            {
                throw new Exception("Could not read an address map.");
            }
            AddressMap = reader.ReadUintArray((int)(Header.AddressMapSize / 4)); // 4 = sizeof(uint)

            // Read thunk map
            if (reader.BytesRemaining < Header.NumberOfThunks * 4) // 4 = sizeof(uint)
            {
                throw new Exception("Could not read a thunk map.");
            }
            ThunkMap = reader.ReadUintArray((int)Header.NumberOfThunks);

            // Read sections
            if (reader.BytesRemaining < Header.NumberOfSections * PublicsStreamSectionOffset.Size)
            {
                throw new Exception("Publics stream doesn't contain all sections specified in the header.");
            }
            PublicsStreamSectionOffset[] sections = new PublicsStreamSectionOffset[Header.NumberOfSections];
            for (int i = 0; i < sections.Length; i++)
            {
                sections[i] = PublicsStreamSectionOffset.Read(reader);
            }
            Sections = sections;

            if (reader.BytesRemaining > 0)
            {
                throw new Exception("Corrupted publics stream.");
            }

            publicSymbolsCache = SimpleCache.CreateStruct(() =>
            {
                Public32Symbol[] publicSymbols = new Public32Symbol[GlobalsStream.Symbols.Count];

                for (int i = 0; i < publicSymbols.Length; i++)
                {
                    publicSymbols[i] = GlobalsStream.Symbols[i] as Public32Symbol;
                }
                return(publicSymbols);
            });
        }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PdbFile"/> class.
        /// </summary>
        /// <param name="file">File loaded into memory for faster parsing.</param>
        public PdbFile(MemoryLoadedFile file)
        {
            Reader         = new SharpPdb.Windows.PdbFile(file);
            functionsCache = SimpleCache.CreateStruct(() =>
            {
                List <IPdbFunction> functions = new List <IPdbFunction>();

                foreach (var dbiModule in Reader.DbiStream.Modules)
                {
                    var symbolStream = dbiModule.LocalSymbolStream;

                    foreach (var kind in ManagedProcedureSymbol.Kinds)
                    {
                        foreach (ManagedProcedureSymbol procedure in symbolStream[kind])
                        {
                            functions.Add(new PdbFunction(this, procedure, dbiModule));
                        }
                    }
                }
                return(functions);
            });
            sourcesCache          = new DictionaryCache <FileChecksumSubsection, PdbSource>(checksum => new PdbSource(this, checksum));
            functionsByTokenCache = SimpleCache.CreateStruct(() => Functions.ToDictionary(f => f.Token));
            tokenRidMapCache      = SimpleCache.CreateStruct(() =>
            {
                var reader = Reader.DbiStream.GetKnownDebugStream(KnownDebugStreamIndex.TokenRidMap)?.Reader;

                if (reader == null)
                {
                    return(null);
                }

                int count          = (int)(reader.Length / 4); // 4 = sizeof(uint)
                uint[] tokenRidMap = new uint[count];

                for (int i = 0; i < count; i++)
                {
                    tokenRidMap[i] = reader.ReadUint();
                }
                return(tokenRidMap);
            });
            this.file = file;
        }