Class FunctionManagerDB

  • All Implemented Interfaces:
    ManagerDB, FunctionManager

    public class FunctionManagerDB
    extends java.lang.Object
    implements ManagerDB, FunctionManager
    Class that manages all functions within the program; there are some convenience methods on Listing to create and access functions, but all function related calls are routed to this class.
    • Constructor Detail

      • FunctionManagerDB

        public FunctionManagerDB​(DBHandle dbHandle,
                                 AddressMap addrMap,
                                 int openMode,
                                 Lock lock,
                                 TaskMonitor monitor)
                          throws VersionException,
                                 CancelledException,
                                 java.io.IOException
        Construct a new FunctionManager
        Parameters:
        dbHandle - data base handle
        addrMap - address map for the program
        openMode - CREATE, UPDATE, READ_ONLY, or UPGRADE defined in db.DBConstants
        lock - the program synchronization lock
        monitor -
        Throws:
        VersionException - if function manager's version does not match its expected version
        CancelledException - if the function table is being upgraded and the user canceled the upgrade process
        java.io.IOException - if there was a problem accessing the database
    • Method Detail

      • getCallingConventionNames

        public java.util.List<java.lang.String> getCallingConventionNames()
        Description copied from interface: FunctionManager
        Gets the names associated with each of the current calling conventions associated with this program. Within the exception of "unknown", all of these calling convention names should have a PrototypeModel.
        Specified by:
        getCallingConventionNames in interface FunctionManager
        Returns:
        the calling convention names.
      • getCallingConvention

        public PrototypeModel getCallingConvention​(java.lang.String name)
        Description copied from interface: FunctionManager
        Gets the prototype model of the calling convention with the specified name in this program.
        Specified by:
        getCallingConvention in interface FunctionManager
        Returns:
        the named function calling convention prototype model or null.
      • getCallingConventions

        public PrototypeModel[] getCallingConventions()
        Description copied from interface: FunctionManager
        Gets all the calling convention prototype models in this program that have names.
        Specified by:
        getCallingConventions in interface FunctionManager
        Returns:
        the function calling convention prototype models.
      • createThunkFunction

        public Function createThunkFunction​(java.lang.String name,
                                            Namespace nameSpace,
                                            Address entryPoint,
                                            AddressSetView body,
                                            Function thunkedFunction,
                                            SourceType source)
                                     throws OverlappingFunctionException
        Description copied from interface: FunctionManager
        Create a thunk function with the given body at entry point.
        Specified by:
        createThunkFunction in interface FunctionManager
        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 function
        body - addresses contained in the function body
        thunkedFunction - referenced function (required is creating a thunk function)
        source - the source of this function
        Returns:
        new function or null if one or more functions overlap the specified body address set.
        Throws:
        OverlappingFunctionException - if the address set of the body overlaps an existing function
      • getFunctionCount

        public int getFunctionCount()
        Description copied from interface: FunctionManager
        Returns the total number of functions in the program including external functions.
        Specified by:
        getFunctionCount in interface FunctionManager
      • functionTagsChanged

        public void functionTagsChanged()
      • functionNamespaceChanged

        public void functionNamespaceChanged​(long key)
      • doRemoveFunction

        public boolean doRemoveFunction​(long key)
      • getFunction

        public Function getFunction​(long key)
        Get the function with the given key.
        Specified by:
        getFunction in interface FunctionManager
        Parameters:
        key - ID of the function; ID is obtained by calling Function.getID()
        Returns:
        null if there is no function with the given key
      • getReferencedFunction

        public Function getReferencedFunction​(Address address)
        Description copied from interface: FunctionManager
        Get the function which resides at the specified address or is referenced from the specified address.
        Specified by:
        getReferencedFunction in interface FunctionManager
        Parameters:
        address - function address or address of pointer to a function.
        Returns:
        referenced function or null
      • getFunctionContaining

        public Function getFunctionContaining​(Address addr)
        Description copied from interface: FunctionManager
        Get a function containing an address.
        Specified by:
        getFunctionContaining in interface FunctionManager
        Parameters:
        addr - address within the function
        Returns:
        function containing this address, null otherwise
      • getFunctions

        public FunctionIterator getFunctions​(boolean forward)
        Description copied from interface: FunctionManager
        Returns an iterator over all non-external functions in address (entry point) order.
        Specified by:
        getFunctions in interface FunctionManager
        Parameters:
        forward - true means to iterate in ascending address order
      • getFunctions

        public FunctionIterator getFunctions​(Address start,
                                             boolean foward)
        Description copied from interface: FunctionManager
        Get an iterator over non-external functions starting at an address and ordered by entry address.
        Specified by:
        getFunctions in interface FunctionManager
        Parameters:
        start - starting address
        Returns:
        an iterator over functions.
      • getFunctions

        public FunctionIterator getFunctions​(AddressSetView asv,
                                             boolean forward)
        Description copied from interface: FunctionManager
        Get an iterator over functions with entry points in the specified address set. Function are ordered based upon entry address.
        Specified by:
        getFunctions in interface FunctionManager
        Parameters:
        asv - address set to iterate over
        forward - true means to iterate in ascending address order
        Returns:
        an iterator over functions.
      • getFunctionsNoStubs

        public FunctionIterator getFunctionsNoStubs​(boolean forward)
        Description copied from interface: FunctionManager
        Returns an iterator over all REAL functions in address (entry point) order (real functions have instructions, and aren't stubs).
        Specified by:
        getFunctionsNoStubs in interface FunctionManager
        Parameters:
        forward - true means to iterate in ascending address order
      • getFunctionsNoStubs

        public FunctionIterator getFunctionsNoStubs​(Address start,
                                                    boolean foward)
        Description copied from interface: FunctionManager
        Get an iterator over REAL functions starting at an address and ordered by entry address (real functions have instructions, and aren't stubs).
        Specified by:
        getFunctionsNoStubs in interface FunctionManager
        Parameters:
        start - starting address
        Returns:
        an iterator over functions.
      • getFunctionsNoStubs

        public FunctionIterator getFunctionsNoStubs​(AddressSetView asv,
                                                    boolean forward)
        Description copied from interface: FunctionManager
        Get an iterator over REAL functions with entry points in the specified address set (real functions have instructions, and aren't stubs). Functions are ordered based upon entry address.
        Specified by:
        getFunctionsNoStubs in interface FunctionManager
        Parameters:
        asv - address set to iterate over
        forward - true means to iterate in ascending address order
        Returns:
        an iterator over functions.
      • isInFunction

        public boolean isInFunction​(Address addr)
        Description copied from interface: FunctionManager
        Check if this address contains a function.
        Specified by:
        isInFunction in interface FunctionManager
        Parameters:
        addr - address to check
        Returns:
        true if this address is contained in a function.
      • programReady

        public void programReady​(int openMode,
                                 int currentRevision,
                                 TaskMonitor monitor)
                          throws java.io.IOException,
                                 CancelledException
        Description copied from interface: ManagerDB
        Callback from program made to each manager after the program has completed initialization. This method may be used by managers to perform additional upgrading which may have been deferred.
        Specified by:
        programReady in interface FunctionManager
        Specified by:
        programReady in interface ManagerDB
        Parameters:
        openMode - the mode that the program is being opened.
        currentRevision - current program revision. If openMode is UPGRADE, this value reflects the pre-upgrade value.
        monitor - the task monitor to use in any upgrade operations.
        Throws:
        java.io.IOException - if a database io error occurs.
        CancelledException - if the user cancelled the operation via the task monitor.
        See Also:
        ManagerDB.programReady(int, int, ghidra.util.task.TaskMonitor)
      • initSignatureSource

        public void initSignatureSource​(TaskMonitor monitor)
                                 throws CancelledException,
                                        java.io.IOException
        Initialize function signature source when it was first introduced and attempt to disable custom storage if possible. NOTE: This method intended to be called by ProgramDB only during appropriate upgrade.
        Parameters:
        monitor -
        Throws:
        CancelledException
        java.io.IOException
      • removeExplicitThisParameters

        public void removeExplicitThisParameters​(TaskMonitor monitor)
                                          throws CancelledException,
                                                 java.io.IOException
        Remove parameter symbols which correspond to the 'this' parameter for all __thiscall functions using dynamic storage. NOTE: This method intended to be called by ProgramDB only during appropriate upgrade.
        Parameters:
        monitor -
        Throws:
        CancelledException
        java.io.IOException
      • invalidateCache

        public void invalidateCache​(boolean all)
        Description copied from interface: ManagerDB
        Clears all data caches.
        Specified by:
        invalidateCache in interface FunctionManager
        Specified by:
        invalidateCache in interface ManagerDB
        Parameters:
        all - if false, some managers may not need to update their cache if they can tell that its not necessary. If this flag is true, then all managers should clear their cache no matter what.
      • getFunctionsOverlapping

        public java.util.Iterator<Function> getFunctionsOverlapping​(AddressSetView set)
        Description copied from interface: FunctionManager
        Return an iterator over functions that overlap the given address set.
        Specified by:
        getFunctionsOverlapping in interface FunctionManager
        Parameters:
        set - address set of interest
        Returns:
        iterator over Functions
      • getReferencedVariable

        public Variable getReferencedVariable​(Address instrAddr,
                                              Address storageAddr,
                                              int size,
                                              boolean isRead)
        Description copied from interface: FunctionManager
        Attempts to determine which if any of the local functions variables are referenced by the specified reference. In utilizing the firstUseOffset scoping model, negative offsets (relative to the functions entry) are shifted beyond the maximum positive offset within the function. While this does not account for the actual instruction flow, it is hopefully accurate enough for most situations.
        Specified by:
        getReferencedVariable in interface FunctionManager
        size - varnode size in bytes (1 is assumed if value <= 0)
        Returns:
        referenced variable or null if one not found
      • replaceDataTypes

        public void replaceDataTypes​(long oldDataTypeID,
                                     long newDataTypeID)
      • isThunk

        public boolean isThunk​(long key)
      • getThunkedFunctionId

        public long getThunkedFunctionId​(long functionId)
      • getThunkFunctionIds

        public java.util.List<java.lang.Long> getThunkFunctionIds​(long referencedFunctionId)
        Returns list of thunk function keys which reference the specified referencedFunctionKey
        Parameters:
        referencedFunctionId -
        Returns:
        list of thunk function IDs or null