~do-win/do/test-paths

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
//
// PEOptionalHeader.cs
//
// Author:
//   Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

namespace Mono.Cecil.Binary {

	public sealed class PEOptionalHeader : IHeader, IBinaryVisitable {

		public StandardFieldsHeader StandardFields;
		public NTSpecificFieldsHeader NTSpecificFields;
		public DataDirectoriesHeader DataDirectories;

		internal PEOptionalHeader ()
		{
			StandardFields = new StandardFieldsHeader ();
			NTSpecificFields = new NTSpecificFieldsHeader ();
			DataDirectories = new DataDirectoriesHeader ();
		}

		public void SetDefaultValues ()
		{
		}

		public void Accept (IBinaryVisitor visitor)
		{
			visitor.VisitPEOptionalHeader (this);

			StandardFields.Accept (visitor);
			NTSpecificFields.Accept (visitor);
			DataDirectories.Accept (visitor);
		}

		public sealed class StandardFieldsHeader : IHeader, IBinaryVisitable {

			public ushort Magic;
			public byte LMajor;
			public byte LMinor;
			public uint CodeSize;
			public uint InitializedDataSize;
			public uint UninitializedDataSize;
			public RVA EntryPointRVA;
			public RVA BaseOfCode;
			public RVA BaseOfData;

			public bool IsPE64 {
				get { return Magic == 0x20b; }
				set {
					if (value)
						Magic = 0x20b;
					else
						Magic = 0x10b;
				}
			}

			internal StandardFieldsHeader ()
			{
			}

			public void SetDefaultValues ()
			{
				Magic = 0x10b;
				LMajor = 6;
				LMinor = 0;
			}

			public void Accept (IBinaryVisitor visitor)
			{
				visitor.VisitStandardFieldsHeader (this);
			}
		}

		public sealed class NTSpecificFieldsHeader : IHeader, IBinaryVisitable {

			public ulong ImageBase;
			public uint SectionAlignment;
			public uint FileAlignment;
			public ushort OSMajor;
			public ushort OSMinor;
			public ushort UserMajor;
			public ushort UserMinor;
			public ushort SubSysMajor;
			public ushort SubSysMinor;
			public uint Reserved;
			public uint ImageSize;
			public uint HeaderSize;
			public uint FileChecksum;
			public SubSystem SubSystem;
			public ushort DLLFlags;
			public ulong StackReserveSize;
			public ulong StackCommitSize;
			public ulong HeapReserveSize;
			public ulong HeapCommitSize;
			public uint LoaderFlags;
			public uint NumberOfDataDir;

			internal NTSpecificFieldsHeader ()
			{
			}

			public void SetDefaultValues ()
			{
				ImageBase = 0x400000;
				SectionAlignment = 0x2000;
				FileAlignment = 0x200;
				OSMajor = 4;
				OSMinor = 0;
				UserMajor = 0;
				UserMinor = 0;
				SubSysMajor = 4;
				SubSysMinor = 0;
				Reserved = 0;
				HeaderSize = 0x200;
				FileChecksum = 0;
				DLLFlags = 0;
				StackReserveSize = 0x100000;
				StackCommitSize = 0x1000;
				HeapReserveSize = 0x100000;
				HeapCommitSize = 0x1000;
				LoaderFlags = 0;
				NumberOfDataDir = 0x10;
			}

			public void Accept (IBinaryVisitor visitor)
			{
				visitor.VisitNTSpecificFieldsHeader (this);
			}
		}

		public sealed class DataDirectoriesHeader : IHeader, IBinaryVisitable {

			public DataDirectory ExportTable;
			public DataDirectory ImportTable;
			public DataDirectory ResourceTable;
			public DataDirectory ExceptionTable;
			public DataDirectory CertificateTable;
			public DataDirectory BaseRelocationTable;
			public DataDirectory Debug;
			public DataDirectory Copyright;
			public DataDirectory GlobalPtr;
			public DataDirectory TLSTable;
			public DataDirectory LoadConfigTable;
			public DataDirectory BoundImport;
			public DataDirectory IAT;
			public DataDirectory DelayImportDescriptor;
			public DataDirectory CLIHeader;
			public DataDirectory Reserved;

			internal DataDirectoriesHeader ()
			{
			}

			public void SetDefaultValues ()
			{
				ExportTable = DataDirectory.Zero;
				ResourceTable = DataDirectory.Zero;
				ExceptionTable = DataDirectory.Zero;
				CertificateTable = DataDirectory.Zero;
				Debug = DataDirectory.Zero;
				Copyright = DataDirectory.Zero;
				GlobalPtr = DataDirectory.Zero;
				TLSTable = DataDirectory.Zero;
				LoadConfigTable = DataDirectory.Zero;
				BoundImport = DataDirectory.Zero;
				IAT = new DataDirectory (new RVA (0x2000), 8);
				DelayImportDescriptor = DataDirectory.Zero;
				CLIHeader = new DataDirectory (new RVA (0x2008), 0x48);
				Reserved = DataDirectory.Zero;
			}

			public void Accept (IBinaryVisitor visitor)
			{
				visitor.VisitDataDirectoriesHeader (this);
			}
		}
	}
}