Package ghidra.program.model.address
Class GenericAddress
java.lang.Object
ghidra.program.model.address.GenericAddress
- All Implemented Interfaces:
Address,Comparable<Address>
- Direct Known Subclasses:
OldGenericNamespaceAddress,SegmentedAddress,SpecialAddress
Generic implementation of the Address interface. Consists of an
Address Space, an offset, and a namespace id.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AddressSpaceprotected longprotected static final StringFields inherited from interface ghidra.program.model.address.Address
EXT_FROM_ADDRESS, NO_ADDRESS, SEPARATOR, SEPARATOR_CHAR -
Method Summary
Modifier and TypeMethodDescriptionadd(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.intbooleanCompares this Address to the specified object.getAddress(String addrString) Creates a new Address by parsing a String representation of an address.longGet 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 addrOffset, boolean isAddressableWordOffset) Returns a new address in this address's space with the given offset.getNewTruncatedAddress(long addrOffset, boolean isAddressableWordOffset) Returns a new address in this address's space with the given offset.longGet the offset of this Address.Get the offset of this Address as a BigInteger.Returns the physical Address that corresponds to this Address.intReturns the number of bytes needed to form a pointer to this address.intgetSize()Returns the number of bits that are used to form the address.longGet the address offset as an unsigned number.inthashCode()Returns a hash code for this Address.booleanhasSameAddressSpace(Address addr) Return true if this address' address space is equal to the address space for addr.booleanReturns true if this address represents a location in constant space.booleanReturns true if this address represents an external location in the external address space.booleanReturns true if this address represents a location in the HASH space.booleanReturns true if this address represents an address in a loaded memory block.booleanReturns true if this address represents a location in memory.booleanReturns true if this address represents an address not loaded in real memory (i.e.booleanReturns true if this address represents a location in the register space.booleanReturns true if this address represents a location in stack space.booleanisSuccessor(Address addr) Tests whether the given address immediately follows this address.booleanReturns true if this address represents a location in unique space.booleanReturns true if this address represents a location in variable space.next()Returns the address's successor.previous()Returns the address's predecessor.subtract(long displacement) Creates a new address (possibly in a new space) by subtracting the displacement to this address.longCalculates 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.toString()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 nametoString(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.Returns a String representation of the address using the given string as a prefix.
-
Field Details
-
zeros
- See Also:
-
addrSpace
-
offset
protected long offset
-
-
Method Details
-
getAddress
Description copied from interface:AddressCreates 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:
getAddressin 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.
-
getNewAddress
Description copied from interface:AddressCreates a new Address in this address's space with the given byte offset.- Specified by:
getNewAddressin interfaceAddress- Parameters:
byteOffset- the byte offset for the new address.- Returns:
- the new Address.
-
getNewAddress
public Address getNewAddress(long addrOffset, boolean isAddressableWordOffset) throws AddressOutOfBoundsException Description copied from interface:AddressReturns 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:
getNewAddressin 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. SeeAddressSpace#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:AddressReturns 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:
getNewTruncatedAddressin 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. SeeAddressSpace#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:AddressGet the offset of this Address. -
getAddressableWordOffset
public long getAddressableWordOffset()Description copied from interface:AddressGet the addressable memory word offset which corresponds to this address.- Specified by:
getAddressableWordOffsetin interfaceAddress- Returns:
- addressable memory word offset
-
getUnsignedOffset
public long getUnsignedOffset()Description copied from interface:AddressGet the address offset as an unsigned number. This may be useful when dealing with signed spaces (e.g. stack)- Specified by:
getUnsignedOffsetin interfaceAddress- Returns:
- unsigned address offset
-
getAddressSpace
Description copied from interface:AddressReturns the address space associated with this address.- Specified by:
getAddressSpacein interfaceAddress- Returns:
- the address space
-
getSize
public int getSize()Description copied from interface:AddressReturns the number of bits that are used to form the address. Thus the maximum offset for this address space will be 2^size-1. -
subtract
Description copied from interface:AddressCalculates the displacement between two addresses (this - addr) -
subtractWrap
Description copied from interface:AddressCreates 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:
subtractWrapin interfaceAddress- Parameters:
displacement- the displacement to subtract.- Returns:
- The new Address formed by subtracting the displacement for the offset.
-
subtractWrapSpace
Description copied from interface:AddressCreates 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:
subtractWrapSpacein interfaceAddress- Parameters:
displacement- the displacement to add.- Returns:
- The new Address formed by subtracting the displacement from this address's offset.
-
subtractNoWrap
Description copied from interface:AddressCreates 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:
subtractNoWrapin 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.
-
subtract
Description copied from interface:AddressCreates a new address (possibly in a new space) by subtracting the displacement to this address. -
addWrap
Description copied from interface:AddressCreates 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. -
addWrapSpace
Description copied from interface:AddressCreates 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:
addWrapSpacein interfaceAddress- Parameters:
displacement- the displacement to add.- Returns:
- The new Address formed by adding the displacement to this address's offset.
-
addNoWrap
Description copied from interface:AddressCreates 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:
addNoWrapin 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.
-
addNoWrap
- Specified by:
addNoWrapin interfaceAddress- Throws:
AddressOverflowException
-
add
Description copied from interface:AddressCreates a new address (possibly in a new space) by adding the displacement to this address. -
isSuccessor
Description copied from interface:AddressTests whether the given address immediately follows this address.- Specified by:
isSuccessorin interfaceAddress- Parameters:
addr- the address to test.- Returns:
- true if the address follows this address.
-
compareTo
- Specified by:
compareToin interfaceComparable<Address>
-
equals
Description copied from interface:AddressCompares this Address to the specified object. The result istrueif and only if the argument is notnulland is aAddressobject that represents the same address as this object. -
hashCode
public int hashCode()Description copied from interface:AddressReturns a hash code for this Address. The hash code for anAddressshould 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(). -
toString
Description copied from interface:AddressReturns a String representation of the address in hex and padded to the appropriate size. -
toString
Description copied from interface:AddressReturns a String representation of the address using the given string as a prefix. Equivalent of prefix + ":" + toString(false) -
toString
Description copied from interface:AddressReturns a String representation that may include the address space name -
toString
Description copied from interface:AddressReturns a String representation that may include the address space name and may or may not pad the address with leading zeros.- Specified by:
toStringin 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
Description copied from interface:AddressReturns a String representation that may include the address space name and may or may not pad the address with leading zeros.- Specified by:
toStringin 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
Description copied from interface:AddressReturn true if this address' address space is equal to the address space for addr.- Specified by:
hasSameAddressSpacein interfaceAddress- Parameters:
addr- the address to check- Returns:
- true if the same space
-
next
Description copied from interface:AddressReturns 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. -
previous
Description copied from interface:AddressReturns 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. -
getPhysicalAddress
Description copied from interface:AddressReturns the physical Address that corresponds to this Address.- Specified by:
getPhysicalAddressin interfaceAddress- Returns:
- address in a physical space corresponding to this address.
-
getPointerSize
public int getPointerSize()Description copied from interface:AddressReturns the number of bytes needed to form a pointer to this address. The result will be one of {1,2,4,8}.- Specified by:
getPointerSizein interfaceAddress- Returns:
- the pointer size
- See Also:
-
isMemoryAddress
public boolean isMemoryAddress()Description copied from interface:AddressReturns true if this address represents a location in memory.- Specified by:
isMemoryAddressin interfaceAddress- Returns:
- true if this address represents a location in memory.
-
isLoadedMemoryAddress
public boolean isLoadedMemoryAddress()Description copied from interface:AddressReturns true if this address represents an address in a loaded memory block.- Specified by:
isLoadedMemoryAddressin interfaceAddress- Returns:
- true if this address represents an address in a loaded memory block.
-
isNonLoadedMemoryAddress
public boolean isNonLoadedMemoryAddress()Description copied from interface:AddressReturns true if this address represents an address not loaded in real memory (i.e. OTHER).- Specified by:
isNonLoadedMemoryAddressin interfaceAddress- Returns:
- true if this address represents an address not loaded in real memory (i.e. OTHER).
-
isHashAddress
public boolean isHashAddress()Description copied from interface:AddressReturns true if this address represents a location in the HASH space.- Specified by:
isHashAddressin interfaceAddress- Returns:
- true if this address represents a location in the HASH space.
-
isStackAddress
public boolean isStackAddress()Description copied from interface:AddressReturns true if this address represents a location in stack space.- Specified by:
isStackAddressin interfaceAddress- Returns:
- true if this address represents a location in stack space.
-
isUniqueAddress
public boolean isUniqueAddress()Description copied from interface:AddressReturns true if this address represents a location in unique space.- Specified by:
isUniqueAddressin interfaceAddress- Returns:
- true if this address represents a location in unique space.
-
isConstantAddress
public boolean isConstantAddress()Description copied from interface:AddressReturns true if this address represents a location in constant space.- Specified by:
isConstantAddressin interfaceAddress- Returns:
- true if this address represents a location in constant space.
-
isVariableAddress
public boolean isVariableAddress()Description copied from interface:AddressReturns true if this address represents a location in variable space.- Specified by:
isVariableAddressin interfaceAddress- Returns:
- true if this address represents a location in variable space.
-
isRegisterAddress
public boolean isRegisterAddress()Description copied from interface:AddressReturns true if this address represents a location in the register space.NOTE: It is important to note that a
Registercould reside within a memory space and not the register space in which case this method would return false for its address.- Specified by:
isRegisterAddressin interfaceAddress- Returns:
- true if a register address
-
isExternalAddress
public boolean isExternalAddress()Description copied from interface:AddressReturns true if this address represents an external location in the external address space.- Specified by:
isExternalAddressin interfaceAddress- Returns:
- true if this address represents an external location in the external address space.
-
getOffsetAsBigInteger
Description copied from interface:AddressGet the offset of this Address as a BigInteger.- Specified by:
getOffsetAsBigIntegerin interfaceAddress- Returns:
- the offset of this Address.
-