Package ghidra.app.cmd.function

# Class CreateFunctionCmd

java.lang.Object
ghidra.framework.cmd.BackgroundCommand<Program>
ghidra.app.cmd.function.CreateFunctionCmd

All Implemented Interfaces:
  `Command<Program>`

public class CreateFunctionCmd extends BackgroundCommand<Program>
Command for Creating a function at an address. It will copy off the parameters used to create the function (Selection or just an address) and create the function on redo and clear on undo.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CreateFunctionCmd(Address entry)`
  Constructs a new command for creating a function that automatically computes the body of the function.
  `CreateFunctionCmd(Address entry, boolean findEntryPoint)`
  `CreateFunctionCmd(AddressSetView entries)`
  Constructs a new command for creating functions that automatically computes the body of each function.
  `CreateFunctionCmd(AddressSetView entries, boolean findEntryPoint)`
  Constructs a new command for creating functions that automatically computes the body of each function.
  `CreateFunctionCmd(AddressSetView entries, SourceType source)`
  Constructs a new command for creating functions that automatically computes the body of each function.
  `CreateFunctionCmd(String name, Address entry, AddressSetView body, SourceType source)`
  `CreateFunctionCmd(String name, Address entry, AddressSetView body, SourceType source, boolean findEntryPoint, boolean recreateFunction)`
  Constructs a new command for creating a function.
  `CreateFunctionCmd(String name, AddressSetView entries, AddressSetView body, SourceType source, boolean findEntryPoint, boolean recreateFunction)`
  Constructs a new command for creating a function.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `applyTo(Program p, TaskMonitor monitor)`
  Method called when this command is to apply changes to the given domain object.
  `static boolean`
  `fixupFunctionBody(Program program, Function func, TaskMonitor monitor)`
  Recompute function body.
  `static boolean`
  `fixupFunctionBody(Program program, Instruction start_inst, TaskMonitor monitor)`
  Recompute function body.
  `Function`
  `getFunction()`
  Returns function if create command was successful
  `static AddressSetView`
  `getFunctionBody(Program program, Address entry)`
  Find the function body by following all flows other than a call from the entry point.
  `static AddressSetView`
  `getFunctionBody(Program program, Address entry, boolean includeOtherFunctions, TaskMonitor monitor)`
  `static AddressSetView`
  `getFunctionBody(Program program, Address entry, TaskMonitor monitor)`
  `static AddressSetView`
  `getFunctionBody(TaskMonitor monitor, Program program, Address entry)`
  Find the function body by following all flows other than a call from the entry point.

  ### Methods inherited from class ghidra.framework.cmd.BackgroundCommand

  `applyTo, canCancel, dispose, getName, getStatusMsg, hasProgress, isModal, run, setStatusMsg, taskCompleted, toString`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### CreateFunctionCmd

    public CreateFunctionCmd(String name, AddressSetView entries, AddressSetView body, SourceType source, boolean findEntryPoint, boolean recreateFunction)
    Constructs a new command for creating a function. The default name for a function is the name associated with the current primary symbol which will be removed.
    Parameters:
      `name` - function name or null for default name.
      `entries` - the entry points at which to create functions.
      `body` - set of addresses to associated with the function to be created. The addresses must not already be included in the body of any existing function.
      `source` - the source of this function
      `findEntryPoint` - true if the entry point should be computed (entry could be in the middle of a function)
      `recreateFunction` - true if the function body should be recreated even if the function exists.

  - ### CreateFunctionCmd

    public CreateFunctionCmd(String name, Address entry, AddressSetView body, SourceType source, boolean findEntryPoint, boolean recreateFunction)
    Constructs a new command for creating a function. The default name for a function is the name associated with the current primary symbol which will be removed.
    Parameters:
      `name` - function name or null for default name.
      `entry` - entry point address for the function to be created.
      `body` - set of addresses to associated with the function to be created. The addresses must not already be included in the body of any existing function.
      `source` - the source of this function
      `findEntryPoint` - true if the entry point should be computed (entry could be in the middle of a function)
      `recreateFunction` - true if the function body should be recreated even if the function exists.

  - ### CreateFunctionCmd

    public CreateFunctionCmd(AddressSetView entries, boolean findEntryPoint)
    Constructs a new command for creating functions that automatically computes the body of each function.
    Parameters:
      `entries` - the entry points at which to create functions.
      `findEntryPoint` - true if entry point is unknown and should be found

  - ### CreateFunctionCmd

    public CreateFunctionCmd(AddressSetView entries)
    Constructs a new command for creating functions that automatically computes the body of each function.
    Parameters:
      `entries` - the entry points at which to create functions.

  - ### CreateFunctionCmd

    public CreateFunctionCmd(AddressSetView entries, SourceType source)
    Constructs a new command for creating functions that automatically computes the body of each function.
    Parameters:
      `entries` - the entry points at which to create functions.
      `source` - SourceType for created function

  - ### CreateFunctionCmd

    public CreateFunctionCmd(String name, Address entry, AddressSetView body, SourceType source)

  - ### CreateFunctionCmd

    public CreateFunctionCmd(Address entry)
    Constructs a new command for creating a function that automatically computes the body of the function.
    Parameters:
      `entry` - the entry point at which to create a function.

  - ### CreateFunctionCmd

    public CreateFunctionCmd(Address entry, boolean findEntryPoint)

- ## Method Details

  - ### applyTo

    public boolean applyTo(Program p, TaskMonitor monitor)
    Description copied from class: `BackgroundCommand`
    Method called when this command is to apply changes to the given domain object. A monitor is provided to display status information about the command as it executes in the background.
    Specified by:
      `applyTo` in class `BackgroundCommand<Program>`
    Parameters:
      `p` - domain object that will be affected by the command
      `monitor` - monitor to show progress of the command
    Returns:
      true if the command applied successfully

  - ### getFunction

    public Function getFunction()
    Returns function if create command was successful
    Returns:
      last new created function, null if failed

  - ### getFunctionBody

    public static AddressSetView getFunctionBody(TaskMonitor monitor, Program program, Address entry)
    Find the function body by following all flows other than a call from the entry point.
    Parameters:
      `monitor` - task monitor
      `program` - the program where the function is being created.
      `entry` - entry point to start tracing flow
    Returns:
      AddressSetView address set representing the body of the function

  - ### getFunctionBody

    public static AddressSetView getFunctionBody(Program program, Address entry)
    Find the function body by following all flows other than a call from the entry point.
    Parameters:
      `program` - the program where the function is being created.
      `entry` - entry point to start tracing flow
    Returns:
      AddressSetView address set representing the body of the function

  - ### getFunctionBody

    public static AddressSetView getFunctionBody(Program program, Address entry, TaskMonitor monitor)

  - ### getFunctionBody

    public static AddressSetView getFunctionBody(Program program, Address entry, boolean includeOtherFunctions, TaskMonitor monitor)

  - ### fixupFunctionBody

    public static boolean fixupFunctionBody(Program program, Instruction start_inst, TaskMonitor monitor) throws CancelledException
    Recompute function body. An open transaction must already exist.
    Parameters:
      `program` - the program the function is in.
      `start_inst` - instruction that is within the function to be fixed up.
      `monitor` - task monitor
    Returns:
      true if successful, false if cancelled or unable to fixup function or no function found containing the start address of the indicated instruction
    Throws:
      `CancelledException` - if the function fixup is cancelled.

  - ### fixupFunctionBody

    public static boolean fixupFunctionBody(Program program, Function func, TaskMonitor monitor) throws CancelledException
    Recompute function body. An open transaction must already exist.
    Parameters:
      `program` - the program the function is in.
      `func` - the function to be fixed up. A null function will return false.
      `monitor` - task monitor
    Returns:
      true if successful, false if unable to fixup function or no function found containing the start address of the indicated instruction
    Throws:
      `CancelledException` - if the function fixup is cancelled.