retag
[mcs.git] / tools / pdb2mdb / PdbFileHeader.cs
blobc351076505eca37c60fe5d1268b3438bb3976884
1 //-----------------------------------------------------------------------------
2 //
3 // Copyright (C) Microsoft Corporation. All Rights Reserved.
4 //
5 //-----------------------------------------------------------------------------
6 using System;
7 using System.IO;
8 using System.Text;
10 namespace Microsoft.Cci.Pdb {
11 internal class PdbFileHeader {
12 internal PdbFileHeader(int pageSize) {
13 this.magic = new byte[32] {
14 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, // "Microsof"
15 0x74, 0x20, 0x43, 0x2F, 0x43, 0x2B, 0x2B, 0x20, // "t C/C++ "
16 0x4D, 0x53, 0x46, 0x20, 0x37, 0x2E, 0x30, 0x30, // "MSF 7.00"
17 0x0D, 0x0A, 0x1A, 0x44, 0x53, 0x00, 0x00, 0x00 // "^^^DS^^^"
19 this.pageSize = pageSize;
20 this.zero = 0;
23 internal PdbFileHeader(Stream reader, BitAccess bits) {
24 bits.MinCapacity(56);
25 reader.Seek(0, SeekOrigin.Begin);
26 bits.FillBuffer(reader, 56);
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 bits.ReadInt32(out this.directoryRoot); // 52..55
38 internal string Magic {
39 get { return StringFromBytesUTF8(magic); }
42 internal void Write(Stream writer, BitAccess bits) {
43 bits.MinCapacity(56);
44 bits.WriteBytes(magic); // 0..31
45 bits.WriteInt32(pageSize); // 32..35
46 bits.WriteInt32(freePageMap); // 36..39
47 bits.WriteInt32(pagesUsed); // 40..43
48 bits.WriteInt32(directorySize); // 44..47
49 bits.WriteInt32(zero); // 48..51
50 bits.WriteInt32(directoryRoot); // 52..55
52 writer.Seek(0, SeekOrigin.Begin);
53 bits.WriteBuffer(writer, 56);
56 //////////////////////////////////////////////////// Helper Functions.
58 internal string StringFromBytesUTF8(byte[] bytes) {
59 return StringFromBytesUTF8(bytes, 0, bytes.Length);
62 internal string StringFromBytesUTF8(byte[] bytes, int offset, int length) {
63 for (int i = 0; i < length; i++) {
64 if (bytes[offset + i] < ' ') {
65 length = i;
68 return Encoding.UTF8.GetString(bytes, offset, length);
71 ////////////////////////////////////////////////////////////// Fields.
73 internal readonly byte[] magic;
74 internal readonly int pageSize;
75 internal int freePageMap;
76 internal int pagesUsed;
77 internal int directorySize;
78 internal readonly int zero;
79 internal int directoryRoot;