Example #1
0
    internal 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]));
        }
      }
    }
Example #2
0
        internal static PdbFunction[] LoadFunctions(Stream read, out Dictionary<uint, PdbTokenLine> tokenToSourceMapping)
        {
            tokenToSourceMapping = new Dictionary<uint, PdbTokenLine>();
              BitAccess bits = new BitAccess(512 * 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;

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

              dir.streams[nameStream].Read(reader, bits);
              IntHashTable names = LoadNameStream(bits);

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

              ArrayList funcList = new ArrayList();

              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, tokenToSourceMapping);
              continue;
            }
            LoadFuncsFromDbiModule(bits, module, names, funcList, true, dir, nameIndex, reader);
              }
            }
              }

              PdbFunction[] funcs = (PdbFunction[])funcList.ToArray(typeof(PdbFunction));

              // 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;
        }
Example #3
0
        internal static PdbFunction[] LoadFunctions(Stream read, BitAccess bits, bool readAllStrings)
        {
            PdbFileHeader head = new PdbFileHeader(read, bits);
              PdbReader reader = new PdbReader(read, head.PageSize);
              MsfDirectory dir = new MsfDirectory(reader, head, bits);
              DbiModuleInfo[] modules;
              DbiDbgHdr header;

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

              dir.streams[nameStream].Read(reader, bits);
              IntHashTable names = LoadNameStream(bits);

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

              ArrayList funcList = new ArrayList();

              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);
              }
            }
              }

              PdbFunction[] funcs = (PdbFunction[])funcList.ToArray(typeof(PdbFunction));

              // 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.ByAddress);
              //Array.Sort(funcs, PdbFunction.byToken);
              return funcs;
        }
Example #4
0
    internal 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);
    }
    internal MsfDirectory(PdbReader 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]));
        }
      }
    }
            public void WriteHash(string pdbFileHash, string hash)
            {
                Guid guid = new Guid(hash.Remove(32));
                int age = int.Parse(hash.Substring(32), NumberStyles.HexNumber);

                using (var read = File.Open(pdbFileHash, FileMode.Open))
                {
                    PdbFileHeader head = new PdbFileHeader(read, bits);
                    PdbReader reader = new PdbReader(read, head.pageSize);
                    MsfDirectory dir = new MsfDirectory(reader, head, bits);

                    reader.Seek(dir.streams[1].pages[0], 8); //bo przeskakujemy 8 znaków na ver i sig

                    using (BinaryWriter writer = new BinaryWriter(read))
                    {
                        writer.Write(age);
                        writer.Write(guid.ToByteArray());
                    }
                }
            }
            public string ReadHash(string pdbFileHash)
            {
                using (var read = File.Open(pdbFileHash, FileMode.Open))
                {
                    PdbFileHeader head = new PdbFileHeader(read, bits);
                    PdbReader reader = new PdbReader(read, head.pageSize);
                    MsfDirectory dir = new MsfDirectory(reader, head, bits);

                    bits.MinCapacity(28);
                    reader.Seek(dir.streams[1].pages[0], 0);
                    reader.Read(bits.Buffer, 0, 28);

                    int ver;
                    int sig;
                    int age;
                    Guid guid;
                    bits.ReadInt32(out ver); //  0..3  Version
                    bits.ReadInt32(out sig); //  4..7  Signature
                    bits.ReadInt32(out age); //  8..11 Age
                    bits.ReadGuid(out guid); // 12..27 GUID
                    return (guid.ToString("N") + age.ToString("x")).ToUpper();
                }
            }
