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