Package ghidra.trace.database.program
Class AbstractDBTraceProgramViewReferenceManager
java.lang.Object
ghidra.trace.database.program.AbstractDBTraceProgramViewReferenceManager
- All Implemented Interfaces:
ReferenceManager
- Direct Known Subclasses:
DBTraceProgramViewReferenceManager
public abstract class AbstractDBTraceProgramViewReferenceManager
extends Object
implements ReferenceManager
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected TraceCodeOperationsprotected final DBTraceProgramViewprotected TraceReferenceOperationsprotected final DBTraceReferenceManagerFields inherited from interface ghidra.program.model.symbol.ReferenceManager
MNEMONIC -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddExternalReference(Address fromAddr, int opIndex, ExternalLocation location, SourceType source, RefType type) Adds an external reference.addExternalReference(Address fromAddr, Namespace extNamespace, String extLabel, Address extAddr, SourceType source, int opIndex, RefType type) Adds an external reference.addExternalReference(Address fromAddr, String libraryName, String extLabel, Address extAddr, SourceType source, int opIndex, RefType type) Adds an external reference to an external symbol.addMemoryReference(Address fromAddr, Address toAddr, RefType type, SourceType source, int opIndex) Adds a memory reference.addOffsetMemReference(Address fromAddr, Address toAddr, boolean toAddrIsBase, long offset, RefType type, SourceType source, int opIndex) Add an offset memory reference.addReference(Reference reference) Add a memory, stack, register or external referenceaddRegisterReference(Address fromAddr, int opIndex, Register register, RefType type, SourceType source) Add a reference to a register.addShiftedMemReference(Address fromAddr, Address toAddr, int shiftValue, RefType type, SourceType source, int opIndex) Add a shifted memory reference; the "to" address is computed as the value at the operand at opIndex shifted by some number of bits, specified in the shiftValue parameter.addStackReference(Address fromAddr, int opIndex, int stackOffset, RefType type, SourceType source) Add a reference to a stack location.protected booleanprotected LifespanchooseLifespan(Address fromAddr) protected Collection<Reference> collect(Function<Long, Collection<? extends Reference>> refFunc) voidDeletes the given reference objectprotected abstract TraceCodeOperationsgetCodeOperations(boolean createIfAbsent) Returns an iterator over all external space referencesgetFlowReferencesFrom(Address addr) Get all flow references from the given address.getPrimaryReferenceFrom(Address addr, int opIndex) Get the primary reference from the given address.getReference(Address fromAddr, Address toAddr, int opIndex) Get the reference that has the given from and to address, and operand index.intgetReferenceCountFrom(Address fromAddr) Returns the number of references from the specifiedfromAddr.intgetReferenceCountTo(Address toAddr) Returns the number of references to the specifiedtoAddr.intReturn the number of references for "to" addresses.getReferenceDestinationIterator(Address startAddr, boolean forward) Returns an iterator over all addresses that are the "To" address in a reference.getReferenceDestinationIterator(AddressSetView addrSet, boolean forward) Returns an iterator over all addresses that are the "To" address in a memory reference, restricted by the given address set.getReferencedVariable(Reference reference) Returns the referenced function variable.protected Comparator<Reference> getReferenceFromComparator(boolean forward) getReferenceIterator(Address startAddr) Get an iterator over references starting with the specified fromAddr.getReferenceIteratorForSnap(long snap, Address startAddr) bytegetReferenceLevel(Address toAddr) Returns the reference level for the references to the given addressprotected abstract TraceReferenceOperationsgetReferenceOperations(boolean createIfAbsent) getReferencesFrom(Address addr) Get all references "from" the specified addr.getReferencesFrom(Address fromAddr, int opIndex) Returns all references "from" the given fromAddr and operand (specified by opIndex).intReturn the number of references for "from" addresses.getReferenceSourceIterator(Address startAddr, boolean forward) Returns an iterator over addresses that are the "From" address in a referencegetReferenceSourceIterator(AddressSetView addrSet, boolean forward) Returns an iterator over all addresses that are the "From" address in a reference, restricted by the given address set.getReferencesTo(Address addr) Get an iterator over all references that have the given address as their "To" address.getReferencesTo(Variable var) Returns all references to the given variable.static bytegetRefLevel(RefType rt) Get the reference level for a given reference typebooleanhasFlowReferencesFrom(Address addr) Return whether the given address has flow references from it.booleanhasReferencesFrom(Address fromAddr) Returns true if there are any memory references at the given address.booleanhasReferencesFrom(Address fromAddr, int opIndex) Returns true if there are any memory references at the given address/opIndex.booleanhasReferencesTo(Address toAddr) Return true if a memory reference exists with the given "to" address.voidremoveAllReferencesFrom(Address fromAddr) Remove all stack, external, and memory references for the given from address.voidremoveAllReferencesFrom(Address beginAddr, Address endAddr) Removes all references where "From address" is in the given range.voidremoveAllReferencesTo(Address toAddr) Remove all stack, external, and memory references for the given to address.voidRemoves any symbol associations with the given reference.voidsetAssociation(Symbol s, Reference ref) Associates the given reference with the given symbol.voidsetPrimary(Reference ref, boolean isPrimary) Set the given reference's primary attributeupdateRefType(Reference ref, RefType refType) Update the reference type on a memory reference.
-
Field Details
-
program
-
refs
-
code
-
refsManager
-
-
Constructor Details
-
AbstractDBTraceProgramViewReferenceManager
-
-
Method Details
-
getReferenceOperations
-
getCodeOperations
-
chooseLifespan
-
addReference
Description copied from interface:ReferenceManagerAdd a memory, stack, register or external reference- Specified by:
addReferencein interfaceReferenceManager- Parameters:
reference- reference to be added- Returns:
- new reference
-
addStackReference
public Reference addStackReference(Address fromAddr, int opIndex, int stackOffset, RefType type, SourceType source) Description copied from interface:ReferenceManagerAdd a reference to a stack location. If a reference already exists for the fromAddr and opIndex, the existing reference is replaced with the new reference.- Specified by:
addStackReferencein interfaceReferenceManager- Parameters:
fromAddr- "from" address within a functionopIndex- operand indexstackOffset- stack offset of the referencetype- reference type - how the location is being referenced.source- the source of this reference- Returns:
- new stack reference
-
addRegisterReference
public Reference addRegisterReference(Address fromAddr, int opIndex, Register register, RefType type, SourceType source) Description copied from interface:ReferenceManagerAdd a reference to a register. If a reference already exists for the fromAddr and opIndex, the existing reference is replaced with the new reference.- Specified by:
addRegisterReferencein interfaceReferenceManager- Parameters:
fromAddr- "from" addressopIndex- operand indexregister- register to add the reference totype- reference type - how the location is being referenced.source- the source of this reference- Returns:
- new register reference
-
addMemoryReference
public Reference addMemoryReference(Address fromAddr, Address toAddr, RefType type, SourceType source, int opIndex) Description copied from interface:ReferenceManagerAdds a memory reference. The first memory reference placed on an operand will be made primary by default. All non-memory references will be removed from the specified operand. Certain referencetypesmay not be specified (e.g.,RefType.FALL_THROUGH).- Specified by:
addMemoryReferencein interfaceReferenceManager- Parameters:
fromAddr- address of the code unit where the reference occurstoAddr- address of the location being referenced. Memory, stack, and register addresses are all permitted.type- reference type - how the location is being referenced.source- the source of this referenceopIndex- the operand index display of the operand making this reference- Returns:
- new memory reference
-
addOffsetMemReference
public Reference addOffsetMemReference(Address fromAddr, Address toAddr, boolean toAddrIsBase, long offset, RefType type, SourceType source, int opIndex) Description copied from interface:ReferenceManagerAdd an offset memory reference. The first memory reference placed on an operand will be made primary by default. All non-memory references will be removed from the specified operand. If toAddr corresponds to the EXTERNAL memory block (seeMemoryBlock.EXTERNAL_BLOCK_NAME) the resulting offset reference will report to/base address as the same regardless of specified offset.- Specified by:
addOffsetMemReferencein interfaceReferenceManager- Parameters:
fromAddr- address for the "from"toAddr- address of the location being referenced.toAddrIsBase- if true toAddr is treated as base address, else treated as (base+offet). It is generally preferred to specify as a base address to ensure proper handling of EXTERNAL block case.offset- value added to a base address to get the toAddrtype- reference type - how the location is being referencedsource- the source of this referenceopIndex- the operand index- Returns:
- new offset reference
-
addShiftedMemReference
public Reference addShiftedMemReference(Address fromAddr, Address toAddr, int shiftValue, RefType type, SourceType source, int opIndex) Description copied from interface:ReferenceManagerAdd a shifted memory reference; the "to" address is computed as the value at the operand at opIndex shifted by some number of bits, specified in the shiftValue parameter. The first memory reference placed on an operand will be made primary by default. All non-memory references will be removed from the specified operand.- Specified by:
addShiftedMemReferencein interfaceReferenceManager- Parameters:
fromAddr- source/from memory addresstoAddr- destination/to memory address computed as somebase offset valueshifted left by the number of bits specified by shiftValue. The least-significant bits of toAddr offset should be 0's based upon the specified shiftValue since this value is shifted right to calculate the base offset value.shiftValue- number of bits to shifttype- reference type - how the location is being referencedsource- the source of this referenceopIndex- the operand index- Returns:
- new shifted reference
-
addExternalReference
public Reference addExternalReference(Address fromAddr, String libraryName, String extLabel, Address extAddr, SourceType source, int opIndex, RefType type) throws InvalidInputException, DuplicateNameException Description copied from interface:ReferenceManagerAdds an external reference to an external symbol. If a reference already exists atfromAddrandopIndexthe existing reference is replaced with a new reference. If the external symbol cannot be found, a newLibraryand/orExternalLocationsymbol will be created which corresponds to the specified library/file namedlibraryNameand the location within that file identified byextLabeland/or its memory addressextAddr. Either or bothextLabelorextAddrmust be specified.- Specified by:
addExternalReferencein interfaceReferenceManager- Parameters:
fromAddr- from memory address (source of the reference)libraryName- name of external programextLabel- label within the external program, may be null if extAddr is not nullextAddr- memory address within the external program, may be nullsource- the source of this referenceopIndex- operand indextype- reference type - how the location is being referenced- Returns:
- new external space reference
- Throws:
InvalidInputException- iflibraryNameis invalid or null, or an invalidextlabelis specified. Names with spaces or the empty string are not permitted. NeitherextLabelnorextAddrwas specified properly.DuplicateNameException- if another non-Library namespace has the same name
-
addExternalReference
public Reference addExternalReference(Address fromAddr, Namespace extNamespace, String extLabel, Address extAddr, SourceType source, int opIndex, RefType type) throws InvalidInputException, DuplicateNameException Description copied from interface:ReferenceManagerAdds an external reference. If a reference already exists for the fromAddr and opIndex, the existing reference is replaced with the new reference.- Specified by:
addExternalReferencein interfaceReferenceManager- Parameters:
fromAddr- from memory address (source of the reference)extNamespace- external namespace containing the named external label.extLabel- label within the external program, may be null if extAddr is not nullextAddr- address within the external program, may be nullsource- the source of this referenceopIndex- operand indextype- reference type - how the location is being referenced- Returns:
- new external space reference
- Throws:
InvalidInputException- if an invalidextlabelis specified. Names with spaces or the empty string are not permitted. NeitherextLabelnorextAddrwas specified properly.DuplicateNameException- if another non-Library namespace has the same name
-
addExternalReference
public Reference addExternalReference(Address fromAddr, int opIndex, ExternalLocation location, SourceType source, RefType type) throws InvalidInputException Description copied from interface:ReferenceManagerAdds an external reference. If a reference already exists for the fromAddr and opIndex, the existing reference is replaced with the new reference.- Specified by:
addExternalReferencein interfaceReferenceManager- Parameters:
fromAddr- from memory address (source of the reference)opIndex- operand indexlocation- external locationsource- the source of this referencetype- reference type - how the location is being referenced- Returns:
- external reference
- Throws:
InvalidInputException- if the input is invalid
-
removeAllReferencesFrom
Description copied from interface:ReferenceManagerRemoves all references where "From address" is in the given range.- Specified by:
removeAllReferencesFromin interfaceReferenceManager- Parameters:
beginAddr- the first address in the range.endAddr- the last address in the range.
-
removeAllReferencesFrom
Description copied from interface:ReferenceManagerRemove all stack, external, and memory references for the given from address.- Specified by:
removeAllReferencesFromin interfaceReferenceManager- Parameters:
fromAddr- the address of the code unit from which to remove all references.
-
removeAllReferencesTo
Description copied from interface:ReferenceManagerRemove all stack, external, and memory references for the given to address.- Specified by:
removeAllReferencesToin interfaceReferenceManager- Parameters:
toAddr- the address for which all references to should be removed.
-
getReferencesTo
Description copied from interface:ReferenceManagerReturns all references to the given variable. Only data references to storage are considered.- Specified by:
getReferencesToin interfaceReferenceManager- Parameters:
var- variable to retrieve references to- Returns:
- array of variable references, or zero length array if no references exist
-
getReferencedVariable
Description copied from interface:ReferenceManagerReturns the referenced function variable.- Specified by:
getReferencedVariablein interfaceReferenceManager- Parameters:
reference- variable reference- Returns:
- function variable or null if variable not found
-
setPrimary
Description copied from interface:ReferenceManagerSet the given reference's primary attribute- Specified by:
setPrimaryin interfaceReferenceManager- Parameters:
ref- the reference to make primary.isPrimary- true to make the reference primary, false to make it non-primary
-
any
-
collect
-
hasFlowReferencesFrom
Description copied from interface:ReferenceManagerReturn whether the given address has flow references from it.- Specified by:
hasFlowReferencesFromin interfaceReferenceManager- Parameters:
addr- the address to test for flow references.- Returns:
- true if the given address has flow references from it, else false
-
getFlowReferencesFrom
Description copied from interface:ReferenceManagerGet all flow references from the given address.- Specified by:
getFlowReferencesFromin interfaceReferenceManager- Parameters:
addr- the address of the code unit to get all flows from.- Returns:
- get all flow references from the given address.
-
getExternalReferences
Description copied from interface:ReferenceManagerReturns an iterator over all external space references- Specified by:
getExternalReferencesin interfaceReferenceManager- Returns:
- reference iterator over all external space references
-
getReferencesTo
Description copied from interface:ReferenceManagerGet an iterator over all references that have the given address as their "To" address.- Specified by:
getReferencesToin interfaceReferenceManager- Parameters:
addr- the address that all references in the iterator refer to.- Returns:
- reference iterator over all references to the specified address.
-
getReferenceFromComparator
-
getReferenceIteratorForSnap
-
getReferenceIterator
Description copied from interface:ReferenceManagerGet an iterator over references starting with the specified fromAddr. A forward iterator is returned with references sorted on the from address.- Specified by:
getReferenceIteratorin interfaceReferenceManager- Parameters:
startAddr- the first from address to consider.- Returns:
- a forward memory reference iterator.
-
getReference
Description copied from interface:ReferenceManagerGet the reference that has the given from and to address, and operand index.- Specified by:
getReferencein interfaceReferenceManager- Parameters:
fromAddr- the address of the code unit making the reference.toAddr- the address being referred to.opIndex- the operand index.- Returns:
- reference which satisfies the specified criteria or null
-
getReferencesFrom
Description copied from interface:ReferenceManagerGet all references "from" the specified addr.- Specified by:
getReferencesFromin interfaceReferenceManager- Parameters:
addr- address of code-unit making the references.- Returns:
- array of all references "from" the specified addr.
-
getReferencesFrom
Description copied from interface:ReferenceManagerReturns all references "from" the given fromAddr and operand (specified by opIndex).- Specified by:
getReferencesFromin interfaceReferenceManager- Parameters:
fromAddr- the from which to get referencesopIndex- the operand from which to get references- Returns:
- all references "from" the given fromAddr and operand.
-
hasReferencesFrom
Description copied from interface:ReferenceManagerReturns true if there are any memory references at the given address/opIndex. Keep in mind this is a rather inefficient method as it must examine all references from the specified fromAddr.- Specified by:
hasReferencesFromin interfaceReferenceManager- Parameters:
fromAddr- the address of the code unit being testedopIndex- the index of the operand being tested.- Returns:
- true if one or more reference from the specified address and opindex are defined, else false
-
hasReferencesFrom
Description copied from interface:ReferenceManagerReturns true if there are any memory references at the given address.- Specified by:
hasReferencesFromin interfaceReferenceManager- Parameters:
fromAddr- the address of the code unit being tested- Returns:
- true if one or more reference from the specified address are defined, else false
-
getPrimaryReferenceFrom
Description copied from interface:ReferenceManagerGet the primary reference from the given address.- Specified by:
getPrimaryReferenceFromin interfaceReferenceManager- Parameters:
addr- from addressopIndex- operand index- Returns:
- the primary reference from the specified address and opindex if it exists, else null
-
getReferenceSourceIterator
Description copied from interface:ReferenceManagerReturns an iterator over addresses that are the "From" address in a reference- Specified by:
getReferenceSourceIteratorin interfaceReferenceManager- Parameters:
startAddr- address to position iterator.forward- true means to iterate in the forward direction- Returns:
- address iterator where references from exist
-
getReferenceSourceIterator
Description copied from interface:ReferenceManagerReturns an iterator over all addresses that are the "From" address in a reference, restricted by the given address set.- Specified by:
getReferenceSourceIteratorin interfaceReferenceManager- Parameters:
addrSet- the set of address to restrict the iterator or null for all addresses.forward- true means to iterate in the forward direction address iterator where references from exist- Returns:
- address iterator where references from exist constrained by addrSet
-
getReferenceDestinationIterator
Description copied from interface:ReferenceManagerReturns an iterator over all addresses that are the "To" address in a reference.- Specified by:
getReferenceDestinationIteratorin interfaceReferenceManager- Parameters:
startAddr- start of iteratorforward- true means to iterate in the forward direction address iterator where references to exist- Returns:
- address iterator where references to exist
-
getReferenceDestinationIterator
Description copied from interface:ReferenceManagerReturns an iterator over all addresses that are the "To" address in a memory reference, restricted by the given address set.- Specified by:
getReferenceDestinationIteratorin interfaceReferenceManager- Parameters:
addrSet- the set of address to restrict the iterator or null for all addresses.forward- true means to iterate in the forward direction- Returns:
- address iterator where references to exist constrained by addrSet
-
getReferenceCountTo
Description copied from interface:ReferenceManagerReturns the number of references to the specifiedtoAddr.- Specified by:
getReferenceCountToin interfaceReferenceManager- Parameters:
toAddr- the address being referenced- Returns:
- the number of references to the specified
toAddr.
-
getReferenceCountFrom
Description copied from interface:ReferenceManagerReturns the number of references from the specifiedfromAddr.- Specified by:
getReferenceCountFromin interfaceReferenceManager- Parameters:
fromAddr- the address of the code unit making the reference.- Returns:
- the number of references from the specified
fromAddr.
-
getReferenceDestinationCount
public int getReferenceDestinationCount()Description copied from interface:ReferenceManagerReturn the number of references for "to" addresses.- Specified by:
getReferenceDestinationCountin interfaceReferenceManager- Returns:
- the number of references for "to" addresses.
-
getReferenceSourceCount
public int getReferenceSourceCount()Description copied from interface:ReferenceManagerReturn the number of references for "from" addresses.- Specified by:
getReferenceSourceCountin interfaceReferenceManager- Returns:
- the number of references for "from" addresses.
-
hasReferencesTo
Description copied from interface:ReferenceManagerReturn true if a memory reference exists with the given "to" address.- Specified by:
hasReferencesToin interfaceReferenceManager- Parameters:
toAddr- address being referred to.- Returns:
- true if specified toAddr has one or more references to it, else false.
-
updateRefType
Description copied from interface:ReferenceManagerUpdate the reference type on a memory reference.- Specified by:
updateRefTypein interfaceReferenceManager- Parameters:
ref- reference to be updatedrefType- new reference type- Returns:
- updated reference
-
setAssociation
Description copied from interface:ReferenceManagerAssociates the given reference with the given symbol. Applies to memory references only where a specified label symbol must have an address which matches the reference to-address. Stack and register reference associations to variable symbols are always inferred.- Specified by:
setAssociationin interfaceReferenceManager- Parameters:
s- the symbol to associate with the given reference.ref- the reference to associate with the given symbol
-
removeAssociation
Description copied from interface:ReferenceManagerRemoves any symbol associations with the given reference.- Specified by:
removeAssociationin interfaceReferenceManager- Parameters:
ref- the reference for which any symbol association is to be removed.
-
delete
Description copied from interface:ReferenceManagerDeletes the given reference object- Specified by:
deletein interfaceReferenceManager- Parameters:
ref- the reference to be deleted.
-
getRefLevel
Get the reference level for a given reference typeTODO: Why is this not a property of
RefType, or a static method ofSymbolUtilities?Note that this was copy-pasted from
BigRefListV0, and there's an exact copy also inRefListV0.- Parameters:
rt- the reference type- Returns:
- the reference level
-
getReferenceLevel
Returns the reference level for the references to the given addressTo clarify, "reference level" is a sort of priority assigned to each reference type. See, e.g.,
SymbolUtilities.SUB_LEVEL. Each is a byte constant, and greater values imply higher priority. This method returns the highest priority of any reference to the given address.TODO: Track this in the database?
- Specified by:
getReferenceLevelin interfaceReferenceManager- Parameters:
toAddr- the address at which to find the highest reference level- Returns:
- reference level for specified to address.
-