/symbols/pdb/Microsoft.Cci.Pdb/PdbFileHeader.cs

http://github.com/jbevain/cecil · C# · 96 lines · 41 code · 14 blank · 41 comment · 1 complexity · 1894315b07e050a9e36a6bbe017377c4 MD5 · raw file

  1. // Copyright (c) Microsoft. All rights reserved.
  2. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
  3. using System;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. namespace Microsoft.Cci.Pdb {
  8. internal class PdbFileHeader {
  9. private readonly byte[] windowsPdbMagic = new byte[32] {
  10. 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, // "Microsof"
  11. 0x74, 0x20, 0x43, 0x2F, 0x43, 0x2B, 0x2B, 0x20, // "t C/C++ "
  12. 0x4D, 0x53, 0x46, 0x20, 0x37, 0x2E, 0x30, 0x30, // "MSF 7.00"
  13. 0x0D, 0x0A, 0x1A, 0x44, 0x53, 0x00, 0x00, 0x00 // "^^^DS^^^"
  14. };
  15. //internal PdbFileHeader(int pageSize) {
  16. // this.magic = new byte[32] {
  17. // 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, // "Microsof"
  18. // 0x74, 0x20, 0x43, 0x2F, 0x43, 0x2B, 0x2B, 0x20, // "t C/C++ "
  19. // 0x4D, 0x53, 0x46, 0x20, 0x37, 0x2E, 0x30, 0x30, // "MSF 7.00"
  20. // 0x0D, 0x0A, 0x1A, 0x44, 0x53, 0x00, 0x00, 0x00 // "^^^DS^^^"
  21. // };
  22. // this.pageSize = pageSize;
  23. //}
  24. internal PdbFileHeader(Stream reader, BitAccess bits) {
  25. bits.MinCapacity(56);
  26. reader.Seek(0, SeekOrigin.Begin);
  27. bits.FillBuffer(reader, 52);
  28. this.magic = new byte[32];
  29. bits.ReadBytes(this.magic); // 0..31
  30. bits.ReadInt32(out this.pageSize); // 32..35
  31. bits.ReadInt32(out this.freePageMap); // 36..39
  32. bits.ReadInt32(out this.pagesUsed); // 40..43
  33. bits.ReadInt32(out this.directorySize); // 44..47
  34. bits.ReadInt32(out this.zero); // 48..51
  35. if (!this.magic.SequenceEqual(windowsPdbMagic))
  36. {
  37. throw new PdbException("The PDB file is not recognized as a Windows PDB file");
  38. }
  39. int directoryPages = ((((directorySize + pageSize - 1) / pageSize) * 4) + pageSize - 1) / pageSize;
  40. this.directoryRoot = new int[directoryPages];
  41. bits.FillBuffer(reader, directoryPages * 4);
  42. bits.ReadInt32(this.directoryRoot);
  43. }
  44. //internal string Magic {
  45. // get { return StringFromBytesUTF8(magic); }
  46. //}
  47. //internal void Write(Stream writer, BitAccess bits) {
  48. // bits.MinCapacity(pageSize);
  49. // bits.WriteBytes(magic); // 0..31
  50. // bits.WriteInt32(pageSize); // 32..35
  51. // bits.WriteInt32(freePageMap); // 36..39
  52. // bits.WriteInt32(pagesUsed); // 40..43
  53. // bits.WriteInt32(directorySize); // 44..47
  54. // bits.WriteInt32(zero); // 48..51
  55. // bits.WriteInt32(directoryRoot); // 52..55
  56. // writer.Seek(0, SeekOrigin.Begin);
  57. // bits.WriteBuffer(writer, pageSize);
  58. //}
  59. //////////////////////////////////////////////////// Helper Functions.
  60. //
  61. //internal static string StringFromBytesUTF8(byte[] bytes) {
  62. // return StringFromBytesUTF8(bytes, 0, bytes.Length);
  63. //}
  64. //internal static string StringFromBytesUTF8(byte[] bytes, int offset, int length) {
  65. // for (int i = 0; i < length; i++) {
  66. // if (bytes[offset + i] < ' ') {
  67. // length = i;
  68. // }
  69. // }
  70. // return Encoding.UTF8.GetString(bytes, offset, length);
  71. //}
  72. ////////////////////////////////////////////////////////////// Fields.
  73. //
  74. internal readonly byte[] magic;
  75. internal readonly int pageSize;
  76. internal int freePageMap;
  77. internal int pagesUsed;
  78. internal int directorySize;
  79. internal readonly int zero;
  80. internal int[] directoryRoot;
  81. }
  82. }