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
{
33 /// IMAGE_DATA_DIRECTORY.
35 public class DataDir
{
37 public static readonly DataDir Null
;
44 Null
= new DataDir ();
53 public DataDir (BinaryReader reader
)
58 public void Read (BinaryReader reader
)
60 virtAddr
= new RVA (reader
.ReadUInt32 ());
61 size
= reader
.ReadUInt32 ();
64 public void Write (BinaryWriter writer
)
66 virtAddr
.Write (writer
);
70 public RVA VirtualAddress
{
90 return (this == Null
);
94 public override int GetHashCode()
96 return (virtAddr
.GetHashCode() ^
(int)(size
<< 1));
99 public override bool Equals(object obj
)
101 bool res
= (obj
is DataDir
);
103 DataDir that
= (DataDir
) obj
;
104 res
= (this.virtAddr
== that
.virtAddr
) &&
105 (this.size
== that
.size
);
110 public static bool operator == (DataDir d1
, DataDir d2
)
112 return d1
.Equals(d2
);
115 public static bool operator != (DataDir d1
, DataDir d2
)
117 return !d1
.Equals(d2
);
122 /// <returns></returns>
123 public override string ToString()
125 if (this.IsNull
) return "NULL";
126 return String
.Format("RVA = {0}, size = 0x{1}", virtAddr
, size
.ToString("X"));