IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
IMAGE_OPTIONAL_HEADER.cs
Go to the documentation of this file.
1/*
2 Copyright (C) 2009 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*/
24using System.IO;
25
26using BYTE = System.Byte;
27using DWORD = System.UInt32;
28using ULONGLONG = System.UInt64;
29using WORD = System.UInt16;
30
32{
33
35 {
36
37 public const WORD IMAGE_NT_OPTIONAL_HDR32_MAGIC = 0x10b;
38 public const WORD IMAGE_NT_OPTIONAL_HDR64_MAGIC = 0x20b;
39
42
43 public WORD Magic;
74
75 internal void Read(BinaryReader br)
76 {
77 Magic = br.ReadUInt16();
79 throw new BadImageFormatException();
80
81 MajorLinkerVersion = br.ReadByte();
82 MinorLinkerVersion = br.ReadByte();
83 SizeOfCode = br.ReadUInt32();
84 SizeOfInitializedData = br.ReadUInt32();
85 SizeOfUninitializedData = br.ReadUInt32();
86 AddressOfEntryPoint = br.ReadUInt32();
87 BaseOfCode = br.ReadUInt32();
89 {
90 BaseOfData = br.ReadUInt32();
91 ImageBase = br.ReadUInt32();
92 }
93 else
94 {
95 ImageBase = br.ReadUInt64();
96 }
97 SectionAlignment = br.ReadUInt32();
98 FileAlignment = br.ReadUInt32();
99 MajorOperatingSystemVersion = br.ReadUInt16();
100 MinorOperatingSystemVersion = br.ReadUInt16();
101 MajorImageVersion = br.ReadUInt16();
102 MinorImageVersion = br.ReadUInt16();
103 MajorSubsystemVersion = br.ReadUInt16();
104 MinorSubsystemVersion = br.ReadUInt16();
105 Win32VersionValue = br.ReadUInt32();
106 SizeOfImage = br.ReadUInt32();
107 SizeOfHeaders = br.ReadUInt32();
108 CheckSum = br.ReadUInt32();
109 Subsystem = br.ReadUInt16();
110 DllCharacteristics = br.ReadUInt16();
112 {
113 SizeOfStackReserve = br.ReadUInt32();
114 SizeOfStackCommit = br.ReadUInt32();
115 SizeOfHeapReserve = br.ReadUInt32();
116 SizeOfHeapCommit = br.ReadUInt32();
117 }
118 else
119 {
120 SizeOfStackReserve = br.ReadUInt64();
121 SizeOfStackCommit = br.ReadUInt64();
122 SizeOfHeapReserve = br.ReadUInt64();
123 SizeOfHeapCommit = br.ReadUInt64();
124 }
125 LoaderFlags = br.ReadUInt32();
126 NumberOfRvaAndSizes = br.ReadUInt32();
128 for (uint i = 0; i < NumberOfRvaAndSizes; i++)
129 {
131 DataDirectory[i].Read(br);
132 }
133 }
134
135 }
136
137}
System.UInt32 DWORD
System.UInt16 WORD
System.UInt64 ULONGLONG
System.Byte BYTE