~do-win/do/test-paths

« back to all changes in this revision

Viewing changes to Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/.svn/text-base/PEOptionalHeader.cs.svn-base

  • Committer: Chris S.
  • Date: 2009-06-21 03:37:34 UTC
  • Revision ID: chris@szikszoy.com-20090621033734-ud2jdcd5pq9r3ue9
initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// PEOptionalHeader.cs
 
3
//
 
4
// Author:
 
5
//   Jb Evain (jbevain@gmail.com)
 
6
//
 
7
// (C) 2005 Jb Evain
 
8
//
 
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:
 
16
//
 
17
// The above copyright notice and this permission notice shall be
 
18
// included in all copies or substantial portions of the Software.
 
19
//
 
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.
 
27
//
 
28
 
 
29
namespace Mono.Cecil.Binary {
 
30
 
 
31
        public sealed class PEOptionalHeader : IHeader, IBinaryVisitable {
 
32
 
 
33
                public StandardFieldsHeader StandardFields;
 
34
                public NTSpecificFieldsHeader NTSpecificFields;
 
35
                public DataDirectoriesHeader DataDirectories;
 
36
 
 
37
                internal PEOptionalHeader ()
 
38
                {
 
39
                        StandardFields = new StandardFieldsHeader ();
 
40
                        NTSpecificFields = new NTSpecificFieldsHeader ();
 
41
                        DataDirectories = new DataDirectoriesHeader ();
 
42
                }
 
43
 
 
44
                public void SetDefaultValues ()
 
45
                {
 
46
                }
 
47
 
 
48
                public void Accept (IBinaryVisitor visitor)
 
49
                {
 
50
                        visitor.VisitPEOptionalHeader (this);
 
51
 
 
52
                        StandardFields.Accept (visitor);
 
53
                        NTSpecificFields.Accept (visitor);
 
54
                        DataDirectories.Accept (visitor);
 
55
                }
 
56
 
 
57
                public sealed class StandardFieldsHeader : IHeader, IBinaryVisitable {
 
58
 
 
59
                        public ushort Magic;
 
60
                        public byte LMajor;
 
61
                        public byte LMinor;
 
62
                        public uint CodeSize;
 
63
                        public uint InitializedDataSize;
 
64
                        public uint UninitializedDataSize;
 
65
                        public RVA EntryPointRVA;
 
66
                        public RVA BaseOfCode;
 
67
                        public RVA BaseOfData;
 
68
 
 
69
                        public bool IsPE64 {
 
70
                                get { return Magic == 0x20b; }
 
71
                                set {
 
72
                                        if (value)
 
73
                                                Magic = 0x20b;
 
74
                                        else
 
75
                                                Magic = 0x10b;
 
76
                                }
 
77
                        }
 
78
 
 
79
                        internal StandardFieldsHeader ()
 
80
                        {
 
81
                        }
 
82
 
 
83
                        public void SetDefaultValues ()
 
84
                        {
 
85
                                Magic = 0x10b;
 
86
                                LMajor = 6;
 
87
                                LMinor = 0;
 
88
                        }
 
89
 
 
90
                        public void Accept (IBinaryVisitor visitor)
 
91
                        {
 
92
                                visitor.VisitStandardFieldsHeader (this);
 
93
                        }
 
94
                }
 
95
 
 
96
                public sealed class NTSpecificFieldsHeader : IHeader, IBinaryVisitable {
 
97
 
 
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;
 
119
 
 
120
                        internal NTSpecificFieldsHeader ()
 
121
                        {
 
122
                        }
 
123
 
 
124
                        public void SetDefaultValues ()
 
125
                        {
 
126
                                ImageBase = 0x400000;
 
127
                                SectionAlignment = 0x2000;
 
128
                                FileAlignment = 0x200;
 
129
                                OSMajor = 4;
 
130
                                OSMinor = 0;
 
131
                                UserMajor = 0;
 
132
                                UserMinor = 0;
 
133
                                SubSysMajor = 4;
 
134
                                SubSysMinor = 0;
 
135
                                Reserved = 0;
 
136
                                HeaderSize = 0x200;
 
137
                                FileChecksum = 0;
 
138
                                DLLFlags = 0;
 
139
                                StackReserveSize = 0x100000;
 
140
                                StackCommitSize = 0x1000;
 
141
                                HeapReserveSize = 0x100000;
 
142
                                HeapCommitSize = 0x1000;
 
143
                                LoaderFlags = 0;
 
144
                                NumberOfDataDir = 0x10;
 
145
                        }
 
146
 
 
147
                        public void Accept (IBinaryVisitor visitor)
 
148
                        {
 
149
                                visitor.VisitNTSpecificFieldsHeader (this);
 
150
                        }
 
151
                }
 
152
 
 
153
                public sealed class DataDirectoriesHeader : IHeader, IBinaryVisitable {
 
154
 
 
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;
 
171
 
 
172
                        internal DataDirectoriesHeader ()
 
173
                        {
 
174
                        }
 
175
 
 
176
                        public void SetDefaultValues ()
 
177
                        {
 
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;
 
192
                        }
 
193
 
 
194
                        public void Accept (IBinaryVisitor visitor)
 
195
                        {
 
196
                                visitor.VisitDataDirectoriesHeader (this);
 
197
                        }
 
198
                }
 
199
        }
 
200
}