Package ghidra.program.model.symbol
Interface SymbolTable
-
- All Known Implementing Classes:
SymbolManager
public interface SymbolTable
A SymbolTable manages the Symbols defined in a program.
A Symbol is an association between an Address, a String name. In addition, symbols may have one or more References.
A Reference is a 4-tuple of a source address, destination address, type, and either a mnemonic or operand index
Any address in a program can have more than one symbol associated to it. At any given time, one and only one symbol will be designated as the primary.
A symbol can be either global or local. Local symbols belong to some namespace other than the global namespace.
Label and Function symbols do not have to have unique names with a namespace. All other symbols must be unique within a namespace and be unique with all other symbols that must be unique. In other words you can have a several functions named "foo" and several labels named "foo" in the same namespace. But you can't have a class named "foo" and a namespace named "foo". But you can have a class named "foo" and and many functions and labels named "foo" all in the same namespace.
A symbol can also be designated as dynamic. Which means the name is generated on-the-fly by the system based on its context.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description void
addExternalEntryPoint(Address addr)
Sets the given address to be an external entry point.GhidraClass
createClass(Namespace parent, java.lang.String name, SourceType source)
Create a class namespace in the given parent namespace.Library
createExternalLibrary(java.lang.String name, SourceType source)
Creates a Library namespace with the given name.Symbol
createLabel(Address addr, java.lang.String name, Namespace namespace, SourceType source)
Create a label symbol with the given name associated to the given Address and namespace.Symbol
createLabel(Address addr, java.lang.String name, SourceType source)
Create a label symbol with the given name associated to the given Address.Namespace
createNameSpace(Namespace parent, java.lang.String name, SourceType source)
Creates a new namespace.Symbol
createSymbol(Address addr, java.lang.String name, Namespace namespace, SourceType source)
Deprecated.usecreateLabel(Address, String, Namespace, SourceType)
instead.Symbol
createSymbol(Address addr, java.lang.String name, SourceType source)
Deprecated.usecreateLabel(Address, String, SourceType)
instead.SymbolIterator
getAllSymbols(boolean includeDynamicSymbols)
Returns an iterator over all symbols, including Dynamic symbols if includeDynamicSymbols is true.SymbolIterator
getChildren(Symbol parentSymbol)
Returns an iterator over all symbols that have the given symbol as its parent..java.util.Iterator<GhidraClass>
getClassNamespaces()
Returns all Class Namespaces defined within the program.Symbol
getClassSymbol(java.lang.String name, Namespace namespace)
Returns the class symbol with the given name in the given namespace.SymbolIterator
getDefinedSymbols()
Returns an iterator over all defined symbols in no particular order.long
getDynamicSymbolID(Address addr)
Get the unique symbol ID for a dynamic symbol associated with the speified addr.AddressIterator
getExternalEntryPointIterator()
Get forward/back iterator over addresses that are entry points.Symbol
getExternalSymbol(java.lang.String name)
Returns the external symbol with the given name.SymbolIterator
getExternalSymbols()
Returns an iterator over all defined external symbols in no particular order.SymbolIterator
getExternalSymbols(java.lang.String name)
Returns all the external symbols with the given name.Symbol
getGlobalSymbol(java.lang.String name, Address addr)
Get the global symbol with the given name and address.java.util.List<Symbol>
getGlobalSymbols(java.lang.String name)
Returns a list of all global symbols with the given name.java.util.Iterator<LabelHistory>
getLabelHistory()
Get an iterator over all the label history objects.LabelHistory[]
getLabelHistory(Address addr)
Get the label history objects for the given address.java.util.List<Symbol>
getLabelOrFunctionSymbols(java.lang.String name, Namespace namespace)
Returns all the label or function symbols that have the given name in the given namespace.Symbol
getLibrarySymbol(java.lang.String name)
Returns the library symbol with the given name.Symbol
getLocalVariableSymbol(java.lang.String name, Namespace namespace)
Returns the local variable symbol with the given name in the given namespace.Namespace
getNamespace(Address addr)
Returns the lowest level Namespace within which the specified address is contained.Namespace
getNamespace(java.lang.String name, Namespace namespace)
Returns the namespace with the given name in the given parent namespace.Symbol
getNamespaceSymbol(java.lang.String name, Namespace namespace)
Returns a generic namespace symbol with the given name in the given namespace.int
getNumSymbols()
Returns the total number of symbols in the table.Symbol
getParameterSymbol(java.lang.String name, Namespace namespace)
Returns the parameter symbol with the given name in the given namespace.Symbol
getPrimarySymbol(Address addr)
Returns the primary symbol at the specified address.SymbolIterator
getPrimarySymbolIterator(boolean forward)
Get iterator over all primary symbols.SymbolIterator
getPrimarySymbolIterator(Address startAddr, boolean forward)
Get iterator over only primary symbols starting at the specifiedstartAddr
SymbolIterator
getPrimarySymbolIterator(AddressSetView asv, boolean forward)
Get an iterator over symbols at addresses in the given addressSetSymbol
getSymbol(long symbolID)
Get the symbol for the given symbol ID.Symbol
getSymbol(Reference ref)
Returns the symbol that this reference is associated with.Symbol
getSymbol(java.lang.String name)
Deprecated.UsegetGlobalSymbols(String)
instead.Symbol
getSymbol(java.lang.String name, Address addr, Namespace namespace)
Get the symbol with the given name, address, and namespace.Symbol
getSymbol(java.lang.String name, Namespace namespace)
Deprecated.This method is no longer useful as Ghidra allows duplicate symbol names in the same namespace.SymbolIterator
getSymbolIterator()
Get iterator over all label symbols.SymbolIterator
getSymbolIterator(boolean forward)
Returns an iterator over all symbols.SymbolIterator
getSymbolIterator(Address startAddr, boolean forward)
Get iterator over all symbols starting at the specifiedstartAddr
SymbolIterator
getSymbolIterator(java.lang.String searchStr, boolean caseSensitive)
Returns a an iterator over all symbols that match the given search string.SymbolIterator
getSymbols(long namespaceID)
Returns an iterator over all the symbols in the given namespaceSymbol[]
getSymbols(Address addr)
Returns all the symbols at the given address.SymbolIterator
getSymbols(AddressSetView set, SymbolType type, boolean forward)
Returns all the symbols of the given type within the given address set.SymbolIterator
getSymbols(Namespace namespace)
Returns an iterator over all the symbols in the given namespaceSymbolIterator
getSymbols(java.lang.String name)
Returns all the symbols with the given name.java.util.List<Symbol>
getSymbols(java.lang.String name, Namespace namespace)
Returns a list of all symbols with the given name in the given namespace.Symbol[]
getUserSymbols(Address addr)
Returns an array of all user defined symbols at the given addressSymbol
getVariableSymbol(java.lang.String name, Function function)
Returns a symbol that is either a parameter or local variable.boolean
hasLabelHistory(Address addr)
Return true if there is a history of label changes at the given address.boolean
hasSymbol(Address addr)
Return true if there exists a symbol at the given address.boolean
isExternalEntryPoint(Address addr)
Returns true if the given address has been set as an external entry point.void
removeExternalEntryPoint(Address addr)
Removes the given address as an external entry point.boolean
removeSymbolSpecial(Symbol sym)
Removes the specified symbol from the symbol table.
-
-
-
Method Detail
-
createLabel
Symbol createLabel(Address addr, java.lang.String name, SourceType source) throws InvalidInputException
Create a label symbol with the given name associated to the given Address. The symbol will be global and be of type SymbolType.CODE. Label Symbols do not have to have unique names. If this is the first symbol defined for the address it becomes the primary.- Parameters:
addr
- the address at which to create a symbolname
- the name of the symbol.source
- the source of this symbol
Some symbol types, such as function symbols, can set the source to Symbol.DEFAULT.- Throws:
InvalidInputException
- thrown if names contains white space, is zero length, or is null. Also thrown if invalid parentNamespace is specified.java.lang.IllegalArgumentException
- if you try to set the source to DEFAULT for a symbol type that doesn't allow it, or an improper addr if specified
-
createSymbol
@Deprecated Symbol createSymbol(Address addr, java.lang.String name, SourceType source) throws InvalidInputException
Deprecated.usecreateLabel(Address, String, SourceType)
instead. Deprecated in version 7.5, will be removed a few versions later.- Throws:
InvalidInputException
-
createLabel
Symbol createLabel(Address addr, java.lang.String name, Namespace namespace, SourceType source) throws InvalidInputException
Create a label symbol with the given name associated to the given Address and namespace. The symbol will be of type SymbolType.CODE. If this is the first symbol defined for the address it becomes the primary symbol. If a symbol with that name already exists at the address, it will be returned instead with its namespace changed to the new namespace unless the new symbol is in the global space, in which case the namespace will remain as is.- Parameters:
addr
- the address at which to create a symbolname
- the name of the symbol.namespace
- the namespace of the symbol.source
- the source of this symbol
Some symbol types, such as function symbols, can set the source to Symbol.DEFAULT.- Throws:
java.lang.IllegalArgumentException
- if you try to set the source to DEFAULT for a symbol type that doesn't allow it, or an improper addr if specifiedInvalidInputException
-
createSymbol
@Deprecated Symbol createSymbol(Address addr, java.lang.String name, Namespace namespace, SourceType source) throws DuplicateNameException, InvalidInputException
Deprecated.usecreateLabel(Address, String, Namespace, SourceType)
instead. Deprecated in version 7.5, will be removed a few versions later.
-
removeSymbolSpecial
boolean removeSymbolSpecial(Symbol sym)
Removes the specified symbol from the symbol table. If removing any non-function symbol the behavior will be the same as invokingSymbol.delete()
on the symbol. Use of this method for non-function symbols is discouraged.WARNING! If removing a function symbol the behavior differs from directly invoking
Symbol.delete()
on the function symbol.When removing a function symbol this method has the following behavior:
- If the function is a default symbol (e.g., FUN_12345678) this method has no affect and will return null
- otherwise if another label exists at the function entry point, that label will be removed and the function will be renamed with that labels name
- If no other labels exist at the function entry, the function will be renamed to the default function name
- Parameters:
sym
- the symbol to be removed.- Returns:
- false, if removal of the symbol fails
-
getSymbol
Symbol getSymbol(long symbolID)
Get the symbol for the given symbol ID.- Parameters:
symbolID
- the id of the symbol to be retrieved.- Returns:
- null if there is no symbol with the given ID.
-
getSymbol
Symbol getSymbol(java.lang.String name, Address addr, Namespace namespace)
Get the symbol with the given name, address, and namespace.Note that for a symbol to be uniquely specified, all these parameters are required. Any method that queries for symbols using just one or two of these parameters will return a list of symbols.
- Parameters:
name
- the name of the symbol to retrieveaddr
- the address of the symbol to retrievenamespace
- the namespace of the symbol to retrieve. May be null which indicates global namespace.
-
getGlobalSymbol
Symbol getGlobalSymbol(java.lang.String name, Address addr)
Get the global symbol with the given name and address. Note that this results in a single Symbol because of an additional restriction that allows only one symbol with a given name at the same address and namespace (in this case the global namespace).This is just a convenience method for
getSymbol(String, Address, Namespace)
where the namespace is the global namespace.- Parameters:
name
- the name of the symbol to retrieveaddr
- the address of the symbol to retrieve
-
getSymbol
@Deprecated Symbol getSymbol(java.lang.String name, Namespace namespace)
Deprecated.This method is no longer useful as Ghidra allows duplicate symbol names in the same namespace. Use#getSymbols(Namespace, String)
instead. Deprecated in version 7.5, will be removed a few versions later.Returns the first symbol with the given name found in the given namespace. Ghidra now allows multiple symbols with the same name in the same namespace, so using this method is likely to produce unintended results. Use#getSymbols(Namespace, String)
instead.- Parameters:
name
- the name of the symbol to retreivenamespace
- the namespace of the symbol to retrieve (null assumes global namespace)
-
getSymbol
@Deprecated Symbol getSymbol(java.lang.String name)
Deprecated.UsegetGlobalSymbols(String)
instead. Ghidra now allows multiple symbols in any namespace to have the same name. Deprecated in Ghidra 7.5 Deprecated in version 7.5, will be removed a few versions later.Returns the first global symbol that it finds with the given name. Now that Ghidra allows duplicate symbol names, this method is practically useless.- Parameters:
name
- the name of the symbol to be retrieved.- Returns:
- symbol, or null if no global symbol has that name
-
getGlobalSymbols
java.util.List<Symbol> getGlobalSymbols(java.lang.String name)
Returns a list of all global symbols with the given name.- Parameters:
name
- the name of the symbols to retrieve.- Returns:
- a list of all global symbols with the given name.
-
getLabelOrFunctionSymbols
java.util.List<Symbol> getLabelOrFunctionSymbols(java.lang.String name, Namespace namespace)
Returns all the label or function symbols that have the given name in the given namespace.- Parameters:
name
- the name of the symbols to search for.namespace
- the namespace to search. If null, then the global namespace is assumed.- Returns:
- a list of all the label or function symbols with the given name in the given namespace.
- Throws:
DuplicateNameException
- if more than one label or function symbol has the name in the given namespace.
-
getNamespaceSymbol
Symbol getNamespaceSymbol(java.lang.String name, Namespace namespace)
Returns a generic namespace symbol with the given name in the given namespace.- Parameters:
name
- the name of the namespace symbol to retrieve.namespace
- the namespace containing the symbol to retrieve.- Returns:
- a generic namespace symbol with the given name in the given namespace.
-
getLibrarySymbol
Symbol getLibrarySymbol(java.lang.String name)
Returns the library symbol with the given name.- Parameters:
name
- the name of the library symbol to retrieve.- Returns:
- the library symbol with the given name.
-
getClassSymbol
Symbol getClassSymbol(java.lang.String name, Namespace namespace)
Returns the class symbol with the given name in the given namespace.- Parameters:
name
- the name of the class.namespace
- the namespace to search for the class.- Returns:
- the class symbol with the given name in the given namespace.
-
getParameterSymbol
Symbol getParameterSymbol(java.lang.String name, Namespace namespace)
Returns the parameter symbol with the given name in the given namespace.- Parameters:
name
- the name of the parameter.namespace
- the namespace (function) to search for the class.- Returns:
- the parameter symbol with the given name in the given namespace.
-
getLocalVariableSymbol
Symbol getLocalVariableSymbol(java.lang.String name, Namespace namespace)
Returns the local variable symbol with the given name in the given namespace.- Parameters:
name
- the name of the local variable.namespace
- the namespace (function) to search for the class.- Returns:
- the local variable symbol with the given name in the given namespace.
-
getSymbols
java.util.List<Symbol> getSymbols(java.lang.String name, Namespace namespace)
Returns a list of all symbols with the given name in the given namespace.- Parameters:
name
- the name of the symbols to retrieve.namespace
- the namespace to search for symbols.- Returns:
-
getVariableSymbol
Symbol getVariableSymbol(java.lang.String name, Function function)
Returns a symbol that is either a parameter or local variable. There can be only one because these symbol types have a unique name requirement.- Parameters:
name
- the naem of the variable.namespace
- the namespace (function) to search.- Returns:
- a parameter or local variable symbol with the given name.
-
getNamespace
Namespace getNamespace(java.lang.String name, Namespace namespace)
Returns the namespace with the given name in the given parent namespace. The namespace returned can be either a generic namespace or a class or library. It does not include functions.- Parameters:
name
- the name of the namespace to be retrieved.namespace
- the parent namespace of the namespace to be retrieved.- Returns:
- the namespace with the given name in the given parent namespace.
-
getSymbols
SymbolIterator getSymbols(java.lang.String name)
Returns all the symbols with the given name.- Parameters:
name
- the name of symbols to search for.- Returns:
- array of symbols with the given name
-
getAllSymbols
SymbolIterator getAllSymbols(boolean includeDynamicSymbols)
Returns an iterator over all symbols, including Dynamic symbols if includeDynamicSymbols is true.- Parameters:
includeDynamicSymbols
- if true, the iterator will include dynamicSymbols
-
getSymbol
Symbol getSymbol(Reference ref)
Returns the symbol that this reference is associated with.- Parameters:
ref
- the reference to find the associated symbol for.
-
getPrimarySymbol
Symbol getPrimarySymbol(Address addr)
Returns the primary symbol at the specified address. This method will always return null if the address specified is neither a Memory address nor an External address.- Parameters:
addr
- the address at which to retrieve the primary symbol- Returns:
- symbol, or null if no symbol at that address
-
getSymbols
Symbol[] getSymbols(Address addr)
Returns all the symbols at the given address. When addr is a memory address the primary symbol will be returned in array slot 0. WARNING! Use of this method with a Variable address is highly discouraged since a single Variable address could be used multiple times by many functions.- Parameters:
addr
- the address at which to retrieve all symbols.- Returns:
- a zero-length array when no symbols are defined at address.
-
getUserSymbols
Symbol[] getUserSymbols(Address addr)
Returns an array of all user defined symbols at the given address- Parameters:
addr
- the address at which to retrieve all user defined symbols.
-
getSymbols
SymbolIterator getSymbols(Namespace namespace)
Returns an iterator over all the symbols in the given namespace- Parameters:
namespace
- the namespace to search for symbols.
-
getSymbols
SymbolIterator getSymbols(long namespaceID)
Returns an iterator over all the symbols in the given namespace- Parameters:
namespaceID
- the namespace ID to search for symbols.
-
hasSymbol
boolean hasSymbol(Address addr)
Return true if there exists a symbol at the given address.- Parameters:
addr
- address to check for an existing symbol- Returns:
- true if any symbol exists
-
getDynamicSymbolID
long getDynamicSymbolID(Address addr)
Get the unique symbol ID for a dynamic symbol associated with the speified addr. The generation of this symbol ID does not reflect the presence of a dyanmic symbol at the specified addr. This symbol ID should not be permanently stored since the encoding may change between software releases.- Parameters:
addr
- dynamic symbol address- Returns:
- unique symbol ID
-
getSymbolIterator
SymbolIterator getSymbolIterator(java.lang.String searchStr, boolean caseSensitive)
Returns a an iterator over all symbols that match the given search string. NOTE: The iterator is in the forward direction only.- Parameters:
searchStr
- the string to search for (may contain * to match any sequence or ? to match a single char)caseSensitive
- flag to determine if the search is case sensitive or not.
-
getSymbols
SymbolIterator getSymbols(AddressSetView set, SymbolType type, boolean forward)
Returns all the symbols of the given type within the given address set.- Parameters:
set
- the address set in which to look for symbols of the given typetype
- the SymbolType to look for.forward
- the direction within the addressSet to search
-
getNumSymbols
int getNumSymbols()
Returns the total number of symbols in the table.
-
getSymbolIterator
SymbolIterator getSymbolIterator()
Get iterator over all label symbols. Labels are defined on memory locations.
-
getDefinedSymbols
SymbolIterator getDefinedSymbols()
Returns an iterator over all defined symbols in no particular order.
-
getExternalSymbol
Symbol getExternalSymbol(java.lang.String name)
Returns the external symbol with the given name.- Parameters:
name
- the name of the symbol to be retrieved.- Returns:
- symbol, or null if no external symbol has that name
-
getExternalSymbols
SymbolIterator getExternalSymbols(java.lang.String name)
Returns all the external symbols with the given name.- Parameters:
name
- the name of symbols to search for.- Returns:
- array of external symbols with the given name
-
getExternalSymbols
SymbolIterator getExternalSymbols()
Returns an iterator over all defined external symbols in no particular order.
-
getSymbolIterator
SymbolIterator getSymbolIterator(boolean forward)
Returns an iterator over all symbols.- Parameters:
forward
- true means the iterator is in the forward direction
-
getSymbolIterator
SymbolIterator getSymbolIterator(Address startAddr, boolean forward)
Get iterator over all symbols starting at the specifiedstartAddr
- Parameters:
startAddr
- the address at which to begin the iteration.forward
- true means the iterator is in the forward direction
-
getPrimarySymbolIterator
SymbolIterator getPrimarySymbolIterator(boolean forward)
Get iterator over all primary symbols.- Parameters:
forward
- true means the iterator is in the forward direction
-
getPrimarySymbolIterator
SymbolIterator getPrimarySymbolIterator(Address startAddr, boolean forward)
Get iterator over only primary symbols starting at the specifiedstartAddr
- Parameters:
startAddr
- the address at which to begin the iteration.forward
- true means the iterator is in the forward direction
-
getPrimarySymbolIterator
SymbolIterator getPrimarySymbolIterator(AddressSetView asv, boolean forward)
Get an iterator over symbols at addresses in the given addressSet- Parameters:
asv
- the set of address over which to iterate symbols.forward
- true means the iterator is in the forward direction
-
addExternalEntryPoint
void addExternalEntryPoint(Address addr)
Sets the given address to be an external entry point.- Parameters:
addr
- the address to set as an external entry point.
-
removeExternalEntryPoint
void removeExternalEntryPoint(Address addr)
Removes the given address as an external entry point.- Parameters:
addr
- the address to remove as an external entry point.
-
isExternalEntryPoint
boolean isExternalEntryPoint(Address addr)
Returns true if the given address has been set as an external entry point.- Parameters:
addr
- address to test for external entry point.
-
getExternalEntryPointIterator
AddressIterator getExternalEntryPointIterator()
Get forward/back iterator over addresses that are entry points.
-
getLabelHistory
LabelHistory[] getLabelHistory(Address addr)
Get the label history objects for the given address. The history object records changes made to labels at some address.- Parameters:
addr
- address of the label change- Returns:
- array of history objects
-
getLabelHistory
java.util.Iterator<LabelHistory> getLabelHistory()
Get an iterator over all the label history objects.
-
hasLabelHistory
boolean hasLabelHistory(Address addr)
Return true if there is a history of label changes at the given address.- Parameters:
addr
- the address to check for symbol history.
-
getNamespace
Namespace getNamespace(Address addr)
Returns the lowest level Namespace within which the specified address is contained.- Parameters:
addr
- the address for which to finds its enclosing namespace.
-
getClassNamespaces
java.util.Iterator<GhidraClass> getClassNamespaces()
Returns all Class Namespaces defined within the program.
-
createClass
GhidraClass createClass(Namespace parent, java.lang.String name, SourceType source) throws DuplicateNameException, InvalidInputException
Create a class namespace in the given parent namespace.- Parameters:
parent
- parent namespacename
- name of the namespacesource
- the source of this class namespace's symbol- Returns:
- new class namespace
- Throws:
DuplicateNameException
- thrown if another non function or lable symbol exists with the given nameInvalidInputException
- throw if the name has invalid characters or is nulljava.lang.IllegalArgumentException
- if you try to set the source to 'Symbol.DEFAULT'.
-
getChildren
SymbolIterator getChildren(Symbol parentSymbol)
Returns an iterator over all symbols that have the given symbol as its parent..- Parameters:
parentSymbol
- the parent symbol
-
createExternalLibrary
Library createExternalLibrary(java.lang.String name, SourceType source) throws DuplicateNameException, InvalidInputException
Creates a Library namespace with the given name.- Parameters:
name
- the name of the new Library namespacesource
- the source of this external library's symbol- Returns:
- the new Library namespace.
- Throws:
java.lang.IllegalArgumentException
- if you try to set the source to 'Symbol.DEFAULT'.DuplicateNameException
- thrown if another non function or lable symbol exists with the given nameInvalidInputException
-
createNameSpace
Namespace createNameSpace(Namespace parent, java.lang.String name, SourceType source) throws DuplicateNameException, InvalidInputException
Creates a new namespace.- Parameters:
parent
- the parent namespace for the new namespacename
- the name of the new namespacesource
- the source of this namespace's symbol- Returns:
- the new Namespace object.
- Throws:
DuplicateNameException
- thrown if another non function or lable symbol exists with the given nameInvalidInputException
- if the name is invalid.java.lang.IllegalArgumentException
- if you try to set the source to 'Symbol.DEFAULT'.
-
-