3 // Permission is hereby granted, free of charge, to any person obtaining
4 // a copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to
8 // permit persons to whom the Software is furnished to do so, subject to
9 // the following conditions:
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 * Copyright (c) 2002 Sergey Chaban <serge@wildwestsoftware.com>
28 using System
.Runtime
.InteropServices
;
30 namespace Mono
.PEToolkit
{
32 public class COFFHeader
{
34 private MachineId machine
;
35 private short sections
;
36 private uint tdStampRaw
;
37 private uint symTabPtr
;
38 private uint numSymbols
;
39 private short optHeaderSize
;
40 private Characteristics characteristics
;
42 public MachineId Machine
{
43 get { return machine; }
44 set { machine = value; }
47 public short NumberOfSections
{
48 get { return sections; }
49 set { sections = value; }
52 public uint TimeDateStamp
{
53 get { return tdStampRaw; }
54 set { tdStampRaw = value; }
57 public DateTime TimeStamp
{
59 return (new DateTime(1970, 1, 1) +
60 TimeSpan
.FromSeconds(tdStampRaw
)).ToLocalTime();
64 public uint PointerToSymbolTable
{
65 get { return symTabPtr; }
66 set { symTabPtr = value; }
69 public uint NumberOfSymbols
{
70 get { return numSymbols; }
71 set { numSymbols = value; }
74 public short SizeOfOptionalHeader
{
75 get { return optHeaderSize; }
76 set { optHeaderSize = value; }
79 public Characteristics Characteristics
{
80 get { return characteristics; }
81 set { characteristics = value; }
84 public void Read (BinaryReader reader
)
86 machine
= (MachineId
) reader
.ReadUInt16 ();
87 sections
= reader
.ReadInt16 ();
88 tdStampRaw
= reader
.ReadUInt32 ();
89 symTabPtr
= reader
.ReadUInt32 ();
90 numSymbols
= reader
.ReadUInt32 ();
91 optHeaderSize
= reader
.ReadInt16 ();
92 characteristics
= (Characteristics
) reader
.ReadUInt16 ();
95 public void Write (BinaryWriter writer
)
97 writer
.Write ((ushort)machine
);
98 writer
.Write (sections
);
99 writer
.Write (tdStampRaw
);
100 writer
.Write (symTabPtr
);
101 writer
.Write (numSymbols
);
102 writer
.Write (optHeaderSize
);
103 writer
.Write ((ushort)characteristics
);
106 public void Dump(TextWriter writer
)
109 "Machine ID : {0}" + Environment
.NewLine
+
110 "Sections : {1}" + Environment
.NewLine
+
111 "Characteristics : {2}" + Environment
.NewLine
+
112 "timestamp : {3} ({4})" + Environment
.NewLine
113 ,machine
, sections
, (ushort)characteristics
,
114 TimeStamp
, tdStampRaw
.ToString("X")
118 public override string ToString()
120 StringWriter sw
= new StringWriter();
122 return sw
.ToString();