Package ghidra.program.model.symbol
Class SymbolUtilities
- java.lang.Object
- 
- ghidra.program.model.symbol.SymbolUtilities
 
- 
 public class SymbolUtilities extends java.lang.ObjectClass with static methods to deal with symbol strings.
- 
- 
Field SummaryFields Modifier and Type Field Description static intDAT_LEVELstatic intEXT_LEVELstatic intFUN_LEVELstatic char[]INVALIDCHARSInvalid characters for a symbol name.static intLAB_LEVELstatic intMAX_SYMBOL_NAME_LENGTHstatic java.lang.StringORDINAL_PREFIXThe standard prefix for denoting the ordinal values of a symbol.static intSUB_LEVELstatic intUNK_LEVEL
 - 
Constructor SummaryConstructors Constructor Description SymbolUtilities()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancontainsInvalidChars(java.lang.String str)Check for invalid characters (space, colon, asterisk, plus, bracket) in labels.static SymbolcreatePreferredLabelOrFunctionSymbol(Program program, Address address, Namespace namespace, java.lang.String name, SourceType source)Create label symbol giving preference to non-global symbols.static java.lang.StringgetAddressAppendedName(java.lang.String name, Address address)Creates the standard symbol name for symbols that have the addresses appended to the name following an "@" character in order to make it unique.static java.lang.StringgetAddressString(Address addr)static java.lang.StringgetCleanSymbolName(Symbol symbol)Gets the base symbol name regardless of whether or not the address has been appended.static java.lang.StringgetCleanSymbolName(java.lang.String symbolName, Address address)Gets the base symbol name regardless of whether or not the address has been appended using either the standard "@" separator, or the less preferred "_" separator.static java.lang.StringgetDefaultExternalFunctionName(Address addr)Generates a default external name for an external functionstatic java.lang.StringgetDefaultExternalName(Address addr, DataType dt)Generates a default external name for a given external data/code location.static java.lang.StringgetDefaultFunctionName(Address addr)Generates a default function name for a given address.static java.lang.StringgetDefaultLocalName(Program program, int stackOffset, int firstUseOffset)static java.lang.StringgetDefaultLocalName(Program program, VariableStorage storage, int firstUseOffset)static java.lang.StringgetDefaultParamName(int ordinal)static java.lang.StringgetDynamicName(int referenceLevel, Address addr)Create a name for a dynamic symbolstatic java.lang.StringgetDynamicName(Program program, Address addr)Create a name for a dynamic symbol.static java.lang.StringgetDynamicOffcutName(Address addr)Create a name for an offcut reference.static SymbolgetExpectedLabelOrFunctionSymbol(Program program, java.lang.String symbolName, java.util.function.Consumer<java.lang.String> errorConsumer)Returns the unique global label or function symbol with the given name.static SymbolgetLabelOrFunctionSymbol(Program program, java.lang.String symbolName, java.util.function.Consumer<java.lang.String> errorConsumer)Returns the unique global label or function symbol with the given name.static intgetOrdinalValue(java.lang.String symbolName)static java.util.Comparator<Symbol>getSymbolNameComparator()Returns a comparator for symbols.static java.lang.StringgetSymbolTypeDisplayName(Symbol symbol)Returns display text suitable for describing in the GUI theSymbolTypeof the given symbolstatic booleanisDefaultLocalName(Program program, java.lang.String name, VariableStorage storage)static booleanisDefaultLocalStackName(java.lang.String name)static booleanisDefaultParameterName(java.lang.String name)static booleanisDynamicSymbolPattern(java.lang.String name, boolean caseSensitive)Tests if the given name is a possible dynamic symbol name.static booleanisInvalidChar(char c)Returns true if the specified char is not valid for use in a symbol namestatic booleanisReservedDynamicLabelName(java.lang.String name, AddressFactory addrFactory)Returns true if the given name could match a default dynamic label (EXT, LAB, SUB, FUN, DAT) at some address.static booleanisReservedExternalDefaultName(java.lang.String name, AddressFactory addrFactory)Returns true if the specified name is reserved as a default external name.static AddressparseDynamicName(AddressFactory factory, java.lang.String name)Parse a dynamic name and return its address or null if unable to parse.static java.lang.StringreplaceInvalidChars(java.lang.String str, boolean replaceWithUnderscore)Removes from the given string any invalid characters or replaces them with underscores.static booleanstartsWithDefaultDynamicPrefix(java.lang.String name)Returns true if the given name starts with a possible default symbol prefix.static voidvalidateName(java.lang.String name, Address address, SymbolType symbolType, AddressFactory addrFactory)Validate the given symbol name: cannot be null, cannot be an empty string, cannot contain blank characters, cannot be a reserved name.
 
- 
- 
- 
Field Detail- 
MAX_SYMBOL_NAME_LENGTHpublic static final int MAX_SYMBOL_NAME_LENGTH - See Also:
- Constant Field Values
 
 - 
