Merged into single file, added assertions
[mono.git] / mcs / class / IKVM.Reflection / Metadata / CliHeader.cs
1 /*
2   Copyright (C) 2008 Jeroen Frijters
3
4   This software is provided 'as-is', without any express or implied
5   warranty.  In no event will the authors be held liable for any damages
6   arising from the use of this software.
7
8   Permission is granted to anyone to use this software for any purpose,
9   including commercial applications, and to alter it and redistribute it
10   freely, subject to the following restrictions:
11
12   1. The origin of this software must not be misrepresented; you must not
13      claim that you wrote the original software. If you use this software
14      in a product, an acknowledgment in the product documentation would be
15      appreciated but is not required.
16   2. Altered source versions must be plainly marked as such, and must not be
17      misrepresented as being the original software.
18   3. This notice may not be removed or altered from any source distribution.
19
20   Jeroen Frijters
21   jeroen@frijters.net
22   
23 */
24 using System.IO;
25 using IMAGE_DATA_DIRECTORY = IKVM.Reflection.Reader.IMAGE_DATA_DIRECTORY;
26
27 namespace IKVM.Reflection.Metadata
28 {
29         sealed class CliHeader
30         {
31                 internal const uint COMIMAGE_FLAGS_ILONLY = 0x00000001;
32                 internal const uint COMIMAGE_FLAGS_32BITREQUIRED = 0x00000002;
33                 internal const uint COMIMAGE_FLAGS_STRONGNAMESIGNED = 0x00000008;
34                 internal const uint COMIMAGE_FLAGS_NATIVE_ENTRYPOINT = 0x00000010;
35                 internal const uint COMIMAGE_FLAGS_32BITPREFERRED = 0x00020000;
36
37                 internal uint Cb = 0x48;
38                 internal ushort MajorRuntimeVersion;
39                 internal ushort MinorRuntimeVersion;
40                 internal IMAGE_DATA_DIRECTORY MetaData;
41                 internal uint Flags;
42                 internal uint EntryPointToken;
43                 internal IMAGE_DATA_DIRECTORY Resources;
44                 internal IMAGE_DATA_DIRECTORY StrongNameSignature;
45                 internal IMAGE_DATA_DIRECTORY CodeManagerTable;
46                 internal IMAGE_DATA_DIRECTORY VTableFixups;
47                 internal IMAGE_DATA_DIRECTORY ExportAddressTableJumps;
48                 internal IMAGE_DATA_DIRECTORY ManagedNativeHeader;
49
50                 internal void Read(BinaryReader br)
51                 {
52                         Cb = br.ReadUInt32();
53                         MajorRuntimeVersion = br.ReadUInt16();
54                         MinorRuntimeVersion = br.ReadUInt16();
55                         MetaData.Read(br);
56                         Flags = br.ReadUInt32();
57                         EntryPointToken = br.ReadUInt32();
58                         Resources.Read(br);
59                         StrongNameSignature.Read(br);
60                         CodeManagerTable.Read(br);
61                         VTableFixups.Read(br);
62                         ExportAddressTableJumps.Read(br);
63                         ManagedNativeHeader.Read(br);
64                 }
65
66                 internal void Write(IKVM.Reflection.Writer.MetadataWriter mw)
67                 {
68                         mw.Write(Cb);
69                         mw.Write(MajorRuntimeVersion);
70                         mw.Write(MinorRuntimeVersion);
71                         MetaData.Write(mw);
72                         mw.Write(Flags);
73                         mw.Write(EntryPointToken);
74                         Resources.Write(mw);
75                         StrongNameSignature.Write(mw);
76                         CodeManagerTable.Write(mw);
77                         VTableFixups.Write(mw);
78                         ExportAddressTableJumps.Write(mw);
79                         ManagedNativeHeader.Write(mw);
80                 }
81         }
82 }