5
// Jb Evain (jbevain@gmail.com)
9
// Permission is hereby granted, free of charge, to any person obtaining
10
// a copy of this software and associated documentation files (the
11
// "Software"), to deal in the Software without restriction, including
12
// without limitation the rights to use, copy, modify, merge, publish,
13
// distribute, sublicense, and/or sell copies of the Software, and to
14
// permit persons to whom the Software is furnished to do so, subject to
15
// the following conditions:
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
namespace Mono.Cecil.Binary {
31
public sealed class PEOptionalHeader : IHeader, IBinaryVisitable {
33
public StandardFieldsHeader StandardFields;
34
public NTSpecificFieldsHeader NTSpecificFields;
35
public DataDirectoriesHeader DataDirectories;
37
internal PEOptionalHeader ()
39
StandardFields = new StandardFieldsHeader ();
40
NTSpecificFields = new NTSpecificFieldsHeader ();
41
DataDirectories = new DataDirectoriesHeader ();
44
public void SetDefaultValues ()
48
public void Accept (IBinaryVisitor visitor)
50
visitor.VisitPEOptionalHeader (this);
52
StandardFields.Accept (visitor);
53
NTSpecificFields.Accept (visitor);
54
DataDirectories.Accept (visitor);
57
public sealed class StandardFieldsHeader : IHeader, IBinaryVisitable {
63
public uint InitializedDataSize;
64
public uint UninitializedDataSize;
65
public RVA EntryPointRVA;
66
public RVA BaseOfCode;
67
public RVA BaseOfData;
70
get { return Magic == 0x20b; }
79
internal StandardFieldsHeader ()
83
public void SetDefaultValues ()
90
public void Accept (IBinaryVisitor visitor)
92
visitor.VisitStandardFieldsHeader (this);
96
public sealed class NTSpecificFieldsHeader : IHeader, IBinaryVisitable {
98
public ulong ImageBase;
99
public uint SectionAlignment;
100
public uint FileAlignment;
101
public ushort OSMajor;
102
public ushort OSMinor;
103
public ushort UserMajor;
104
public ushort UserMinor;
105
public ushort SubSysMajor;
106
public ushort SubSysMinor;
107
public uint Reserved;
108
public uint ImageSize;
109
public uint HeaderSize;
110
public uint FileChecksum;
111
public SubSystem SubSystem;
112
public ushort DLLFlags;
113
public ulong StackReserveSize;
114
public ulong StackCommitSize;
115
public ulong HeapReserveSize;
116
public ulong HeapCommitSize;
117
public uint LoaderFlags;
118
public uint NumberOfDataDir;
120
internal NTSpecificFieldsHeader ()
124
public void SetDefaultValues ()
126
ImageBase = 0x400000;
127
SectionAlignment = 0x2000;
128
FileAlignment = 0x200;
139
StackReserveSize = 0x100000;
140
StackCommitSize = 0x1000;
141
HeapReserveSize = 0x100000;
142
HeapCommitSize = 0x1000;
144
NumberOfDataDir = 0x10;
147
public void Accept (IBinaryVisitor visitor)
149
visitor.VisitNTSpecificFieldsHeader (this);
153
public sealed class DataDirectoriesHeader : IHeader, IBinaryVisitable {
155
public DataDirectory ExportTable;
156
public DataDirectory ImportTable;
157
public DataDirectory ResourceTable;
158
public DataDirectory ExceptionTable;
159
public DataDirectory CertificateTable;
160
public DataDirectory BaseRelocationTable;
161
public DataDirectory Debug;
162
public DataDirectory Copyright;
163
public DataDirectory GlobalPtr;
164
public DataDirectory TLSTable;
165
public DataDirectory LoadConfigTable;
166
public DataDirectory BoundImport;
167
public DataDirectory IAT;
168
public DataDirectory DelayImportDescriptor;
169
public DataDirectory CLIHeader;
170
public DataDirectory Reserved;
172
internal DataDirectoriesHeader ()
176
public void SetDefaultValues ()
178
ExportTable = DataDirectory.Zero;
179
ResourceTable = DataDirectory.Zero;
180
ExceptionTable = DataDirectory.Zero;
181
CertificateTable = DataDirectory.Zero;
182
Debug = DataDirectory.Zero;
183
Copyright = DataDirectory.Zero;
184
GlobalPtr = DataDirectory.Zero;
185
TLSTable = DataDirectory.Zero;
186
LoadConfigTable = DataDirectory.Zero;
187
BoundImport = DataDirectory.Zero;
188
IAT = new DataDirectory (new RVA (0x2000), 8);
189
DelayImportDescriptor = DataDirectory.Zero;
190
CLIHeader = new DataDirectory (new RVA (0x2008), 0x48);
191
Reserved = DataDirectory.Zero;
194
public void Accept (IBinaryVisitor visitor)
196
visitor.VisitDataDirectoriesHeader (this);