UNK_LEVELpublic static final int UNK_LEVEL - See Also:
- Constant Field Values
 
 - 
DAT_LEVELpublic static final int DAT_LEVEL - See Also:
- Constant Field Values
 
 - 
LAB_LEVELpublic static final int LAB_LEVEL - See Also:
- Constant Field Values
 
 - 
SUB_LEVELpublic static final int SUB_LEVEL - See Also:
- Constant Field Values
 
 - 
EXT_LEVELpublic static final int EXT_LEVEL - See Also:
- Constant Field Values
 
 - 
FUN_LEVELpublic static final int FUN_LEVEL - See Also:
- Constant Field Values
 
 - 
ORDINAL_PREFIXpublic static final java.lang.String ORDINAL_PREFIX The standard prefix for denoting the ordinal values of a symbol.- See Also:
- Constant Field Values
 
 - 
INVALIDCHARSpublic static final char[] INVALIDCHARS Invalid characters for a symbol name.
 
- 
 - 
Method Detail- 
getOrdinalValuepublic static int getOrdinalValue(java.lang.String symbolName) 
 - 
containsInvalidCharspublic static boolean containsInvalidChars(java.lang.String str) Check for invalid characters (space, colon, asterisk, plus, bracket) in labels.- Parameters:
- str- the string to be checked for invalid characters.
- Returns:
- boolean true if no invalid chars
 
 - 
getDefaultFunctionNamepublic static java.lang.String getDefaultFunctionName(Address addr) Generates a default function name for a given address.- Parameters:
- addr- the entry point of the function.
- Returns:
- the default generated name for the function.
 
 - 
isReservedExternalDefaultNamepublic static boolean isReservedExternalDefaultName(java.lang.String name, AddressFactory addrFactory)Returns true if the specified name is reserved as a default external name.- Parameters:
- name-
- addrFactory-
- Returns:
- true if the specified name is reserved as a default external name.
 
 - 
getDefaultExternalFunctionNamepublic static java.lang.String getDefaultExternalFunctionName(Address addr) Generates a default external name for an external function- Parameters:
- addr- the memory address referred to by the external.
- Returns:
- the default generated name for the external.
 
 - 
getDefaultExternalNamepublic static java.lang.String getDefaultExternalName(Address addr, DataType dt) Generates a default external name for a given external data/code location.- Parameters:
- addr- the memory address referred to by the external.
- dt- data type associated with the specified external memory address
- Returns:
- the default generated name for the external.
 
 - 
isReservedDynamicLabelNamepublic static boolean isReservedDynamicLabelName(java.lang.String name, AddressFactory addrFactory)Returns true if the given name could match a default dynamic label (EXT, LAB, SUB, FUN, DAT) at some address. WARNING! Does not handle dynamic labels which use data-type prefixes - seeisDynamicSymbolPattern(String, boolean)for more liberal check
 - 
validateNamepublic static void validateName(java.lang.String name, Address address, SymbolType symbolType, AddressFactory addrFactory) throws InvalidInputExceptionValidate the given symbol name: cannot be null, cannot be an empty string, cannot contain blank characters, cannot be a reserved name. NOTE: This is not infallible since default data labels can start with any data-type name- Throws:
- InvalidInputException- invalid or reserved name has been specified
 
 - 
startsWithDefaultDynamicPrefixpublic static boolean startsWithDefaultDynamicPrefix(java.lang.String name) Returns true if the given name starts with a possible default symbol prefix.- Parameters:
- name- the name string to test.
 
 - 
isDynamicSymbolPatternpublic static boolean isDynamicSymbolPattern(java.lang.String name, boolean caseSensitive)Tests if the given name is a possible dynamic symbol name. WARNING! This method should be used carefully since it will return true for any name which ends with an '_' followed by a valid hex value- Parameters:
- name- the name to test
- caseSensitive- true if case matters.
 
 - 
isInvalidCharpublic static boolean isInvalidChar(char c) Returns true if the specified char is not valid for use in a symbol name- Parameters:
- c- the character to be tested as a valid symbol character.
 
 - 
replaceInvalidCharspublic static java.lang.String replaceInvalidChars(java.lang.String str, boolean replaceWithUnderscore)Removes from the given string any invalid characters or replaces them with underscores. For example: given "a:b*c", the return value would be "a_b_c"- Parameters:
- str- the string to have invalid chars converted to underscores or removed.
- replaceWithUnderscore- - true means replace the invalid chars with underscore. if false, then just drop the invalid chars
 
 - 
getDynamicOffcutNamepublic static java.lang.String getDynamicOffcutName(Address addr) Create a name for an offcut reference.- Parameters:
- addr- the address at which to create an offcut reference name.
 
 - 
getDynamicNamepublic static java.lang.String getDynamicName(int referenceLevel, Address addr)Create a name for a dynamic symbol- Parameters:
- referenceLevel- the type of reference for which to create a dynamic name.
- addr- the address at which to create a dynamic name.
 
 - 
