Debian Codegraph @

external/ikvm/reflect/Metadata/CliHeader.cs

raw
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 [email protected]
22
23 */
24 using System.IO;
25
26 namespace IKVM.Reflection.Metadata
27 {
28 struct RvaSize
29 {
30 internal uint VirtualAddress;
31 internal uint Size;
32
33 internal void Read(BinaryReader br)
34 {
35 VirtualAddress = br.ReadUInt32();
36 Size = br.ReadUInt32();
37 }
38
39 internal void Write(IKVM.Reflection.Writer.MetadataWriter mw)
40 {
41 mw.Write(VirtualAddress);
42 mw.Write(Size);
43 }
44 }
45
46 sealed class CliHeader
47 {
48 internal const uint COMIMAGE_FLAGS_ILONLY = 0x00000001;
49 internal const uint COMIMAGE_FLAGS_32BITREQUIRED = 0x00000002;
50 internal const uint COMIMAGE_FLAGS_STRONGNAMESIGNED = 0x00000008;
51 internal const uint COMIMAGE_FLAGS_NATIVE_ENTRYPOINT = 0x00000010;
52 internal const uint COMIMAGE_FLAGS_32BITPREFERRED = 0x00020000;
53
54 internal uint Cb = 0x48;
55 internal ushort MajorRuntimeVersion;
56 internal ushort MinorRuntimeVersion;
57 internal RvaSize MetaData;
58 internal uint Flags;
59 internal uint EntryPointToken;
60 internal RvaSize Resources;
61 internal RvaSize StrongNameSignature;
62 internal RvaSize CodeManagerTable;
63 internal RvaSize VTableFixups;
64 internal RvaSize ExportAddressTableJumps;
65 internal RvaSize ManagedNativeHeader;
66
67 internal void Read(BinaryReader br)
68 {
69 Cb = br.ReadUInt32();
70 MajorRuntimeVersion = br.ReadUInt16();
71 MinorRuntimeVersion = br.ReadUInt16();
72 MetaData.Read(br);
73 Flags = br.ReadUInt32();
74 EntryPointToken = br.ReadUInt32();
75 Resources.Read(br);
76 StrongNameSignature.Read(br);
77 CodeManagerTable.Read(br);
78 VTableFixups.Read(br);
79 ExportAddressTableJumps.Read(br);
80 ManagedNativeHeader.Read(br);
81 }
82
83 internal void Write(IKVM.Reflection.Writer.MetadataWriter mw)
84 {
85 mw.Write(Cb);
86 mw.Write(MajorRuntimeVersion);
87 mw.Write(MinorRuntimeVersion);
88 MetaData.Write(mw);
89 mw.Write(Flags);
90 mw.Write(EntryPointToken);
91 Resources.Write(mw);
92 StrongNameSignature.Write(mw);
93 CodeManagerTable.Write(mw);
94 VTableFixups.Write(mw);
95 ExportAddressTableJumps.Write(mw);
96 ManagedNativeHeader.Write(mw);
97 }
98 }
99 }