Class FunctionUtility

java.lang.Object
ghidra.program.util.FunctionUtility

public class FunctionUtility extends Object
Utility methods for performing function related actions.
  • 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 name
      InvalidInputException - if the name or namespace from the source function is invalid
      CircularDependencyException - 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 the default conflict handler.
      Parameters:
      destinationFunction - the destination function to update
      sourceFunction - 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 update
      sourceFunction - the source function to use as a template
      applyEmptyComposites - 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 or DataTypeConflictHandler.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. See DataTypeConflictHandler 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 function
      parameters - 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

      public 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.
      Parameters:
      program1 - the first program
      program2 - the second program
      Returns:
      true if the two programs have the same processor language and compiler spec.
    • isDefaultFunctionName

      public static boolean isDefaultFunctionName(Function function)
      Determines if the indicated function has a default name.
      Parameters:
      function - the function
      Returns:
      true if the function has a default name.
    • getFunctionTitle

      public static String getFunctionTitle(Function function)
      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.