getDynamicNamepublic static java.lang.String getDynamicName(Program program, Address addr) Create a name for a dynamic symbol.- Parameters:
- program- the current program
- addr- the address of the symbol for which to generate a name
- Returns:
- a name for the symbol at the given address
 
 - 
parseDynamicNamepublic static Address parseDynamicName(AddressFactory factory, java.lang.String name) Parse a dynamic name and return its address or null if unable to parse.- Parameters:
- name- the dynamic label name to parse into an address.
 
 - 
getAddressStringpublic static java.lang.String getAddressString(Address addr) 
 - 
getDefaultParamNamepublic static java.lang.String getDefaultParamName(int ordinal) 
 - 
isDefaultParameterNamepublic static boolean isDefaultParameterName(java.lang.String name) 
 - 
getDefaultLocalNamepublic static java.lang.String getDefaultLocalName(Program program, int stackOffset, int firstUseOffset) 
 - 
getDefaultLocalNamepublic static java.lang.String getDefaultLocalName(Program program, VariableStorage storage, int firstUseOffset) 
 - 
isDefaultLocalNamepublic static boolean isDefaultLocalName(Program program, java.lang.String name, VariableStorage storage) 
 - 
isDefaultLocalStackNamepublic static boolean isDefaultLocalStackName(java.lang.String name) 
 - 
getAddressAppendedNamepublic static java.lang.String getAddressAppendedName(java.lang.String name, Address address)Creates the standard symbol name for symbols that have the addresses appended to the name following an "@" character in order to make it unique.- Parameters:
- name- the "true" name of the symbol
- address- the address to be appended
- Returns:
- the name with the address appended.
 
 - 
getCleanSymbolNamepublic static java.lang.String getCleanSymbolName(Symbol symbol) Gets the base symbol name regardless of whether or not the address has been appended.- Parameters:
- symbol- the symbol to get the clean name for.
- Returns:
- the base symbol name where the "@" has been stripped away if it exists.
 
 - 
getCleanSymbolNamepublic static java.lang.String getCleanSymbolName(java.lang.String symbolName, Address address)Gets the base symbol name regardless of whether or not the address has been appended using either the standard "@" separator, or the less preferred "_" separator. The address string extension must match that which is produced by thegetAddressString(Address)method for it to be recognized.- Parameters:
- symbolName- a symbol name to get the clean name for.
- address- the symbol's address
- Returns:
- the base symbol name where the "@" has been stripped away if it exists.
 
 - 
getSymbolTypeDisplayNamepublic static java.lang.String getSymbolTypeDisplayName(Symbol symbol) Returns display text suitable for describing in the GUI theSymbolTypeof the given symbol- Parameters:
- symbol- The symbol from which to get the SymbolType
- Returns:
- a display string for the SymbolType
 
 - 
getExpectedLabelOrFunctionSymbolpublic static Symbol getExpectedLabelOrFunctionSymbol(Program program, java.lang.String symbolName, java.util.function.Consumer<java.lang.String> errorConsumer) Returns the unique global label or function symbol with the given name. Also, logs if there is not exactly one symbol with that name.- Parameters:
- program- the program to search.
- symbolName- the name of the global label or function symbol to search.
- errorConsumer- the object to use for reporting errors via it's accept() method.
 
 - 
getLabelOrFunctionSymbolpublic static Symbol getLabelOrFunctionSymbol(Program program, java.lang.String symbolName, java.util.function.Consumer<java.lang.String> errorConsumer) Returns the unique global label or function symbol with the given name. Also, logs if there is more than one symbol with that name.- Parameters:
- program- the program to search.
- symbolName- the name of the global label or function symbol to search.
- errorConsumer- the object to use for reporting errors via it's accept() method.
 
 - 
createPreferredLabelOrFunctionSymbolpublic static Symbol createPreferredLabelOrFunctionSymbol(Program program, Address address, Namespace namespace, java.lang.String name, SourceType source) throws InvalidInputException Create label symbol giving preference to non-global symbols. An existing function symbol may be returned. If attempting to create a global symbol and the name already exists at the address no symbol will be created and null will be returned. If attempting to create a non-global symbol, which does not exist, and a global symbol does exist with same name its' namespace will be changed.- Parameters:
- program- program within which the symbol should be created
- address- memory address where symbol should be created
- namespace- symbol namespace or null for global
- name- symbol name
- source- symbol source type
- errorConsumer- error logging consumer
- Returns:
- new or existing label or function symbol or null if creating a global symbol whose name already exists at address
- Throws:
- InvalidInputException- if invalid symbol name provided
 
 - 
getSymbolNameComparatorpublic static java.util.Comparator<Symbol> getSymbolNameComparator() Returns a comparator for symbols. The comparison is based upon the name. This call replaces the former compareTo method on Symbol. This comparator returned here is case-insensitive.- Returns:
- the comparator
 
 
- 
 
-