Interface Address

All Superinterfaces:
Comparable<Address>
All Known Implementing Classes:
GenericAddress, OldGenericNamespaceAddress, SegmentedAddress, SpecialAddress

public interface Address extends Comparable<Address>
An address represents a location in a program. Conceptually, addresses consist of an "address space" and an offset within that space. Many processors have only one "real" address space, but some have several spaces. Also, there are "artificial" address spaces used for analysis and representing other non-memory locations such as a register or an offset on the stack relative to a functions frame pointer.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Address
    Address object representing an external entry address.
    static final Address
    Address object representing an invalid address.
    static final String
     
    static final char
    Character used to separate space names from offsets.
  • Method Summary

    Modifier and Type
    Method
    Description
    add(long displacement)
    Creates a new address (possibly in a new space) by adding the displacement to this address.
    addNoWrap(long displacement)
    Creates a new Address with a displacement relative to this Address.
    addNoWrap(BigInteger displacement)
     
    addWrap(long displacement)
    Creates a new address by adding the displacement to the current address.
    addWrapSpace(long displacement)
    Creates a new address by adding the displacement to the current address.
    boolean
    Compares this Address to the specified object.
    getAddress(String addrString)
    Creates a new Address by parsing a String representation of an address.
    long
    Get the addressable memory word offset which corresponds to this address.
    Returns the address space associated with this address.
    getNewAddress(long byteOffset)
    Creates a new Address in this address's space with the given byte offset.
    getNewAddress(long offset, boolean isAddressableWordOffset)
    Returns a new address in this address's space with the given offset.
    getNewTruncatedAddress(long offset, boolean isAddressableWordOffset)
    Returns a new address in this address's space with the given offset.
    long
    Get the offset of this Address.
    Get the offset of this Address as a BigInteger.
    Returns the physical Address that corresponds to this Address.
    int
    Returns the number of bytes needed to form a pointer to this address.
    int
    Returns the number of bits that are used to form the address.
    long
    Get the address offset as an unsigned number.
    int
    Returns a hash code for this Address.
    boolean
    Return true if this address' address space is equal to the address space for addr.
    boolean
    Returns true if this address represents a location in constant space.
    boolean
    Returns true if this address represents an external location in the external address space.
    boolean
    Returns true if this address represents a location in the HASH space.
    boolean
    Returns true if this address represents an address in a loaded memory block.
    boolean
    Returns true if this address represents a location in memory.
    boolean
    Returns true if this address represents an address not loaded in real memory (i.e.
    boolean
    Returns true if this address represents a location in the register space.
    boolean
    Returns true if this address represents a location in stack space.
    boolean
    Tests whether the given address immediately follows this address.
    boolean
    Returns true if this address represents a location in unique space.
    boolean
    Returns true if this address represents a location in variable space.
    static Address
    Return the maximum of two addresses using Address.compareTo
    static Address
    Return the minimum of two addresses using Address.compareTo
    Returns the address's successor.
    Returns the address's predecessor.
    subtract(long displacement)
    Creates a new address (possibly in a new space) by subtracting the displacement to this address.
    long
    Calculates the displacement between two addresses (this - addr)
    subtractNoWrap(long displacement)
    Creates a new Address by subtracting displacement from the Address.
    subtractWrap(long displacement)
    Creates a new address by subtracting the displacement from the current address.
    subtractWrapSpace(long displacement)
    Creates a new address by subtracting the displacement from the current address.
    Returns a String representation of the address in hex and padded to the appropriate size.
    toString(boolean showAddressSpace)
    Returns a String representation that may include the address space name
    toString(boolean showAddressSpace, boolean pad)
    Returns a String representation that may include the address space name and may or may not pad the address with leading zeros.
    toString(boolean showAddressSpace, int minNumDigits)
    Returns a String representation that may include the address space name and may or may not pad the address with leading zeros.
    toString(String prefix)
    Returns a String representation of the address using the given string as a prefix.

    Methods inherited from interface java.lang.Comparable

    compareTo
  • Field Details

    • NO_ADDRESS

      static final Address NO_ADDRESS
      Address object representing an invalid address.
    • EXT_FROM_ADDRESS

      static final Address EXT_FROM_ADDRESS
      Address object representing an external entry address.
    • SEPARATOR_CHAR

      static final char SEPARATOR_CHAR
      Character used to separate space names from offsets.
      See Also:
    • SEPARATOR

      static final String SEPARATOR
      See Also:
  • Method Details

    • getAddress

      Address getAddress(String addrString) throws AddressFormatException
      Creates a new Address by parsing a String representation of an address. The string may be either a simple number (just the offset part of an address) or take the form "addressSpaceName:offset". If the latter form is used, the "addressSpaceName" must match the name of the space for this address.
      Parameters:
      addrString - the String to parse.
      Returns:
      the new Address if the string is a legally formed address or null if the string contains an address space name that does not match this address's space.
      Throws:
      AddressFormatException - if the string cannot be parsed or the parsed offset is larger than the size for this address' space.
    • getNewAddress

      Address getNewAddress(long byteOffset)
      Creates a new Address in this address's space with the given byte offset.
      Parameters:
      byteOffset - the byte offset for the new address.
      Returns:
      the new Address.
      Throws:
      AddressOutOfBoundsException - if the offset is less than the minimum offset or greater than the max offset allowed for this space.
    • getNewAddress

      Address getNewAddress(long offset, boolean isAddressableWordOffset) throws AddressOutOfBoundsException
      Returns a new address in this address's space with the given offset.

      NOTE: for those spaces with an addressable unit size other than 1, the address returned may not correspond to an addressable unit/word boundary if a byte-offset is specified.

      Parameters:
      offset - the offset for the new address.
      isAddressableWordOffset - if true the specified offset is an addressable unit/word offset, otherwise offset is a byte offset. See AddressSpace#getAddressableUnitSize() to understand the distinction (i.e., wordOffset = byteOffset * addressableUnitSize).
      Returns:
      address with given offset
      Throws:
      AddressOutOfBoundsException - if the offset is less than 0 or greater than the max offset allowed for this space.
    • getNewTruncatedAddress

      Address getNewTruncatedAddress(long offset, boolean isAddressableWordOffset)
      Returns a new address in this address's space with the given offset. The specified offset will be truncated within the space and will not throw an exception.

      NOTE: for those spaces with an addressable unit size other than 1, the address returned may not correspond to a word boundary (addressable unit) if a byte-offset is specified.

      Parameters:
      offset - the offset for the new address.
      isAddressableWordOffset - if true the specified offset is an addressable unit/word offset, otherwise offset is a byte offset. See AddressSpace#getAddressableUnitSize() to understand the distinction (i.e., wordOffset = byteOffset * addressableUnitSize).
      Returns:
      address with given byte offset truncated to the physical space size
    • getPointerSize

      int getPointerSize()
      Returns the number of bytes needed to form a pointer to this address. The result will be one of {1,2,4,8}.
      Returns:
      the pointer size
      See Also:
    • next

      Address next()
      Returns the address's successor. In most cases, this is equivalent to addr.add(1), but segmented addresses could span segments. The result of calling this on the highest address will result in a null return value.
      Returns:
      the next higher address, or null if already at the highest address.
    • previous

      Address previous()
      Returns the address's predecessor. In most cases, this is equivalent to addr.subtract(1), but segmented addresses could span segments. The result of calling this on the lowest address will result in a null return value.
      Returns:
      the next lower address, or null if already at the lowest address.
    • getOffset

      long getOffset()
      Get the offset of this Address.
      Returns:
      the offset of this Address.
    • getOffsetAsBigInteger

      BigInteger getOffsetAsBigInteger()
      Get the offset of this Address as a BigInteger.
      Returns:
      the offset of this Address.
    • getUnsignedOffset

      long getUnsignedOffset()
      Get the address offset as an unsigned number. This may be useful when dealing with signed spaces (e.g. stack)
      Returns:
      unsigned address offset
    • getAddressableWordOffset

      long getAddressableWordOffset()
      Get the addressable memory word offset which corresponds to this address.
      Returns:
      addressable memory word offset
    • getAddressSpace

      AddressSpace getAddressSpace()
      Returns the address space associated with this address.
      Returns:
      the address space
    • hasSameAddressSpace

      boolean hasSameAddressSpace(Address addr)
      Return true if this address' address space is equal to the address space for addr.
      Parameters:
      addr - the address to check
      Returns:
      true if the same space
    • getSize

      int getSize()
      Returns the number of bits that are used to form the address. Thus the maximum offset for this address space will be 2^size-1.
      Returns:
      the size
    • subtract

      long subtract(Address addr)
      Calculates the displacement between two addresses (this - addr)
      Parameters:
      addr - the Address to subtract from this address
      Returns:
      the difference (thisAddress.offset - thatAddress.offset)
      Throws:
      IllegalArgumentException - if the two addresses are not in the same address space
    • subtractWrap

      Address subtractWrap(long displacement)
      Creates a new address by subtracting the displacement from the current address. The new address will wrap in a manner that depends on the address space. For a generic address space this will wrap at the extents of the address space. For a segmented address space it will wrap at the extents of the segment.
      Parameters:
      displacement - the displacement to subtract.
      Returns:
      The new Address formed by subtracting the displacement for the offset.
    • subtractWrapSpace

      Address subtractWrapSpace(long displacement)
      Creates a new address by subtracting the displacement from the current address. If the offset is greater than the max offset of the address space, the high order bits are masked off, making the address wrap. For non-segmented addresses this will be the same as subtractWrap(). For segmented addresses, the address will wrap when the 20 bit (oxfffff) offset is exceeded, as opposed to when the segment offset is exceeded.
      Parameters:
      displacement - the displacement to add.
      Returns:
      The new Address formed by subtracting the displacement from this address's offset.
    • subtractNoWrap

      Address subtractNoWrap(long displacement) throws AddressOverflowException
      Creates a new Address by subtracting displacement from the Address. The Address will not wrap within the space and in fact will throw an exception if the result is less than the min address in this space or greater than the max address in this space.
      Parameters:
      displacement - the displacement to subtract.
      Returns:
      The new Address
      Throws:
      AddressOverflowException - if the offset in this Address would overflow due to this operation.
    • subtract

      Address subtract(long displacement)
      Creates a new address (possibly in a new space) by subtracting the displacement to this address.
      Parameters:
      displacement - the amount to subtract from this offset.
      Returns:
      The address using the subtracted offset.
    • addWrap

      Address addWrap(long displacement)
      Creates a new address by adding the displacement to the current address. The new address will wrap in a manner that depends on the address space. For a generic address space this will wrap at the extents of the address space. For a segmented address space it will wrap at the extents of the segment.
      Parameters:
      displacement - the displacement to add.
      Returns:
      The new Address formed by adding the displacement to this address's offset.
    • addWrapSpace

      Address addWrapSpace(long displacement)
      Creates a new address by adding the displacement to the current address. If the offset is greater than the max offset of the address space, the high order bits are masked off, making the address wrap. For non-segmented addresses this will be the same as addWrap(). For segmented addresses, the address will wrap when the 20 bit (oxfffff) offset is exceeded, as opposed to when the segment offset is exceeded.
      Parameters:
      displacement - the displacement to add.
      Returns:
      The new Address formed by adding the displacement to this address's offset.
    • addNoWrap

      Address addNoWrap(long displacement) throws AddressOverflowException
      Creates a new Address with a displacement relative to this Address. The Address will not wrap around! An exception will be throw if the result is not within this address space.
      Parameters:
      displacement - the displacement to add.
      Returns:
      the new address.
      Throws:
      AddressOverflowException - if the offset in this Address would overflow (wrap around) due to this operation.
    • addNoWrap

      Address addNoWrap(BigInteger displacement) throws AddressOverflowException
      Throws:
      AddressOverflowException
    • add

      Address add(long displacement) throws AddressOutOfBoundsException
      Creates a new address (possibly in a new space) by adding the displacement to this address.
      Parameters:
      displacement - the amount to add to this offset.
      Returns:
      The new address.
      Throws:
      AddressOutOfBoundsException - if wrapping is not supported by the corresponding address space and the addition causes an out-of-bounds error
    • isSuccessor

      boolean isSuccessor(Address addr)
      Tests whether the given address immediately follows this address.
      Parameters:
      addr - the address to test.
      Returns:
      true if the address follows this address.
    • toString

      String toString()
      Returns a String representation of the address in hex and padded to the appropriate size.
      Overrides:
      toString in class Object
      Returns:
      the string
    • toString

      String toString(String prefix)
      Returns a String representation of the address using the given string as a prefix. Equivalent of prefix + ":" + toString(false)
      Parameters:
      prefix - the string to prepend to the address string.
      Returns:
      the string
    • toString

      String toString(boolean showAddressSpace)
      Returns a String representation that may include the address space name
      Parameters:
      showAddressSpace - true if the address space should be included in resulting string.
      Returns:
      String the string representation of the address
    • toString

      String toString(boolean showAddressSpace, boolean pad)
      Returns a String representation that may include the address space name and may or may not pad the address with leading zeros.
      Parameters:
      showAddressSpace - if true, the addressSpace name will be prepended to the address string.
      pad - if true, the address will be prepended with leading zeros to completely fill out the max digits the address could contain. If false, the address will be prepended only to make the number of hex digits at least 4.
      Returns:
      the address as a String.
    • toString

      String toString(boolean showAddressSpace, int minNumDigits)
      Returns a String representation that may include the address space name and may or may not pad the address with leading zeros.
      Parameters:
      showAddressSpace - if true, the addressSpace name will be prepended to the address string.
      minNumDigits - specifies the minimum number of digits to use. If the address space size is less that minNumDigits, the address will be padded to the address space size. If the address space size is larger that minNumDigits, the address will be displayed with as many digits as necessary, but will contain leading zeros to make the address string have at least minNumDigits.
      Returns:
      the address as a String.
    • equals

      boolean equals(Object o)
      Compares this Address to the specified object. The result is true if and only if the argument is not null and is a Address object that represents the same address as this object.
      Overrides:
      equals in class Object
      Parameters:
      o - the object to compare this String against.
      Returns:
      true if the Addressesare equal; false otherwise.
    • hashCode

      int hashCode()
      Returns a hash code for this Address. The hash code for an Address should be a value such that two Address objects which are equal will return the same hash code. This method should generally return the same value as getLong().
      Overrides:
      hashCode in class Object
      Returns:
      a hash code value for this object.
    • getPhysicalAddress

      Address getPhysicalAddress()
      Returns the physical Address that corresponds to this Address.
      Returns:
      address in a physical space corresponding to this address.
    • isMemoryAddress

      boolean isMemoryAddress()
      Returns true if this address represents a location in memory.
      Returns:
      true if this address represents a location in memory.
    • isLoadedMemoryAddress

      boolean isLoadedMemoryAddress()
      Returns true if this address represents an address in a loaded memory block.
      Returns:
      true if this address represents an address in a loaded memory block.
    • isNonLoadedMemoryAddress

      boolean isNonLoadedMemoryAddress()
      Returns true if this address represents an address not loaded in real memory (i.e. OTHER).
      Returns:
      true if this address represents an address not loaded in real memory (i.e. OTHER).
    • isStackAddress

      boolean isStackAddress()
      Returns true if this address represents a location in stack space.
      Returns:
      true if this address represents a location in stack space.
    • isUniqueAddress

      boolean isUniqueAddress()
      Returns true if this address represents a location in unique space.
      Returns:
      true if this address represents a location in unique space.
    • isConstantAddress

      boolean isConstantAddress()
      Returns true if this address represents a location in constant space.
      Returns:
      true if this address represents a location in constant space.
    • isHashAddress

      boolean isHashAddress()
      Returns true if this address represents a location in the HASH space.
      Returns:
      true if this address represents a location in the HASH space.
    • isRegisterAddress

      boolean isRegisterAddress()
      Returns true if this address represents a location in the register space.

      NOTE: It is important to note that a Register could reside within a memory space and not the register space in which case this method would return false for its address.

      Returns:
      true if a register address
    • isVariableAddress

      boolean isVariableAddress()
      Returns true if this address represents a location in variable space.
      Returns:
      true if this address represents a location in variable space.
    • isExternalAddress

      boolean isExternalAddress()
      Returns true if this address represents an external location in the external address space.
      Returns:
      true if this address represents an external location in the external address space.
    • min

      static Address min(Address a, Address b)
      Return the minimum of two addresses using Address.compareTo
      Parameters:
      a - first address
      b - second address
      Returns:
      minimum of two addresses
    • max

      static Address max(Address a, Address b)
      Return the maximum of two addresses using Address.compareTo
      Parameters:
      a - first address
      b - second address
      Returns:
      maximum of two addresses