internal PdbFileHeader(Stream reader, BitAccess bits) { bits.MinCapacity(56); reader.Seek(0, SeekOrigin.Begin); bits.FillBuffer(reader, 52); this.magic = new byte[32]; bits.ReadBytes(this.magic); // 0..31 bits.ReadInt32(out this.pageSize); // 32..35 bits.ReadInt32(out this.freePageMap); // 36..39 bits.ReadInt32(out this.pagesUsed); // 40..43 bits.ReadInt32(out this.directorySize); // 44..47 bits.ReadInt32(out this.zero); // 48..51 /*Telerik Authorship early fix*/ if (Magic != MAGIC) { throw new InvalidOperationException("Magic is wrong."); } int directoryPages = ((((directorySize + pageSize - 1) / pageSize) * 4) + pageSize - 1) / pageSize; this.directoryRoot = new int[directoryPages]; bits.FillBuffer(reader, directoryPages * 4); bits.ReadInt32(this.directoryRoot); }
//internal PdbFileHeader(int pageSize) { // this.magic = new byte[32] { // 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, // "Microsof" // 0x74, 0x20, 0x43, 0x2F, 0x43, 0x2B, 0x2B, 0x20, // "t C/C++ " // 0x4D, 0x53, 0x46, 0x20, 0x37, 0x2E, 0x30, 0x30, // "MSF 7.00" // 0x0D, 0x0A, 0x1A, 0x44, 0x53, 0x00, 0x00, 0x00 // "^^^DS^^^" // }; // this.pageSize = pageSize; //} internal PdbFileHeader(Stream reader, BitAccess bits) { bits.MinCapacity(56); reader.Seek(0, SeekOrigin.Begin); bits.FillBuffer(reader, 52); this.magic = new byte[32]; bits.ReadBytes(this.magic); // 0..31 bits.ReadInt32(out this.pageSize); // 32..35 bits.ReadInt32(out this.freePageMap); // 36..39 bits.ReadInt32(out this.pagesUsed); // 40..43 bits.ReadInt32(out this.directorySize); // 44..47 bits.ReadInt32(out this.zero); // 48..51 if (!this.magic.SequenceEqual(windowsPdbMagic)) { throw new PdbException("The PDB file is not recognized as a Windows PDB file"); } int directoryPages = ((((directorySize + pageSize - 1) / pageSize) * 4) + pageSize - 1) / pageSize; this.directoryRoot = new int[directoryPages]; bits.FillBuffer(reader, directoryPages * 4); bits.ReadInt32(this.directoryRoot); }
internal PdbFileHeader(Stream reader, BitAccess bits) { bits.MinCapacity(56); reader.Seek(0, SeekOrigin.Begin); bits.FillBuffer(reader, 56); this.magic = new byte[32]; bits.ReadBytes(this.magic); // 0..31 bits.ReadInt32(out this.pageSize); // 32..35 bits.ReadInt32(out this.freePageMap); // 36..39 bits.ReadInt32(out this.pagesUsed); // 40..43 bits.ReadInt32(out this.directorySize); // 44..47 bits.ReadInt32(out this.zero); // 48..51 bits.ReadInt32(out this.directoryRoot); // 52..55 }
internal PdbFileHeader(Stream reader, BitAccess bits) { bits.MinCapacity(56); reader.Seek(0, SeekOrigin.Begin); bits.FillBuffer(reader, 56); this.magic = new byte[32]; bits.ReadBytes(this.magic); // 0..31 bits.ReadInt32(out this.PageSize); // 32..35 bits.ReadInt32(out this.FreePageMap); // 36..39 bits.ReadInt32(out this.PagesUsed); // 40..43 bits.ReadInt32(out this.DirectorySize); // 44..47 bits.ReadInt32(out this.Zero); // 48..51 bits.ReadInt32(out this.DirectoryRoot); // 52..55 }
static void LoadInjectedSourceInformation(BitAccess bits, out Guid doctype, out Guid language, out Guid vendor, out Guid checksumAlgo, out byte[] checksum) { int checksumSize; int injectedSourceSize; checksum = null; bits.ReadGuid(out language); bits.ReadGuid(out vendor); bits.ReadGuid(out doctype); bits.ReadGuid(out checksumAlgo); bits.ReadInt32(out checksumSize); bits.ReadInt32(out injectedSourceSize); if (checksumSize > 0) { checksum = new byte[checksumSize]; bits.ReadBytes(checksum); } }
//internal PdbFileHeader(int pageSize) { // this.magic = new byte[32] { // 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, // "Microsof" // 0x74, 0x20, 0x43, 0x2F, 0x43, 0x2B, 0x2B, 0x20, // "t C/C++ " // 0x4D, 0x53, 0x46, 0x20, 0x37, 0x2E, 0x30, 0x30, // "MSF 7.00" // 0x0D, 0x0A, 0x1A, 0x44, 0x53, 0x00, 0x00, 0x00 // "^^^DS^^^" // }; // this.pageSize = pageSize; //} internal PdbFileHeader(Stream reader, BitAccess bits) { bits.MinCapacity(56); reader.Seek(0, SeekOrigin.Begin); bits.FillBuffer(reader, 52); this.magic = new byte[32]; bits.ReadBytes(this.magic); // 0..31 bits.ReadInt32(out this.pageSize); // 32..35 bits.ReadInt32(out this.freePageMap); // 36..39 bits.ReadInt32(out this.pagesUsed); // 40..43 bits.ReadInt32(out this.directorySize); // 44..47 bits.ReadInt32(out this.zero); // 48..51 int directoryPages = ((((directorySize + pageSize - 1) / pageSize) * 4) + pageSize - 1) / pageSize; this.directoryRoot = new int[directoryPages]; bits.FillBuffer(reader, directoryPages * 4); bits.ReadInt32(this.directoryRoot); }
static void LoadInjectedSourceInformation(BitAccess bits, out Guid doctype, out Guid language, out Guid vendor, out Guid checksumAlgo, out byte[] checksum) { int checksumSize; int injectedSourceSize; checksum = null; bits.ReadGuid(out language); bits.ReadGuid(out vendor); bits.ReadGuid(out doctype); bits.ReadGuid(out checksumAlgo); bits.ReadInt32(out checksumSize); bits.ReadInt32(out injectedSourceSize); if (checksumSize > 0) { checksum = new byte[checksumSize]; bits.ReadBytes(checksum); } }
internal PdbFileHeader(Stream reader, BitAccess bits) { bits.MinCapacity(56); reader.Seek(0, SeekOrigin.Begin); bits.FillBuffer(reader, 52); this.magic = new byte[32]; bits.ReadBytes(this.magic); // 0..31 bits.ReadInt32(out this.pageSize); // 32..35 bits.ReadInt32(out this.freePageMap); // 36..39 bits.ReadInt32(out this.pagesUsed); // 40..43 bits.ReadInt32(out this.directorySize); // 44..47 bits.ReadInt32(out this.zero); // 48..51 if (Magic != MAGIC) { throw new InvalidOperationException("Magic is wrong."); } int directoryPages = ((((directorySize + pageSize - 1) / pageSize) * 4) + pageSize - 1) / pageSize; this.directoryRoot = new int[directoryPages]; bits.FillBuffer(reader, directoryPages * 4); bits.ReadInt32(this.directoryRoot); }
internal static PdbInfo LoadFunctions(Stream read) { PdbInfo pdbInfo = new PdbInfo(); pdbInfo.TokenToSourceMapping = new Dictionary <uint, PdbTokenLine>(); BitAccess bits = new BitAccess(64 * 1024); PdbFileHeader head = new PdbFileHeader(read, bits); PdbReader reader = new PdbReader(read, head.pageSize); MsfDirectory dir = new MsfDirectory(reader, head, bits); DbiModuleInfo[] modules = null; DbiDbgHdr header; Dictionary <string, PdbSource> sourceCache = new Dictionary <string, PdbSource>(); dir.streams[1].Read(reader, bits); Dictionary <string, int> nameIndex = LoadNameIndex(bits, out pdbInfo.Age, out pdbInfo.Guid); int nameStream; if (!nameIndex.TryGetValue("/NAMES", out nameStream)) { throw new PdbException("Could not find the '/NAMES' stream: the PDB file may be a public symbol file instead of a private symbol file"); } dir.streams[nameStream].Read(reader, bits); IntHashTable names = LoadNameStream(bits); int srcsrvStream; if (!nameIndex.TryGetValue("SRCSRV", out srcsrvStream)) { pdbInfo.SourceServerData = string.Empty; } else { DataStream dataStream = dir.streams[srcsrvStream]; byte[] bytes = new byte[dataStream.contentSize]; dataStream.Read(reader, bits); pdbInfo.SourceServerData = bits.ReadBString(bytes.Length); } int sourceLinkStream; if (nameIndex.TryGetValue("SOURCELINK", out sourceLinkStream)) { DataStream dataStream = dir.streams[sourceLinkStream]; pdbInfo.SourceLinkData = new byte[dataStream.contentSize]; dataStream.Read(reader, bits); bits.ReadBytes(pdbInfo.SourceLinkData); } dir.streams[3].Read(reader, bits); LoadDbiStream(bits, out modules, out header, true); List <PdbFunction> funcList = new List <PdbFunction>(); if (modules != null) { for (int m = 0; m < modules.Length; m++) { var module = modules[m]; if (module.stream > 0) { dir.streams[module.stream].Read(reader, bits); if (module.moduleName == "TokenSourceLineInfo") { LoadTokenToSourceInfo(bits, module, names, dir, nameIndex, reader, pdbInfo.TokenToSourceMapping, sourceCache); continue; } LoadFuncsFromDbiModule(bits, module, names, funcList, true, dir, nameIndex, reader, sourceCache); } } } PdbFunction[] funcs = funcList.ToArray(); // 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); pdbInfo.Functions = funcs; return(pdbInfo); }