Package ghidra.program.model.address
Class DefaultAddressFactory
- java.lang.Object
-
- ghidra.program.model.address.DefaultAddressFactory
-
- All Implemented Interfaces:
AddressFactory
- Direct Known Subclasses:
ProgramAddressFactory
public class DefaultAddressFactory extends java.lang.Object implements AddressFactory
Keeps track of all the Address spaces in the program and provides methods for parsing address strings.
-
-
Constructor Summary
Constructors Constructor Description DefaultAddressFactory(AddressSpace[] addrSpaces)
Constructs a new DefaultAddressFactory.DefaultAddressFactory(AddressSpace[] addrSpaces, AddressSpace defaultSpace)
Constructs a new DefaultAddressFactory with the given spaces and default space.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addAddressSpace(AddressSpace space)
Adds an AddressSpace to this factoryboolean
equals(java.lang.Object o)
Address
getAddress(int spaceID, long offset)
Get an address using the addressSpace with the given id and having the given offset.Address
getAddress(java.lang.String addrString)
Create an address from String.AddressSet
getAddressSet()
Returns an addressSet containing all possible "real" addresses for this address factory.AddressSet
getAddressSet(Address min, Address max)
Computes an address set from a start and end address that may span address spaces.AddressSpace
getAddressSpace(int spaceID)
Returns the space with the given spaceID or null if none existsAddressSpace
getAddressSpace(java.lang.String name)
Returns the space with the given name or null if no space exists with that name.AddressSpace[]
getAddressSpaces()
Get the array of all "physical" AddressSpaces.Address[]
getAllAddresses(java.lang.String addrString)
Generates all reasonable addresses that can be interpreted from the given string.Address[]
getAllAddresses(java.lang.String addrString, boolean caseSensitive)
Generates all reasonable addresses that can be interpreted from the given string.AddressSpace[]
getAllAddressSpaces()
Returns an array of all address spaces, including analysis spaces.Address
getConstantAddress(long offset)
Returns an address in "constant" space with the given offset.AddressSpace
getConstantSpace()
Returns the "constant" address space.AddressSpace
getDefaultAddressSpace()
Returns the default AddressSpacelong
getIndex(Address addr)
Returns the index (old encoding) for the given address.int
getNumAddressSpaces()
Returns the number of physical AddressSpaces.AddressSpace
getPhysicalSpace(AddressSpace space)
Gets the physical address space associated with the given address space.AddressSpace[]
getPhysicalSpaces()
Returns an array of all the physical address spaces.AddressSpace
getRegisterSpace()
Returns the "register" address space.AddressSpace
getStackSpace()
Returns the "stack" address space.AddressSpace
getUniqueSpace()
Returns the "unique" address space.boolean
hasMultipleMemorySpaces()
Returns true if there is more than one memory address spaceboolean
isValidAddress(Address addr)
Tests if the given address is valid for at least one of the Address Spaces in this factoryAddress
oldGetAddressFromLong(long value)
Returns the address using the old encoding format.protected void
removeAddressSpace(java.lang.String spaceName)
Removes the AddressSpace from this factoryprotected void
renameOverlaySpace(java.lang.String oldName, java.lang.String newName)
-
-
-
Constructor Detail
-
DefaultAddressFactory
public DefaultAddressFactory(AddressSpace[] addrSpaces)
Constructs a new DefaultAddressFactory. The default space is assumed to be the first space in the array.- Parameters:
addrSpaces
- array of address spaces for the Program
-
DefaultAddressFactory
public DefaultAddressFactory(AddressSpace[] addrSpaces, AddressSpace defaultSpace)
Constructs a new DefaultAddressFactory with the given spaces and default space.- Parameters:
addrSpaces
- the set of addressSpaces to managedefaultSpace
- the space to use as the default space. The default space should be one of the spaces provided in the addrSpaces array.
-
-
Method Detail
-
getAddress
public Address getAddress(java.lang.String addrString)
Description copied from interface:AddressFactory
Create an address from String. Attempts to use the "default" address space first. Otherwise loops through each addressSpace, returning the first valid address that any addressSpace creates from the string. Returns an Address if the string is valid, otherwise null.- Specified by:
getAddress
in interfaceAddressFactory
- See Also:
AddressFactory.getAddress(java.lang.String)
-
getAllAddresses
public Address[] getAllAddresses(java.lang.String addrString)
Description copied from interface:AddressFactory
Generates all reasonable addresses that can be interpreted from the given string. Each Address Space is given a change to parse the string and all the valid results are return in the array.- Specified by:
getAllAddresses
in interfaceAddressFactory
- Parameters:
addrString
- the address string to parse.- Returns:
- Address[] The list of addresses generated from the string.
-
getAllAddresses
public Address[] getAllAddresses(java.lang.String addrString, boolean caseSensitive)
Description copied from interface:AddressFactory
Generates all reasonable addresses that can be interpreted from the given string. Each Address Space is given a change to parse the string and all the valid results are return in the array.- Specified by:
getAllAddresses
in interfaceAddressFactory
- Parameters:
addrString
- the address string to parse.caseSensitive
- determines if addressSpace names must be case sensitive to match.- Returns:
- Address[] The list of addresses generated from the string.
-
getDefaultAddressSpace
public AddressSpace getDefaultAddressSpace()
Description copied from interface:AddressFactory
Returns the default AddressSpace- Specified by:
getDefaultAddressSpace
in interfaceAddressFactory
-
getAddressSpaces
public AddressSpace[] getAddressSpaces()
Description copied from interface:AddressFactory
Get the array of all "physical" AddressSpaces.- Specified by:
getAddressSpaces
in interfaceAddressFactory
-
getAllAddressSpaces
public AddressSpace[] getAllAddressSpaces()
Description copied from interface:AddressFactory
Returns an array of all address spaces, including analysis spaces.- Specified by:
getAllAddressSpaces
in interfaceAddressFactory
- Returns:
- an array of all the address spaces.
-
getAddressSpace
public AddressSpace getAddressSpace(java.lang.String name)
Description copied from interface:AddressFactory
Returns the space with the given name or null if no space exists with that name.- Specified by:
getAddressSpace
in interfaceAddressFactory
-
getAddressSpace
public AddressSpace getAddressSpace(int spaceID)
Description copied from interface:AddressFactory
Returns the space with the given spaceID or null if none exists- Specified by:
getAddressSpace
in interfaceAddressFactory
-
getNumAddressSpaces
public int getNumAddressSpaces()
Description copied from interface:AddressFactory
Returns the number of physical AddressSpaces.- Specified by:
getNumAddressSpaces
in interfaceAddressFactory
-
isValidAddress
public boolean isValidAddress(Address addr)
Description copied from interface:AddressFactory
Tests if the given address is valid for at least one of the Address Spaces in this factory- Specified by:
isValidAddress
in interfaceAddressFactory
- Parameters:
addr
- The address to test- Returns:
- boolean true if the address valid, false otherwise
-
equals
public boolean equals(java.lang.Object o)
- Specified by:
equals
in interfaceAddressFactory
- Overrides:
equals
in classjava.lang.Object
- See Also:
Object.equals(Object)
-
getIndex
public long getIndex(Address addr)
Description copied from interface:AddressFactory
Returns the index (old encoding) for the given address.- Specified by:
getIndex
in interfaceAddressFactory
- Parameters:
addr
- the address to encode.
-
getPhysicalSpace
public AddressSpace getPhysicalSpace(AddressSpace space)
Description copied from interface:AddressFactory
Gets the physical address space associated with the given address space. If the given space is physical, then it will be returned.- Specified by:
getPhysicalSpace
in interfaceAddressFactory
- Parameters:
space
- the addressSpace for which the physical space is requested.- Returns:
- the physical address space associated with the given address space.
-
getPhysicalSpaces
public AddressSpace[] getPhysicalSpaces()
Description copied from interface:AddressFactory
Returns an array of all the physical address spaces.- Specified by:
getPhysicalSpaces
in interfaceAddressFactory
- Returns:
- an array of all the physical address spaces.
-
getAddress
public Address getAddress(int spaceID, long offset)
Description copied from interface:AddressFactory
Get an address using the addressSpace with the given id and having the given offset.- Specified by:
getAddress
in interfaceAddressFactory
- Parameters:
spaceID
- the id of the address space to use to create the new address.offset
- the offset of the new address to be created.- Returns:
- the new address.
-
getConstantSpace
public AddressSpace getConstantSpace()
Description copied from interface:AddressFactory
Returns the "constant" address space.- Specified by:
getConstantSpace
in interfaceAddressFactory
-
getUniqueSpace
public AddressSpace getUniqueSpace()
Description copied from interface:AddressFactory
Returns the "unique" address space.- Specified by:
getUniqueSpace
in interfaceAddressFactory
-
getStackSpace
public AddressSpace getStackSpace()
Description copied from interface:AddressFactory
Returns the "stack" address space.- Specified by:
getStackSpace
in interfaceAddressFactory
-
getRegisterSpace
public AddressSpace getRegisterSpace()
Description copied from interface:AddressFactory
Returns the "register" address space.- Specified by:
getRegisterSpace
in interfaceAddressFactory
-
getConstantAddress
public Address getConstantAddress(long offset)
Description copied from interface:AddressFactory
Returns an address in "constant" space with the given offset.- Specified by:
getConstantAddress
in interfaceAddressFactory
- Parameters:
offset
- the offset in "constant" space for the new address.- Returns:
- a new address in the "constant" space with the given offset.
-
getAddressSet
public AddressSet getAddressSet(Address min, Address max)
Description copied from interface:AddressFactory
Computes an address set from a start and end address that may span address spaces. Although in general, it is not meaningful to compare addresses from multiple spaces, but since there is an absolute ordering of address spaces it can be useful for iterating over all addresses in a program with multiple address spaces.- Specified by:
getAddressSet
in interfaceAddressFactory
- Parameters:
min
- the start addressmax
- the end address.- Returns:
- an addressSet containing ranges that don't span address spaces.
-
getAddressSet
public AddressSet getAddressSet()
Description copied from interface:AddressFactory
Returns an addressSet containing all possible "real" addresses for this address factory.- Specified by:
getAddressSet
in interfaceAddressFactory
-
oldGetAddressFromLong
public Address oldGetAddressFromLong(long value)
Description copied from interface:AddressFactory
Returns the address using the old encoding format.- Specified by:
oldGetAddressFromLong
in interfaceAddressFactory
- Parameters:
value
- to decode into an address.
-
addAddressSpace
protected void addAddressSpace(AddressSpace space) throws DuplicateNameException
Adds an AddressSpace to this factory- Parameters:
space
- the address space being added.- Throws:
DuplicateNameException
- if an address space with the given name already exists
-
renameOverlaySpace
protected void renameOverlaySpace(java.lang.String oldName, java.lang.String newName) throws DuplicateNameException
- Throws:
DuplicateNameException
-
removeAddressSpace
protected void removeAddressSpace(java.lang.String spaceName)
Removes the AddressSpace from this factory- Parameters:
spaceName
- the name of the space to remove.
-
hasMultipleMemorySpaces
public boolean hasMultipleMemorySpaces()
Description copied from interface:AddressFactory
Returns true if there is more than one memory address space- Specified by:
hasMultipleMemorySpaces
in interfaceAddressFactory
-
-