Package ghidra.program.database.symbol
Class SymbolDB
java.lang.Object
ghidra.program.database.DatabaseObject
ghidra.program.database.symbol.SymbolDB
- All Implemented Interfaces:
Symbol
- Direct Known Subclasses:
ClassSymbol
,CodeSymbol
,FunctionSymbol
,LibrarySymbol
,NamespaceSymbol
,VariableSymbolDB
Base class for symbols
-
Field Summary
Fields inherited from class ghidra.program.database.DatabaseObject
key
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
Checks if this object has been deleted, in which case any use of the object is not allowed.boolean
delete()
Delete the symbol and its associated resources.protected boolean
protected String
The code for creating the name content for this symbol.protected Namespace
protected boolean
void
doSetNameAndNamespace
(String newName, Namespace newNamespace, SourceType source, boolean checkForDuplicates) protected void
doSetPinned
(boolean pinned) protected void
doSetPrimary
(boolean primary) boolean
long
long
getID()
final String
getName()
getName
(boolean includeNamespace) Returns the symbol name, optionally prepended with the namespace path.Return the parent namespace for this symbol.Returns namespace symbol of the namespace containing this symbolString[]
getPath()
Gets the full path name for this symbol as an ordered array of strings ending with the symbol name.Get the program associated with this symbolint
Returns all memory references to the address of this symbol.getReferences
(TaskMonitor monitor) Returns all memory references to the address of this symbol.Gets the source of this symbol.Returns the symbol's string data which has different meanings depending on the symbol type and whether or not it is externalprotected int
gets the generic symbol data 2 data.int
hashCode()
boolean
boolean
boolean
Determine if this symbol object has been deleted.boolean
boolean
isDescendant
(Namespace namespace) Returns true if the given namespace symbol is a descendant of this symbol.boolean
boolean
boolean
isGlobal()
boolean
isPinned()
Returns true if the symbol is pinned to its current address.abstract boolean
boolean
isValidParent
(Namespace parent) Determines if the given parent is valid for this Symbol.protected void
moveLowLevel
(Address newAddress, String newName, Namespace newNamespace, SourceType newSource, boolean pinned) low level record adjustment to move a symbol.protected boolean
refresh()
Tells the object to refresh its state from the database.protected boolean
Tells the object to refresh its state from the database using the specified record if not null.protected void
setAddress
(Address addr) void
setDataTypeId
(long value) Sets the generic symbol data 1.void
setName
(String newName, SourceType source) Sets the name this symbol.void
setNameAndNamespace
(String newName, Namespace newNamespace, SourceType source) Sets the symbols name and namespace.void
setNamespace
(Namespace newNamespace) Sets the symbols namespacevoid
setPinned
(boolean pinned) Sets whether or not this symbol is pinned to its associated address.boolean
Sets this symbol to be primary.void
setSource
(SourceType newSource) Sets this symbol's source as specified.void
setSymbolStringData
(String stringData) Sets the symbol's string data field.void
setVariableOffset
(int offset) Sets the symbol's variable offset.toString()
protected SourceType
validateNameSource
(String newName, SourceType source) Allow symbol implementations to validate the source when setting the name of this symbolMethods inherited from class ghidra.program.database.DatabaseObject
checkIsValid, checkIsValid, getKey, isDeleted, isInvalid, keyChanged, setDeleted, setInvalid, validate
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ghidra.program.model.symbol.Symbol
getObject, getProgramLocation, getSymbolType, isExternal
-
Field Details
-
address
-
symbolMgr
-
lock
-
-
Method Details
-
isDeleted
public boolean isDeleted()Description copied from interface:Symbol
Determine if this symbol object has been deleted. NOTE: the symbol could be deleted at anytime due to asynchronous activity. -
checkDeleted
protected void checkDeleted()Description copied from class:DatabaseObject
Checks if this object has been deleted, in which case any use of the object is not allowed. This method should be invoked before any modifications to the object are performed to ensure it still exists and is in a valid state.- Overrides:
checkDeleted
in classDatabaseObject
-
toString
-
refresh
protected boolean refresh()Description copied from class:DatabaseObject
Tells the object to refresh its state from the database.- Specified by:
refresh
in classDatabaseObject
- Returns:
- true if the object was able to refresh itself. Return false if the object was deleted. Objects that extend this class must implement a refresh method. If an object can never refresh itself, then it should always return false.
-
refresh
Description copied from class:DatabaseObject
Tells the object to refresh its state from the database using the specified record if not null. NOTE: The default implementation ignores the record and invokes refresh(). Implementations of this method must take care if multiple database tables are used since the record supplied could correspond to another object. In some cases it may be best not to override this method or ignore the record provided.- Overrides:
refresh
in classDatabaseObject
- Parameters:
rec
- valid record associated with object's key (optional, may be null to force record lookup or other refresh technique)- Returns:
- true if the object was able to refresh itself. Return false if record is null and object was deleted. Objects that extend this class must implement a refresh method. If an object can never refresh itself, then it should always return false.
-
getAddress
- Specified by:
getAddress
in interfaceSymbol
- Returns:
- the address for the symbol.
-
setAddress
-
moveLowLevel
protected void moveLowLevel(Address newAddress, String newName, Namespace newNamespace, SourceType newSource, boolean pinned) low level record adjustment to move a symbol. Used only when moving a memory block or changing the image base.- Parameters:
newAddress
- the new address for the symbolnewName
- the new name for the symbol (or null if the name should stay the same)newNamespace
- the new namespace for the symbol (or null if it should stay the same)newSource
- the new SourceType for the symbol (or null if it should stay the same)pinned
- the new pinned state
-
getName
-
doGetName
The code for creating the name content for this symbol. This code will be called with the symbol's lock.- Returns:
- the name
-
getProgram
Description copied from interface:Symbol
Get the program associated with this symbol- Specified by:
getProgram
in interfaceSymbol
- Returns:
- the program associated with this symbol.
-
getName
Description copied from interface:Symbol
Returns the symbol name, optionally prepended with the namespace path. -
getPath
Description copied from interface:Symbol
Gets the full path name for this symbol as an ordered array of strings ending with the symbol name. The global symbol will return an empty array. -
getReferenceCount
public int getReferenceCount()- Specified by:
getReferenceCount
in interfaceSymbol
- Returns:
- the number of References to this symbol.
-
getReferences
Description copied from interface:Symbol
Returns all memory references to the address of this symbol. If you do not have aTaskMonitor
instance, then you can passTaskMonitor.DUMMY
ornull
.- Specified by:
getReferences
in interfaceSymbol
- Parameters:
monitor
- the monitor that is used to report progress and to cancel this potentially long-running call- Returns:
- all memory references to the address of this symbol.
-
getReferences
Description copied from interface:Symbol
Returns all memory references to the address of this symbol.- Specified by:
getReferences
in interfaceSymbol
- Returns:
- all memory references to the address of this symbol
- See Also:
-
hasMultipleReferences
public boolean hasMultipleReferences()- Specified by:
hasMultipleReferences
in interfaceSymbol
- Returns:
- true if this symbol has more than one reference to it.
-
hasReferences
public boolean hasReferences()- Specified by:
hasReferences
in interfaceSymbol
- Returns:
- true if this symbol has at least one reference to it.
-
isDynamic
public boolean isDynamic() -
isExternalEntryPoint
public boolean isExternalEntryPoint()- Specified by:
isExternalEntryPoint
in interfaceSymbol
- Returns:
- true if the symbol is at an address set as a external entry point.
-
isPrimary
public abstract boolean isPrimary() -
setSource
Sets this symbol's source as specified.- Specified by:
setSource
in interfaceSymbol
- Parameters:
newSource
- the new source type (IMPORTED, ANALYSIS, USER_DEFINED)- Throws:
IllegalArgumentException
- if you try to change the source from default or to default
-
getSource
Description copied from interface:Symbol
Gets the source of this symbol.SourceType
-
isPinned
public boolean isPinned()Description copied from interface:Symbol
Returns true if the symbol is pinned to its current address. If it is pinned, then moving or removing the memory associated with that address will not affect this symbol. -
doIsPinned
protected boolean doIsPinned() -
setPinned
public void setPinned(boolean pinned) Description copied from interface:Symbol
Sets whether or not this symbol is pinned to its associated address.
If the symbol is pinned then moving or removing the memory associated with its address will not cause this symbol to be removed and will not cause its address to change. If the symbol is not pinned, then removing the memory at its address will also remove this symbol.
Likewise, moving a memory block containing a symbol that is not anchored will change the address for that symbol to keep it associated with the same byte in the memory block.
-
doSetPinned
protected void doSetPinned(boolean pinned) -
setName
public void setName(String newName, SourceType source) throws DuplicateNameException, InvalidInputException Description copied from interface:Symbol
Sets the name this symbol. If this symbol is dynamic, then the name is set and the symbol is no longer dynamic.- Specified by:
setName
in interfaceSymbol
- Parameters:
newName
- the new name for this symbol.source
- the source of this symbol
Some symbol types, such as function symbols, can set the source to Symbol.DEFAULT.- Throws:
DuplicateNameException
- if name already exists as the name of another symbol or alias.InvalidInputException
- if alias contains blank characters, is zero length, or is null
-
setNamespace
public void setNamespace(Namespace newNamespace) throws DuplicateNameException, InvalidInputException, CircularDependencyException Description copied from interface:Symbol
Sets the symbols namespace- Specified by:
setNamespace
in interfaceSymbol
- Parameters:
newNamespace
- new parent namespace- Throws:
DuplicateNameException
- if newNamespace already contains a symbol with this symbol's nameInvalidInputException
- is newNamespace is not a valid parent for this symbolCircularDependencyException
- if this symbol is an ancestor of newNamespace
-
validateNameSource
Allow symbol implementations to validate the source when setting the name of this symbol- Parameters:
newName
- the new namesource
- the source type- Returns:
- the validated source type
-
doSetNameAndNamespace
public void doSetNameAndNamespace(String newName, Namespace newNamespace, SourceType source, boolean checkForDuplicates) throws DuplicateNameException, InvalidInputException, CircularDependencyException -
setNameAndNamespace
public void setNameAndNamespace(String newName, Namespace newNamespace, SourceType source) throws DuplicateNameException, InvalidInputException, CircularDependencyException Description copied from interface:Symbol
Sets the symbols name and namespace. This is provided to allow the caller to avoid a name conflict by creating an autonomous action.- Specified by:
setNameAndNamespace
in interfaceSymbol
- Parameters:
newName
- new symbol namenewNamespace
- new parent namespacesource
- the source of this symbol
Some symbol types, such as function symbols, can set the source to Symbol.DEFAULT.- Throws:
DuplicateNameException
- if newNamespace already contains a symbol with this symbol's nameInvalidInputException
- is newNamespace is not a valid parent for this symbolCircularDependencyException
- if this symbol is an ancestor of newNamespace
-
getSymbolsDynamicallyRenamedByMyRename
-
setPrimary
public boolean setPrimary()Description copied from interface:Symbol
Sets this symbol to be primary. All other symbols at the same address will be set to !primary. Only applies to non-function symbols.- Specified by:
setPrimary
in interfaceSymbol
- Returns:
- returns true if the symbol was not primary and now it is, otherwise false
- See Also:
-
getID
public long getID() -
equals
-
hashCode
public int hashCode() -
getParentNamespace
Description copied from interface:Symbol
Return the parent namespace for this symbol.- Specified by:
getParentNamespace
in interfaceSymbol
- Returns:
- the namespace that contains this symbol.
-
doGetParentNamespace
-
getParentSymbol
Description copied from interface:Symbol
Returns namespace symbol of the namespace containing this symbol- Specified by:
getParentSymbol
in interfaceSymbol
- Returns:
- parent namespace symbol
-
isGlobal
public boolean isGlobal() -
getSymbolStringData
Returns the symbol's string data which has different meanings depending on the symbol type and whether or not it is external- Returns:
- the symbol's string data
-
setSymbolStringData
Sets the symbol's string data field. This field's data has different uses depending on the symbol type and whether or not it is external.- Parameters:
stringData
- the string to store in the string data field
-
getDataTypeId
public long getDataTypeId() -
setDataTypeId
public void setDataTypeId(long value) Sets the generic symbol data 1.- Parameters:
value
- the value to set as symbol data 1.
-
getVariableOffset
protected int getVariableOffset()gets the generic symbol data 2 data.- Returns:
- the symbol data
-
setVariableOffset
public void setVariableOffset(int offset) Sets the symbol's variable offset. For parameters, this is the ordinal, for locals, it is the first use offset- Parameters:
offset
- the value to set as the symbols variable offset.
-
doSetPrimary
protected void doSetPrimary(boolean primary) -
doCheckIsPrimary
protected boolean doCheckIsPrimary() -
delete
public boolean delete()Description copied from interface:Symbol
Delete the symbol and its associated resources. Any references symbol associations will be discarded. -
isDeleting
public boolean isDeleting() -
isDescendant
Description copied from interface:Symbol
Returns true if the given namespace symbol is a descendant of this symbol.- Specified by:
isDescendant
in interfaceSymbol
- Parameters:
namespace
- to test as descendant symbol of this Symbol- Returns:
- true if this symbol is an ancestor of the given namespace symbol
-
isValidParent
Description copied from interface:Symbol
Determines if the given parent is valid for this Symbol. Specified namespace must belong to the same symbol table as this symbol.- Specified by:
isValidParent
in interfaceSymbol
- Parameters:
parent
- prospective parent namespace for this symbol- Returns:
- true if parent is valid
-