Package ghidra.program.model.address
Class GenericAddress
- java.lang.Object
-
- ghidra.program.model.address.GenericAddress
-
- Direct Known Subclasses:
OldGenericNamespaceAddress
,SegmentedAddress
,SpecialAddress
public class GenericAddress extends java.lang.Object implements Address
Generic implementation of the Address interface. Consists of an Address Space, an offset, and a namespace id.
-
-
Field Summary
Fields Modifier and Type Field Description protected AddressSpace
addrSpace
protected long
offset
protected static java.lang.String
zeros
-
Fields inherited from interface ghidra.program.model.address.Address
EXT_FROM_ADDRESS, NO_ADDRESS, SEPARATOR_CHAR
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Address
add(long displacement)
Creates a new address (possibly in a new space) by adding the displacement to this address.Address
addNoWrap(long displacement)
Creates a new Address with a displacement relative to this Address.Address
addNoWrap(java.math.BigInteger displacement)
Address
addWrap(long displacement)
Creates a new address by adding the displacement to the current address.Address
addWrapSpace(long displacement)
Creates a new address by adding the displacement to the current address.int
compareTo(Address a)
boolean
equals(java.lang.Object o)
Compares this Address to the specified object.Address
getAddress(java.lang.String addrString)
Creates a new Address by parsing a String representation of an address.long
getAddressableWordOffset()
Get the addressable memory word offset which corresponds to this address.AddressSpace
getAddressSpace()
Returns the address space associated with this address.Address
getNewAddress(long byteOffset)
Creates a new Address in this address's space with the given byte offset.Address
getNewAddress(long addrOffset, boolean isAddressableWordOffset)
Returns a new address in this address's space with the given offset.Address
getNewTruncatedAddress(long addrOffset, boolean isAddressableWordOffset)
Returns a new address in this address's space with the given offset.long
getOffset()
Get the offset of this Address.java.math.BigInteger
getOffsetAsBigInteger()
Get the offset of this Address as a BigIntegerAddress
getPhysicalAddress()
Returns the physical Address that corresponds to this Address.int
getPointerSize()
Returns the number of bytes needed to form a pointer to this address.int
getSize()
Returns the number of bits that are used to form the address.long
getUnsignedOffset()
Get the address offset as an unsigned number.int
hashCode()
Returns a hashcode for this Address.boolean
hasSameAddressSpace(Address addr)
Return true if this address' address space is equal to the address space for addr.boolean
isConstantAddress()
Returns true if this address represents a location in constant spaceboolean
isExternalAddress()
Returns true if this address represents an external location in the external address spaceboolean
isHashAddress()
Returns true if this address represents a location in the HASH spaceboolean
isLoadedMemoryAddress()
Returns true if this address represents an address in a loaded memory blockboolean
isMemoryAddress()
Returns true if this address represents a location in memoryboolean
isNonLoadedMemoryAddress()
Returns true if this address represents an address not loaded in real memory (i.e.boolean
isRegisterAddress()
Returns true if this address represents a location in register space.boolean
isStackAddress()
Returns true if this address represents a location in stack spaceboolean
isSuccessor(Address addr)
Tests whether the given address immediately follows this address.boolean
isUniqueAddress()
Returns true if this address represents a location in unique spaceboolean
isVariableAddress()
Returns true if this address represents a location in variable spaceAddress
next()
Returns the address's successor.Address
previous()
Returns the address's predecessor.Address
subtract(long displacement)
Creates a new address (possibly in a new space) by subtracting the displacement to this address.long
subtract(Address addr)
Calculates the displacement between two addresses (this - addr
)Address
subtractNoWrap(long displacement)
Creates a new Address by subtracting displacement from the Address.Address
subtractWrap(long displacement)
Creates a new address by subtracting the displacement from the current address.Address
subtractWrapSpace(long displacement)
Creates a new address by subtracting the displacement from the current address.java.lang.String
toString()
Returns a String representation of the address in hex and padded to the appropriate size.java.lang.String
toString(boolean showAddressSpace)
Returns a String representation that may include the address space namejava.lang.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.java.lang.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.java.lang.String
toString(java.lang.String prefix)
Returns a String representation of the address using the given string as a prefix.
-
-
-
Field Detail
-
zeros
protected static final java.lang.String zeros
- See Also:
- Constant Field Values
-
addrSpace
protected AddressSpace addrSpace
-
offset
protected long offset
-
-
Method Detail
-
getAddress
public Address getAddress(java.lang.String addrString) throws AddressFormatException
Description copied from interface:Address
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.- Specified by:
getAddress
in interfaceAddress
- 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.- See Also:
Address.getAddress(java.lang.String)
-
getNewAddress
public Address getNewAddress(long byteOffset)
Description copied from interface:Address
Creates a new Address in this address's space with the given byte offset.- Specified by:
getNewAddress
in interfaceAddress
- Parameters:
byteOffset
- the byte offset for the new address.- Returns:
- the new Address.
- See Also:
Address.getNewAddress(long)
-
getNewAddress
public Address getNewAddress(long addrOffset, boolean isAddressableWordOffset) throws AddressOutOfBoundsException
Description copied from interface:Address
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.- Specified by:
getNewAddress
in interfaceAddress
- Parameters:
addrOffset
- 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#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
public Address getNewTruncatedAddress(long addrOffset, boolean isAddressableWordOffset) throws AddressOutOfBoundsException
Description copied from interface:Address
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.- Specified by:
getNewTruncatedAddress
in interfaceAddress
- Parameters:
addrOffset
- 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#getAddressableUnitSize()
to understand the distinction (i.e., wordOffset = byteOffset * addressableUnitSize).- Returns:
- address with given byte offset truncated to the physical space size
- Throws:
AddressOutOfBoundsException
-
getOffset
public long getOffset()
Description copied from interface:Address
Get the offset of this Address.- Specified by:
getOffset
in interfaceAddress
- Returns:
- the offset of this Address.
- See Also:
Address.getOffset()
-
getAddressableWordOffset
public long getAddressableWordOffset()
Description copied from interface:Address
Get the addressable memory word offset which corresponds to this address.- Specified by:
getAddressableWordOffset
in interfaceAddress
- Returns:
- addressable memory word offset
-
getUnsignedOffset
public long getUnsignedOffset()
Description copied from interface:Address
Get the address offset as an unsigned number. This may be useful when dealing with signed spaces (e.g. stack)- Specified by:
getUnsignedOffset
in interfaceAddress
- Returns:
- unsigned address offset
- See Also:
Address.getUnsignedOffset()
-
getAddressSpace
public AddressSpace getAddressSpace()
Description copied from interface:Address
Returns the address space associated with this address.- Specified by:
getAddressSpace
in interfaceAddress
- See Also:
Address.getAddressSpace()
-
getSize
public int getSize()
Description copied from interface:Address
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.- Specified by:
getSize
in interfaceAddress
- See Also:
Address.getSize()
-
subtract
public long subtract(Address addr)
Description copied from interface:Address
Calculates the displacement between two addresses (this - addr
)- Specified by:
subtract
in interfaceAddress
- Parameters:
addr
- the Address to subtract fromthis
address- Returns:
- the difference (thisAddress.offset - thatAddress.offset)
- See Also:
Address.subtract(ghidra.program.model.address.Address)
-
subtractWrap
public Address subtractWrap(long displacement)
Description copied from interface:Address
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.- Specified by:
subtractWrap
in interfaceAddress
- Parameters:
displacement
- the displacement to subtract.- Returns:
- The new Address formed by subtracting the displacement for the offset.
- See Also:
Address.subtractWrap(long)
-
subtractWrapSpace
public Address subtractWrapSpace(long displacement)
Description copied from interface:Address
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.- Specified by:
subtractWrapSpace
in interfaceAddress
- Parameters:
displacement
- the displacement to add.- Returns:
- The new Address formed by subtracting the displacement from this address's offset.
- See Also:
Address.subtractWrapSpace(long)
-
subtractNoWrap
public Address subtractNoWrap(long displacement) throws AddressOverflowException
Description copied from interface:Address
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.- Specified by:
subtractNoWrap
in interfaceAddress
- Parameters:
displacement
- the displacement to subtract.- Returns:
- The new Address
- Throws:
AddressOverflowException
- if the offset in this Address would overflow due to this operation.- See Also:
Address.subtractNoWrap(long)
-
subtract
public Address subtract(long displacement)
Description copied from interface:Address
Creates a new address (possibly in a new space) by subtracting the displacement to this address.- Specified by:
subtract
in interfaceAddress
- Parameters:
displacement
- the amount to subtract from this offset.- Returns:
- The address using the subtracted offset.
- See Also:
Address.subtract(long)
-
addWrap
public Address addWrap(long displacement)
Description copied from interface:Address
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.- Specified by:
addWrap
in interfaceAddress
- Parameters:
displacement
- the displacement to add.- Returns:
- The new Address formed by adding the displacement to this address's offset.
- See Also:
Address.addWrap(long)
-
addWrapSpace
public Address addWrapSpace(long displacement)
Description copied from interface:Address
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.- Specified by:
addWrapSpace
in interfaceAddress
- Parameters:
displacement
- the displacement to add.- Returns:
- The new Address formed by adding the displacement to this address's offset.
- See Also:
Address.addWrapSpace(long)
-
addNoWrap
public Address addNoWrap(long displacement) throws AddressOverflowException
Description copied from interface:Address
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.- Specified by:
addNoWrap
in interfaceAddress
- 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.- See Also:
Address.addNoWrap(long)
-
addNoWrap
public Address addNoWrap(java.math.BigInteger displacement) throws AddressOverflowException
- Specified by:
addNoWrap
in interfaceAddress
- Throws:
AddressOverflowException
-
add
public Address add(long displacement)
Description copied from interface:Address
Creates a new address (possibly in a new space) by adding the displacement to this address.- Specified by:
add
in interfaceAddress
- Parameters:
displacement
- the amount to add to this offset.- Returns:
- The new address.
- See Also:
Address.add(long)
-
isSuccessor
public boolean isSuccessor(Address addr)
Description copied from interface:Address
Tests whether the given address immediately follows this address.- Specified by:
isSuccessor
in interfaceAddress
- Parameters:
addr
- the address to test.- See Also:
Address.isSuccessor(ghidra.program.model.address.Address)
-
compareTo
public int compareTo(Address a)
- Specified by:
compareTo
in interfacejava.lang.Comparable<Address>
-
equals
public boolean equals(java.lang.Object o)
Description copied from interface:Address
Compares this Address to the specified object. The result istrue
if and only if the argument is notnull
and is aAddress
object that represents the same address as this object.
-
hashCode
public int hashCode()
Description copied from interface:Address
Returns a hashcode for this Address. The hashcode for anAddress
should be a value such that two Address objects which are equal will return the same hashcode. This method should generally return the same value as getLong().
-
toString
public java.lang.String toString()
Description copied from interface:Address
Returns a String representation of the address in hex and padded to the appropriate size.
-
toString
public java.lang.String toString(java.lang.String prefix)
Description copied from interface:Address
Returns a String representation of the address using the given string as a prefix. Equivalent of prefix + ":" + toString(false)- Specified by:
toString
in interfaceAddress
- Parameters:
prefix
- the string to prepend to the address string.- See Also:
Address.toString(java.lang.String)
-
toString
public java.lang.String toString(boolean showAddressSpace)
Description copied from interface:Address
Returns a String representation that may include the address space name
-
toString
public java.lang.String toString(boolean showAddressSpace, boolean pad)
Description copied from interface:Address
Returns a String representation that may include the address space name and may or may not pad the address with leading zeros.- Specified by:
toString
in interfaceAddress
- 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
public java.lang.String toString(boolean showAddressSpace, int minNumDigits)
Description copied from interface:Address
Returns a String representation that may include the address space name and may or may not pad the address with leading zeros.- Specified by:
toString
in interfaceAddress
- 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.
-
hasSameAddressSpace
public boolean hasSameAddressSpace(Address addr)
Description copied from interface:Address
Return true if this address' address space is equal to the address space for addr.- Specified by:
hasSameAddressSpace
in interfaceAddress
- See Also:
Address.hasSameAddressSpace(ghidra.program.model.address.Address)
-
next
public Address next()
Description copied from interface:Address
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.- Specified by:
next
in interfaceAddress
- Returns:
- the next higher address, or null if already at the highest address.
- See Also:
Address.next()
-
previous
public Address previous()
Description copied from interface:Address
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.- Specified by:
previous
in interfaceAddress
- Returns:
- the next lower address, or null if already at the lowest address.
- See Also:
Address.previous()
-
getPhysicalAddress
public Address getPhysicalAddress()
Description copied from interface:Address
Returns the physical Address that corresponds to this Address.- Specified by:
getPhysicalAddress
in interfaceAddress
- Returns:
- address in a physical space corresponding to this address.
- See Also:
Address.getPhysicalAddress()
-
getPointerSize
public int getPointerSize()
Description copied from interface:Address
Returns the number of bytes needed to form a pointer to this address. The result will be one of {1,2,4,8}.- Specified by:
getPointerSize
in interfaceAddress
- See Also:
Address.getPointerSize()
-
isMemoryAddress
public boolean isMemoryAddress()
Description copied from interface:Address
Returns true if this address represents a location in memory- Specified by:
isMemoryAddress
in interfaceAddress
- See Also:
Address.isMemoryAddress()
-
isLoadedMemoryAddress
public boolean isLoadedMemoryAddress()
Description copied from interface:Address
Returns true if this address represents an address in a loaded memory block- Specified by:
isLoadedMemoryAddress
in interfaceAddress
-
isNonLoadedMemoryAddress
public boolean isNonLoadedMemoryAddress()
Description copied from interface:Address
Returns true if this address represents an address not loaded in real memory (i.e. OTHER)- Specified by:
isNonLoadedMemoryAddress
in interfaceAddress
-
isHashAddress
public boolean isHashAddress()
Description copied from interface:Address
Returns true if this address represents a location in the HASH space- Specified by:
isHashAddress
in interfaceAddress
- See Also:
Address.isHashAddress()
-
isStackAddress
public boolean isStackAddress()
Description copied from interface:Address
Returns true if this address represents a location in stack space- Specified by:
isStackAddress
in interfaceAddress
- See Also:
Address.isStackAddress()
-
isUniqueAddress
public boolean isUniqueAddress()
Description copied from interface:Address
Returns true if this address represents a location in unique space- Specified by:
isUniqueAddress
in interfaceAddress
- See Also:
Address.isUniqueAddress()
-
isConstantAddress
public boolean isConstantAddress()
Description copied from interface:Address
Returns true if this address represents a location in constant space- Specified by:
isConstantAddress
in interfaceAddress
- See Also:
Address.isConstantAddress()
-
isVariableAddress
public boolean isVariableAddress()
Description copied from interface:Address
Returns true if this address represents a location in variable space- Specified by:
isVariableAddress
in interfaceAddress
- See Also:
Address.isVariableAddress()
-
isRegisterAddress
public boolean isRegisterAddress()
Description copied from interface:Address
Returns true if this address represents a location in register space.- Specified by:
isRegisterAddress
in interfaceAddress
- See Also:
Address.isRegisterAddress()
-
isExternalAddress
public boolean isExternalAddress()
Description copied from interface:Address
Returns true if this address represents an external location in the external address space- Specified by:
isExternalAddress
in interfaceAddress
- See Also:
Address.isExternalAddress()
-
getOffsetAsBigInteger
public java.math.BigInteger getOffsetAsBigInteger()
Description copied from interface:Address
Get the offset of this Address as a BigInteger- Specified by:
getOffsetAsBigInteger
in interfaceAddress
- Returns:
- the offset of this Address.
-
-