OffsetTable.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using System.IO;
  3. namespace Mono.CompilerServices.SymbolWriter
  4. {
  5. public class OffsetTable
  6. {
  7. [Flags]
  8. public enum Flags
  9. {
  10. IsAspxSource = 1,
  11. WindowsFileNames = 2
  12. }
  13. public const int MajorVersion = 50;
  14. public const int MinorVersion = 0;
  15. public const long Magic = 5037318119232611860L;
  16. public int TotalFileSize;
  17. public int DataSectionOffset;
  18. public int DataSectionSize;
  19. public int CompileUnitCount;
  20. public int CompileUnitTableOffset;
  21. public int CompileUnitTableSize;
  22. public int SourceCount;
  23. public int SourceTableOffset;
  24. public int SourceTableSize;
  25. public int MethodCount;
  26. public int MethodTableOffset;
  27. public int MethodTableSize;
  28. public int TypeCount;
  29. public int AnonymousScopeCount;
  30. public int AnonymousScopeTableOffset;
  31. public int AnonymousScopeTableSize;
  32. public OffsetTable.Flags FileFlags;
  33. public int LineNumberTable_LineBase = -1;
  34. public int LineNumberTable_LineRange = 8;
  35. public int LineNumberTable_OpcodeBase = 9;
  36. internal OffsetTable()
  37. {
  38. int platform = (int)Environment.OSVersion.Platform;
  39. if (platform != 4 && platform != 128)
  40. {
  41. this.FileFlags |= OffsetTable.Flags.WindowsFileNames;
  42. }
  43. }
  44. internal OffsetTable(BinaryReader reader, int major_version, int minor_version)
  45. {
  46. this.TotalFileSize = reader.ReadInt32();
  47. this.DataSectionOffset = reader.ReadInt32();
  48. this.DataSectionSize = reader.ReadInt32();
  49. this.CompileUnitCount = reader.ReadInt32();
  50. this.CompileUnitTableOffset = reader.ReadInt32();
  51. this.CompileUnitTableSize = reader.ReadInt32();
  52. this.SourceCount = reader.ReadInt32();
  53. this.SourceTableOffset = reader.ReadInt32();
  54. this.SourceTableSize = reader.ReadInt32();
  55. this.MethodCount = reader.ReadInt32();
  56. this.MethodTableOffset = reader.ReadInt32();
  57. this.MethodTableSize = reader.ReadInt32();
  58. this.TypeCount = reader.ReadInt32();
  59. this.AnonymousScopeCount = reader.ReadInt32();
  60. this.AnonymousScopeTableOffset = reader.ReadInt32();
  61. this.AnonymousScopeTableSize = reader.ReadInt32();
  62. this.LineNumberTable_LineBase = reader.ReadInt32();
  63. this.LineNumberTable_LineRange = reader.ReadInt32();
  64. this.LineNumberTable_OpcodeBase = reader.ReadInt32();
  65. this.FileFlags = (OffsetTable.Flags)reader.ReadInt32();
  66. }
  67. internal void Write(BinaryWriter bw, int major_version, int minor_version)
  68. {
  69. bw.Write(this.TotalFileSize);
  70. bw.Write(this.DataSectionOffset);
  71. bw.Write(this.DataSectionSize);
  72. bw.Write(this.CompileUnitCount);
  73. bw.Write(this.CompileUnitTableOffset);
  74. bw.Write(this.CompileUnitTableSize);
  75. bw.Write(this.SourceCount);
  76. bw.Write(this.SourceTableOffset);
  77. bw.Write(this.SourceTableSize);
  78. bw.Write(this.MethodCount);
  79. bw.Write(this.MethodTableOffset);
  80. bw.Write(this.MethodTableSize);
  81. bw.Write(this.TypeCount);
  82. bw.Write(this.AnonymousScopeCount);
  83. bw.Write(this.AnonymousScopeTableOffset);
  84. bw.Write(this.AnonymousScopeTableSize);
  85. bw.Write(this.LineNumberTable_LineBase);
  86. bw.Write(this.LineNumberTable_LineRange);
  87. bw.Write(this.LineNumberTable_OpcodeBase);
  88. bw.Write((int)this.FileFlags);
  89. }
  90. public override string ToString()
  91. {
  92. return string.Format("OffsetTable [{0} - {1}:{2} - {3}:{4}:{5} - {6}:{7}:{8} - {9}]", new object[]
  93. {
  94. this.TotalFileSize,
  95. this.DataSectionOffset,
  96. this.DataSectionSize,
  97. this.SourceCount,
  98. this.SourceTableOffset,
  99. this.SourceTableSize,
  100. this.MethodCount,
  101. this.MethodTableOffset,
  102. this.MethodTableSize,
  103. this.TypeCount
  104. });
  105. }
  106. }
  107. }