Functions
functions
Classes:
-
Functions
–Provides access to function-related operations within the IDA database.
Functions
Functions(database: Database)
Bases: DatabaseEntity
Provides access to function-related operations within the IDA database.
This class handles function discovery, analysis, manipulation, and provides access to function properties like names, signatures, basic blocks, and pseudocode.
Can be used to iterate over all functions in the opened database.
Args: database: Reference to the active IDA database.
Note: Since this class does not manage the lifetime of IDA kernel objects (func_t*), it is recommended to use these pointers within a limited scope. Obtain the pointer, perform the necessary operations, and avoid retaining references beyond the immediate context to prevent potential issues with object invalidation.
Methods:
-
create
–Creates a new function at the specified address.
-
get_all
–Retrieves all functions in the database.
-
get_at
–Retrieves the function that contains the given address.
-
get_basic_blocks
–Retrieves the basic blocks that compose the given function.
-
get_between
–Retrieves functions within the specified address range.
-
get_callees
–Gets all functions called by this function.
-
get_callers
–Gets all functions that call this function.
-
get_disassembly
–Retrieves the disassembly lines for the given function.
-
get_instructions
–Retrieves all instructions within the given function.
-
get_microcode
–Retrieves the microcode of the given function.
-
get_name
–Retrieves the function's name.
-
get_pseudocode
–Retrieves the decompiled pseudocode of the given function.
-
get_signature
–Retrieves the function's type signature.
-
remove
–Removes the function at the specified address.
-
set_name
–Renames the given function.
Attributes:
-
database
(Database
) –Get the database reference, guaranteed to be non-None when called from
-
m_database
–
database
property
database: Database
Get the database reference, guaranteed to be non-None when called from methods decorated with @check_db_open.
Returns: The active database instance.
Note: This property should only be used in methods decorated with @check_db_open, which ensures m_database is not None.
m_database
instance-attribute
m_database = database
create
create(ea: ea_t) -> bool
Creates a new function at the specified address.
Args: ea: The effective address where the function should start.
Returns: True if the function was successfully created, False otherwise.
Raises: InvalidEAError: If the effective address is invalid.
get_all
get_all() -> Iterator[func_t]
Retrieves all functions in the database.
Returns: An iterator over all functions in the database.
get_at
get_at(ea: ea_t) -> Optional[func_t]
Retrieves the function that contains the given address.
Args: ea: An effective address within the function body.
Returns: The function object containing the address, or None if no function exists at that address.
Raises: InvalidEAError: If the effective address is invalid.
get_basic_blocks
get_basic_blocks(func: func_t) -> Optional[_FlowChart]
Retrieves the basic blocks that compose the given function.
Args: func: The function instance.
Returns: An iterator over the function's basic blocks, or empty iterator if function is invalid.
get_between
get_between(
start_ea: ea_t, end_ea: ea_t
) -> Iterator[func_t]
Retrieves functions within the specified address range.
Args: start_ea: Start address of the range (inclusive). end_ea: End address of the range (exclusive).
Yields: Function objects whose start address falls within the specified range.
Raises: InvalidEAError: If the start_ea/end_ea are specified but they are not in the database range.
get_callees
get_callees(func: func_t) -> List[func_t]
Gets all functions called by this function.
Args: func: The function instance.
Returns: List of called functions.
get_callers
get_callers(func: func_t) -> List[func_t]
Gets all functions that call this function.
Args: func: The function instance.
Returns: List of calling functions.
get_disassembly
get_disassembly(
func: func_t, remove_tags: bool = True
) -> List[str]
Retrieves the disassembly lines for the given function.
Args: func: The function instance. remove_tags: If True, removes IDA color/formatting tags from the output.
Returns: A list of strings, each representing a line of disassembly. Returns empty list if function is invalid.
get_instructions
get_instructions(
func: func_t,
) -> Optional[Iterator[insn_t]]
Retrieves all instructions within the given function.
Args: func: The function instance.
Returns: An iterator over all instructions in the function, or empty iterator if function is invalid.
get_microcode
get_microcode(
func: func_t, remove_tags: bool = True
) -> List[str]
Retrieves the microcode of the given function.
Args: func: The function instance. remove_tags: If True, removes IDA color/formatting tags from the output.
Returns: A list of strings, each representing a line of microcode. Returns empty list if function is invalid or decompilation fails.
Raises: RuntimeError: If microcode generation fails for the function.
get_name
get_name(func: func_t) -> str
Retrieves the function's name.
Args: func: The function instance.
Returns: The function name as a string, or empty string if no name is set.
get_pseudocode
get_pseudocode(
func: func_t, remove_tags: bool = True
) -> List[str]
Retrieves the decompiled pseudocode of the given function.
Args: func: The function instance. remove_tags: If True, removes IDA color/formatting tags from the output.
Returns: A list of strings, each representing a line of pseudocode. Returns empty list if function is invalid or decompilation fails.
Raises: RuntimeError: If decompilation fails for the function.
get_signature
get_signature(func: func_t) -> str
Retrieves the function's type signature.
Args: func: The function instance.
Returns: The function signature as a string, or empty string if unavailable or function is invalid.
remove
remove(ea: ea_t) -> bool
Removes the function at the specified address.
Args: ea: The effective address of the function to remove.
Returns: True if the function was successfully removed, False otherwise.
Raises: InvalidEAError: If the effective address is invalid.
set_name
set_name(
func: func_t, name: str, auto_correct: bool = True
) -> bool
Renames the given function.
Args: func: The function instance. name: The new name to assign to the function. auto_correct: If True, allows IDA to replace invalid characters automatically.
Returns: True if the function was successfully renamed, False otherwise.
Raises: InvalidParameterError: If the name parameter is empty or invalid.