PdbFileHeader.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //-----------------------------------------------------------------------------
  2. //
  3. // Copyright (c) Microsoft. All rights reserved.
  4. // This code is licensed under the Microsoft Public License.
  5. // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
  6. // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
  7. // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
  8. // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
  9. //
  10. //-----------------------------------------------------------------------------
  11. using System;
  12. using System.IO;
  13. using System.Text;
  14. namespace Microsoft.Cci.Pdb {
  15. internal class PdbFileHeader {
  16. //internal PdbFileHeader(int pageSize) {
  17. // this.magic = new byte[32] {
  18. // 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, // "Microsof"
  19. // 0x74, 0x20, 0x43, 0x2F, 0x43, 0x2B, 0x2B, 0x20, // "t C/C++ "
  20. // 0x4D, 0x53, 0x46, 0x20, 0x37, 0x2E, 0x30, 0x30, // "MSF 7.00"
  21. // 0x0D, 0x0A, 0x1A, 0x44, 0x53, 0x00, 0x00, 0x00 // "^^^DS^^^"
  22. // };
  23. // this.pageSize = pageSize;
  24. //}
  25. internal PdbFileHeader(Stream reader, BitAccess bits) {
  26. bits.MinCapacity(56);
  27. reader.Seek(0, SeekOrigin.Begin);
  28. bits.FillBuffer(reader, 52);
  29. this.magic = new byte[32];
  30. bits.ReadBytes(this.magic); // 0..31
  31. bits.ReadInt32(out this.pageSize); // 32..35
  32. bits.ReadInt32(out this.freePageMap); // 36..39
  33. bits.ReadInt32(out this.pagesUsed); // 40..43
  34. bits.ReadInt32(out this.directorySize); // 44..47
  35. bits.ReadInt32(out this.zero); // 48..51
  36. int directoryPages = ((((directorySize + pageSize - 1) / pageSize) * 4) + pageSize - 1) / pageSize;
  37. this.directoryRoot = new int[directoryPages];
  38. bits.FillBuffer(reader, directoryPages * 4);
  39. bits.ReadInt32(this.directoryRoot);
  40. }
  41. //internal string Magic {
  42. // get { return StringFromBytesUTF8(magic); }
  43. //}
  44. //internal void Write(Stream writer, BitAccess bits) {
  45. // bits.MinCapacity(pageSize);
  46. // bits.WriteBytes(magic); // 0..31
  47. // bits.WriteInt32(pageSize); // 32..35
  48. // bits.WriteInt32(freePageMap); // 36..39
  49. // bits.WriteInt32(pagesUsed); // 40..43
  50. // bits.WriteInt32(directorySize); // 44..47
  51. // bits.WriteInt32(zero); // 48..51
  52. // bits.WriteInt32(directoryRoot); // 52..55
  53. // writer.Seek(0, SeekOrigin.Begin);
  54. // bits.WriteBuffer(writer, pageSize);
  55. //}
  56. //////////////////////////////////////////////////// Helper Functions.
  57. //
  58. //internal static string StringFromBytesUTF8(byte[] bytes) {
  59. // return StringFromBytesUTF8(bytes, 0, bytes.Length);
  60. //}
  61. //internal static string StringFromBytesUTF8(byte[] bytes, int offset, int length) {
  62. // for (int i = 0; i < length; i++) {
  63. // if (bytes[offset + i] < ' ') {
  64. // length = i;
  65. // }
  66. // }
  67. // return Encoding.UTF8.GetString(bytes, offset, length);
  68. //}
  69. ////////////////////////////////////////////////////////////// Fields.
  70. //
  71. internal readonly byte[] magic;
  72. internal readonly int pageSize;
  73. internal int freePageMap;
  74. internal int pagesUsed;
  75. internal int directorySize;
  76. internal readonly int zero;
  77. internal int[] directoryRoot;
  78. }
  79. }