Skip to main content

Overview

The FunctionManager interface provides methods for creating, retrieving, and managing functions within a Ghidra program. It handles function creation, deletion, iteration, and querying.

Interface

Package: ghidra.program.model.listing
Location: Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/FunctionManager.java

Basic Methods

getProgram()

Returns this manager’s program.
Returns: The program associated with this manager

getFunctionCount()

Returns the total number of functions in the program, including external functions.
Returns: The total count of functions

Function Creation

createFunction() - Basic

Creates a function with the given body at entry point within the global namespace.
Parameters:
  • name - The name of the new function or null for default name
  • entryPoint - Entry point of the function
  • body - Addresses contained in the function body
  • source - The source of this function (e.g., SourceType.USER_DEFINED, SourceType.ANALYSIS)
Returns: New function or null if functions overlap the specified body address set Throws:
  • InvalidInputException - If the name has invalid characters
  • OverlappingFunctionException - If the address set overlaps an existing function

createFunction() - With Namespace

Creates a function with the given body at entry point in a specific namespace.
Parameters:
  • name - The name of the new function or null for default name
  • nameSpace - The namespace in which to create the function
  • entryPoint - Entry point of the function
  • body - Addresses contained in the function body
  • source - The source of this function
Returns: New function or null if functions overlap Throws:
  • InvalidInputException - If the name has invalid characters
  • OverlappingFunctionException - If the address set overlaps an existing function

createThunkFunction()

Creates a thunk function with the given body at entry point.
Parameters:
  • name - The name of the new function or null for default name
  • nameSpace - The namespace in which to create the function
  • entryPoint - Entry point of the function
  • body - Addresses contained in the function body
  • thunkedFunction - Referenced function (required when creating a thunk)
  • source - The source of this function
Returns: New thunk function Throws:
  • OverlappingFunctionException - If the address set overlaps an existing function
  • UnsupportedOperationException - If invoked on an external entryPoint address

Function Deletion

removeFunction()

Removes the function defined at the specified entry point.
Parameters:
  • entryPoint - The entry point of the function to remove
Returns: true if the function was removed

Function Retrieval

getFunctionAt()

Returns the function at the specified entry point.
Parameters:
  • entryPoint - The entry point address
Returns: Function at the entry point or null if none exists

getReferencedFunction()

Returns the function which resides at or is referenced from the specified address.
Parameters:
  • address - Function address or address of pointer to a function
Returns: Referenced function or null

getFunctionContaining()

Returns the function containing the specified address.
Parameters:
  • addr - Address within the function
Returns: Function containing this address, or null

getFunction()

Returns a function by its unique key.
Parameters:
  • key - Function symbol key
Returns: Function object or null if not found

Function Iteration

getFunctions() - All Functions

Returns an iterator over all non-external functions in address (entry point) order.
Parameters:
  • forward - true to iterate in ascending address order
Returns: Function iterator

getFunctions() - Starting at Address

Returns an iterator over non-external functions starting at an address.
Parameters:
  • start - Starting address
  • forward - true to iterate in ascending address order
Returns: Function iterator

getFunctions() - Address Set

Returns an iterator over functions with entry points in the specified address set.
Parameters:
  • asv - Address set to iterate over
  • forward - true to iterate in ascending address order
Returns: Function iterator

getFunctionsNoStubs()

Returns an iterator over REAL functions (functions with instructions, not stubs).
Parameters:
  • forward - true to iterate in ascending address order
Returns: Function iterator excluding stubs

getFunctionsNoStubs() - Starting at Address

Returns an iterator over REAL functions starting at an address.
Parameters:
  • start - Starting address
  • forward - true to iterate in ascending address order
Returns: Function iterator excluding stubs

getFunctionsNoStubs() - Address Set

Returns an iterator over REAL functions in the specified address set.
Parameters:
  • asv - Address set to iterate over
  • forward - true to iterate in ascending address order
Returns: Function iterator excluding stubs

getExternalFunctions()

Returns an iterator over all external functions.
Returns: Iterator over external functions (no particular order)

getFunctionsOverlapping()

Returns an iterator over functions that overlap the given address set.
Parameters:
  • set - Address set of interest
Returns: Iterator over overlapping functions

Query Methods

isInFunction()

Checks if an address is contained within a function.
Parameters:
  • addr - Address to check
Returns: true if the address is contained in a function

Calling Convention Methods

getCallingConventionNames()

Returns the ordered list of defined calling convention names.
Returns: Collection of calling convention names
The reserved names “unknown” and “default” are not included. This set is limited to those defined by the compiler specification.

getDefaultCallingConvention()

Returns the default calling convention’s prototype model.
Returns: The default calling convention prototype model or null

getCallingConvention()

Returns the prototype model of the specified calling convention.
Parameters:
  • name - The calling convention name
Returns: The named function calling convention prototype model or null

Variable Methods

getReferencedVariable()

Determines which local function variable is referenced by a specific reference.
Parameters:
  • instrAddr - The instruction address
  • storageAddr - The storage address
  • size - Varnode size in bytes (1 is assumed if value is less than or equal to 0)
  • isRead - true if the reference is a read reference
Returns: Referenced variable or null if not found

Tag Management

getFunctionTagManager()

Returns the function tag manager.
Returns: The function tag manager

Usage Examples

Creating a Function

Iterating Over Functions

Finding Functions

Working with Calling Conventions

See Also