**** Merged from MCS ****
[mono-project.git] / mcs / class / Mono.PEToolkit / DataDir.cs
blob79d254c933d0a031f9fdc5e89ef5660583c91a17
2 //
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:
10 //
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
13 //
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>
26 using System;
27 using System.IO;
28 using System.Runtime.InteropServices;
30 namespace Mono.PEToolkit {
32 /// <summary>
33 /// IMAGE_DATA_DIRECTORY.
34 /// </summary>
35 public class DataDir {
37 public static readonly DataDir Null;
39 public RVA virtAddr;
40 public uint size;
42 static DataDir ()
44 Null = new DataDir ();
45 Null.virtAddr = 0;
46 Null.size = 0;
49 public DataDir () {
53 public DataDir (BinaryReader reader)
55 Read (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);
67 writer.Write (size);
70 public RVA VirtualAddress {
71 get {
72 return virtAddr;
74 set {
75 virtAddr = value;
79 public uint Size {
80 get {
81 return size;
83 set {
84 size = value;
88 public bool IsNull {
89 get {
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);
102 if (res) {
103 DataDir that = (DataDir) obj;
104 res = (this.virtAddr == that.virtAddr) &&
105 (this.size == that.size);
107 return res;
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);
120 /// <summary>
121 /// </summary>
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"));