Debian Codegraph @

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

raw
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
15 namespace Microsoft.Cci.Pdb {
16 internal class PdbFileHeader {
17 //internal PdbFileHeader(int pageSize) {
18 // this.magic = new byte[32] {
19 // 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, // "Microsof"
20 // 0x74, 0x20, 0x43, 0x2F, 0x43, 0x2B, 0x2B, 0x20, // "t C/C++ "
21 // 0x4D, 0x53, 0x46, 0x20, 0x37, 0x2E, 0x30, 0x30, // "MSF 7.00"
22 // 0x0D, 0x0A, 0x1A, 0x44, 0x53, 0x00, 0x00, 0x00 // "^^^DS^^^"
23 // };
24 // this.pageSize = pageSize;
25 //}
26
27 internal PdbFileHeader(Stream reader, BitAccess bits) {
28 bits.MinCapacity(56);
29 reader.Seek(0, SeekOrigin.Begin);
30 bits.FillBuffer(reader, 52);
31
32 this.magic = new byte[32];
33 bits.ReadBytes(this.magic); // 0..31
34 bits.ReadInt32(out this.pageSize); // 32..35
35 bits.ReadInt32(out this.freePageMap); // 36..39
36 bits.ReadInt32(out this.pagesUsed); // 40..43
37 bits.ReadInt32(out this.directorySize); // 44..47
38 bits.ReadInt32(out this.zero); // 48..51
39
40 int directoryPages = ((((directorySize + pageSize - 1) / pageSize) * 4) + pageSize - 1) / pageSize;
41 this.directoryRoot = new int[directoryPages];
42 bits.FillBuffer(reader, directoryPages * 4);
43 bits.ReadInt32(this.directoryRoot);
44 }
45
46 //internal string Magic {
47 // get { return StringFromBytesUTF8(magic); }
48 //}
49
50 //internal void Write(Stream writer, BitAccess bits) {
51 // bits.MinCapacity(pageSize);
52 // bits.WriteBytes(magic); // 0..31
53 // bits.WriteInt32(pageSize); // 32..35
54 // bits.WriteInt32(freePageMap); // 36..39
55 // bits.WriteInt32(pagesUsed); // 40..43
56 // bits.WriteInt32(directorySize); // 44..47
57 // bits.WriteInt32(zero); // 48..51
58 // bits.WriteInt32(directoryRoot); // 52..55
59
60 // writer.Seek(0, SeekOrigin.Begin);
61 // bits.WriteBuffer(writer, pageSize);
62 //}
63
64 //////////////////////////////////////////////////// Helper Functions.
65 //
66 //internal static string StringFromBytesUTF8(byte[] bytes) {
67 // return StringFromBytesUTF8(bytes, 0, bytes.Length);
68 //}
69
70 //internal static string StringFromBytesUTF8(byte[] bytes, int offset, int length) {
71 // for (int i = 0; i < length; i++) {
72 // if (bytes[offset + i] < ' ') {
73 // length = i;
74 // }
75 // }
76 // return Encoding.UTF8.GetString(bytes, offset, length);
77 //}
78
79 ////////////////////////////////////////////////////////////// Fields.
80 //
81 internal readonly byte[] magic;
82 internal readonly int pageSize;
83 internal int freePageMap;
84 internal int pagesUsed;
85 internal int directorySize;
86 internal readonly int zero;
87 internal int[] directoryRoot;
88 }
89
90 }