// dnlib: See LICENSE.txt for more info using System; using System.Diagnostics; using dnlib.IO; namespace dnlib.DotNet.Pdb.Managed { /// /// An address in the image /// [DebuggerDisplay("{Section}:{Offset}")] readonly struct PdbAddress : IEquatable, IComparable { /// /// Section /// public readonly ushort Section; /// /// Offset in /// public readonly uint Offset; /// /// Constructor /// /// Section /// Offset in public PdbAddress(ushort section, int offset) { Section = section; Offset = (uint)offset; } /// /// Constructor /// /// Section /// Offset in public PdbAddress(ushort section, uint offset) { Section = section; Offset = offset; } /// /// Returns true if is less than or equal to /// /// First /// Second /// public static bool operator <=(PdbAddress a, PdbAddress b) => a.CompareTo(b) <= 0; /// /// Returns true if is less than /// /// First /// Second /// public static bool operator <(PdbAddress a, PdbAddress b) => a.CompareTo(b) < 0; /// /// Returns true if is greater than or equal to /// /// First /// Second /// public static bool operator >=(PdbAddress a, PdbAddress b) => a.CompareTo(b) >= 0; /// /// Returns true if is greater than /// /// First /// Second /// public static bool operator >(PdbAddress a, PdbAddress b) => a.CompareTo(b) > 0; /// /// Returns true if is equal to /// /// First /// Second /// public static bool operator ==(PdbAddress a, PdbAddress b) => a.Equals(b); /// /// Returns true if is not equal to /// /// First /// Second /// public static bool operator !=(PdbAddress a, PdbAddress b) => !a.Equals(b); /// /// Compares this instance with and returns less than 0 if it's /// less than , 0 if it's equal to and /// greater than 0 if it's greater than /// /// Other instance /// public int CompareTo(PdbAddress other) { if (Section != other.Section) return Section.CompareTo(other.Section); return Offset.CompareTo(other.Offset); } /// /// Compares this to another instance /// /// The other one /// true if they're equal public bool Equals(PdbAddress other) => Section == other.Section && Offset == other.Offset; /// /// Compares this to another instance /// /// The other one /// true if they're equal public override bool Equals(object obj) { if (!(obj is PdbAddress)) return false; return Equals((PdbAddress)obj); } /// /// Gets the hash code /// /// Hash code public override int GetHashCode() => (Section << 16) ^ (int)Offset; /// /// ToString() override /// /// public override string ToString() => $"{Section:X4}:{Offset:X8}"; /// /// Reads a 32-bit offset followed by a 16-bit section and creates a new /// /// Reader /// public static PdbAddress ReadAddress(ref DataReader reader) { uint offs = reader.ReadUInt32(); return new PdbAddress(reader.ReadUInt16(), offs); } } }