Example #8
0
    internal static uint[] LoadRemapTable(Stream read)
    {
      //tokenToSourceMapping = new Dictionary<uint, PdbTokenLine>();
      BitAccess bits = new BitAccess(512 * 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;

      dir.streams[1].Read(reader, bits);
      Dictionary<string, int> nameIndex = LoadNameIndex(bits);
      int nameStream;
      if (!nameIndex.TryGetValue("/NAMES", out nameStream))
      {
        throw new NoNameStreamPdbException();
      }
      dir.streams[nameStream].Read(reader, bits);
      IntHashTable names = LoadNameStream(bits);

      int srcsrvStream;
      string sourceServerData;
      if (!nameIndex.TryGetValue("SRCSRV", out srcsrvStream))
        sourceServerData = string.Empty;
      else
      {
        DataStream dataStream = dir.streams[srcsrvStream];
        byte[] bytes = new byte[dataStream.contentSize];
        dataStream.Read(reader, bits);
        sourceServerData = bits.ReadBString(bytes.Length);
      }

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

#if SKIP_THIS
      ArrayList funcList = new ArrayList();

      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, tokenToSourceMapping);
              continue;
            }
            LoadFuncsFromDbiModule(bits, module, names, funcList, true, dir, nameIndex, reader, ilreader);
          }
        }
      }

      PdbFunction[] funcs = (PdbFunction[])funcList.ToArray(typeof(PdbFunction));
#endif

      // After reading the functions, apply the token remapping table if it exists.
      if (header.snTokenRidMap != 0 && header.snTokenRidMap != 0xffff)
      {
        uint[] ridMap = new uint[dir.streams[header.snTokenRidMap].Length / 4];
        dir.streams[header.snTokenRidMap].Read(reader, bits);
        bits.ReadUInt32(ridMap);
        return ridMap;
      }
      return null;
    }
Example #9
0
    internal static PdbFunction[] LoadFunctions(Stream read, out Dictionary<uint, PdbTokenLine> tokenToSourceMapping, out string sourceServerData,
      System.Compiler.Metadata.Reader ilreader)
    {
      tokenToSourceMapping = new Dictionary<uint, PdbTokenLine>();
      BitAccess bits = new BitAccess(512 * 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);
      int nameStream;
      if (!nameIndex.TryGetValue("/NAMES", out nameStream))
      {
        throw new PdbDebugException("No `name' stream");
      }
      dir.streams[nameStream].Read(reader, bits);
      IntHashTable names = LoadNameStream(bits);

      int srcsrvStream;
      if (!nameIndex.TryGetValue("SRCSRV", out srcsrvStream))
        sourceServerData = string.Empty;
      else
      {
        DataStream dataStream = dir.streams[srcsrvStream];
        byte[] bytes = new byte[dataStream.contentSize];
        dataStream.Read(reader, bits);
        sourceServerData = bits.ReadBString(bytes.Length);
      }

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

      ArrayList funcList = new ArrayList();

      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, tokenToSourceMapping, sourceCache);
              continue;
            }
            LoadFuncsFromDbiModule(bits, module, names, funcList, true, dir, nameIndex, reader, ilreader, sourceCache);
          }
        }
      }

      PdbFunction[] funcs = (PdbFunction[])funcList.ToArray(typeof(PdbFunction));

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

        foreach (PdbFunction func in funcs)
        {
          func.MapTokens(ridMap, ilreader);
        }
      }
      else
      {
        foreach (PdbFunction func in funcs)
        {
          func.MapTokens(null, ilreader);
        }
      }
      //
      Array.Sort(funcs, PdbFunction.byAddressAndToken);
      //Array.Sort(funcs, PdbFunction.byToken);
      return funcs;
    }
Example #10
0
    internal static PdbFunction[] LoadFunctions(Stream read, out Dictionary<uint, PdbTokenLine> tokenToSourceMapping, out string sourceServerData, out int age, out Guid guid) {
      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 age, out 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))
        sourceServerData = string.Empty;
      else {
        DataStream dataStream = dir.streams[srcsrvStream];
        byte[] bytes = new byte[dataStream.contentSize];
        dataStream.Read(reader, bits);
        sourceServerData = bits.ReadBString(bytes.Length);
      }

      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, 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);
      return funcs;
    }