Package ghidra.program.util
Class FunctionUtility
java.lang.Object
ghidra.program.util.FunctionUtility
Utility methods for performing function related actions.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
applyNameAndNamespace
(Function target, Function source) Applies the name and namespace from source function to the target functionstatic void
applySignature
(Function destinationFunction, Function sourceFunction, boolean applyEmptyComposites, DataTypeConflictHandler conflictHandler) Updates the destination function so its signature will match the source function's signature as closely as possible.static String
getFunctionTitle
(Function function) Gets a title string wrapped as HTML and indicating the function's name and the program containing it.static boolean
isDefaultFunctionName
(Function function) Determines if the indicated function has a default name.static boolean
isSameLanguageAndCompilerSpec
(Program program1, Program program2) Determines whether or not the two programs are considered to have the same processor language and compiler specification.static void
setUniqueParameterNames
(Function function, List<Parameter> parameters) Changes the names of the parameters in the array to unique names that won't conflict with any other names in the function's namespace when the parameters are used to replace the existing parameters in the function.static void
updateFunction
(Function destinationFunction, Function sourceFunction) Updates the destination function so its signature will match the source function's signature as closely as possible.
-
Method Details
-
applyNameAndNamespace
public static void applyNameAndNamespace(Function target, Function source) throws DuplicateNameException, InvalidInputException, CircularDependencyException Applies the name and namespace from source function to the target function- Parameters:
target
- the function whose name is being changed.source
- the source function from which to get name and namespace. The source function can be from another program.- Throws:
DuplicateNameException
- if creating a namespace would create a invalid duplicate nameInvalidInputException
- if the name or namespace from the source function is invalidCircularDependencyException
- if this function is an ancestor of the target namespace. This probably can't happen
-
updateFunction
public static void updateFunction(Function destinationFunction, Function sourceFunction) throws InvalidInputException, DuplicateNameException, CircularDependencyException Updates the destination function so its signature will match the source function's signature as closely as possible. This method will try to create conflict names if necessary for the function and its parameters.
All datatypes will be resolved using thedefault conflict handler
.- Parameters:
destinationFunction
- the destination function to updatesourceFunction
- the source function to use as a template- Throws:
InvalidInputException
- if the function name or a variable name is invalid or if a parameter data type is not a fixed length.DuplicateNameException
- This shouldn't happen since it will try to create conflict names for the function and its variables if necessary. Otherwise, this would be because the function's name or a variable name already exists.CircularDependencyException
- if namespaces have circular references
-
applySignature
public static void applySignature(Function destinationFunction, Function sourceFunction, boolean applyEmptyComposites, DataTypeConflictHandler conflictHandler) throws InvalidInputException, DuplicateNameException, CircularDependencyException Updates the destination function so its signature will match the source function's signature as closely as possible. This method will try to create conflict names if necessary for the function and its parameters.- Parameters:
destinationFunction
- the destination function to updatesourceFunction
- the source function to use as a templateapplyEmptyComposites
- If true, applied composites will be resolved without their respective components if the type does not already exist in the destination datatype manager. If false, normal type resolution will occur.conflictHandler
- conflict handler to be used when applying datatypes to the destination program. If this value is not null orDataTypeConflictHandler.DEFAULT_HANDLER
the datatypes will be resolved prior to updating the destinationFunction. This handler will provide some control over how applied datatype are handled when they conflict with existing datatypes. SeeDataTypeConflictHandler
which provides some predefined handlers.- Throws:
InvalidInputException
- if the function name or a variable name is invalid or if a parameter data type is not a fixed length.DuplicateNameException
- This shouldn't happen since it will try to create conflict names for the function and its variables if necessary. Otherwise, this would be because the function's name or a variable name already exists.CircularDependencyException
- if namespaces have circular references
-
setUniqueParameterNames
public static void setUniqueParameterNames(Function function, List<Parameter> parameters) throws DuplicateNameException, InvalidInputException Changes the names of the parameters in the array to unique names that won't conflict with any other names in the function's namespace when the parameters are used to replace the existing parameters in the function. Appends an integer number to the base name if necessary to create a unique name in the function's namespace.- Parameters:
function
- the functionparameters
- the parameters that need names that won't conflict. These should be Impl objects and not DB objects since their names will be changed within this method.- Throws:
InvalidInputException
DuplicateNameException
-
isSameLanguageAndCompilerSpec
Determines whether or not the two programs are considered to have the same processor language and compiler specification.- Parameters:
program1
- the first programprogram2
- the second program- Returns:
- true if the two programs have the same processor language and compiler spec.
-
isDefaultFunctionName
Determines if the indicated function has a default name.- Parameters:
function
- the function- Returns:
- true if the function has a default name.
-
getFunctionTitle
Gets a title string wrapped as HTML and indicating the function's name and the program containing it.- Parameters:
function
- the function to be indicated in the title.- Returns:
- the title string as HTML.
-