Package ghidra.program.database.function
Class FunctionManagerDB
java.lang.Object
ghidra.program.database.function.FunctionManagerDB
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionFunctionManagerDB(DBHandle dbHandle, AddressMap addrMap, OpenMode openMode, Lock lock, TaskMonitor monitor) Construct a new FunctionManager -
Method Summary
Modifier and TypeMethodDescriptioncreateExternalFunction(Address extSpaceAddr, String name, Namespace nameSpace, String extData, SourceType source) Transform an existing external symbol into an external function.createFunction(String name, Address entryPoint, AddressSetView body, SourceType source) Create a function with the given body at entry point within the global namespace.createFunction(String name, Namespace nameSpace, Address entryPoint, AddressSetView body, SourceType source) Create a function with the given body at entry point.createThunkFunction(String name, Namespace nameSpace, Address entryPoint, AddressSetView body, Function thunkedFunction, SourceType source) Create a thunk function with the given body at entry point.voiddeleteAddressRange(Address startAddr, Address endAddr, TaskMonitor monitor) Delete all objects which have been applied to the address range startAddr to endAddr and update the database accordingly.booleandoRemoveFunction(long key) voidfunctionNamespaceChanged(long key) voidgetCallingConvention(String name) Gets the prototype model of the calling convention with the specified name in this programGet the ordered list of defined calling convention names.Gets the default calling convention's prototype model in this program.Get an iterator over all external functions.getFunction(long key) Get the function with the given key.getFunctionAt(Address entryPoint) Get the function at entryPointgetFunctionContaining(Address addr) Get a function containing an address.intReturns the total number of functions in the program including external functionsgetFunctions(boolean forward) Returns an iterator over all non-external functions in address (entry point) ordergetFunctions(Address start, boolean forward) Get an iterator over non-external functions starting at an address and ordered by entry addressgetFunctions(AddressSetView asv, boolean forward) Get an iterator over functions with entry points in the specified address set.getFunctionsNoStubs(boolean forward) Returns an iterator over all REAL functions in address (entry point) order (real functions have instructions, and aren't stubs)getFunctionsNoStubs(Address start, boolean forward) Get an iterator over REAL functions starting at an address and ordered by entry address (real functions have instructions, and aren't stubs).getFunctionsNoStubs(AddressSetView asv, boolean forward) Get an iterator over REAL functions with entry points in the specified address set (real functions have instructions, and aren't stubs).Return an iterator over functions that overlap the given address set.Returns the function tag managerReturns this manager's programgetReferencedFunction(Address address) Get the function which resides at the specified address or is referenced from the specified addressgetReferencedVariable(Address instrAddr, Address storageAddr, int size, boolean isRead) Attempts to determine which if any of the local functions variables are referenced by the specified reference.longgetThunkedFunctionId(long functionId) getThunkFunctionIds(long referencedFunctionId) Returns list of thunk function keys which reference the specified referencedFunctionKeyvoidinitSignatureSource(TaskMonitor monitor) Initialize function signature source when it was first introduced and attempt to disable custom storage if possible.voidinvalidateCache(boolean all) Clears all data cachesbooleanisInFunction(Address addr) Check if this address contains a function.booleanisThunk(long key) voidmoveAddressRange(Address fromAddr, Address toAddr, long length, TaskMonitor monitor) Move all objects within an address range to a new locationvoidprogramReady(OpenMode openMode, int currentRevision, TaskMonitor monitor) Callback from program made to each manager after the program has completed initialization.voidremoveExplicitThisParameters(TaskMonitor monitor) Remove parameter symbols which correspond to the 'this' parameter for all __thiscall functions using dynamic storage.booleanremoveFunction(Address entryPoint) Remove a function defined at entryPointvoidreplaceDataTypes(Map<Long, Long> dataTypeReplacementMap) voidsetLanguage(LanguageTranslator translator, TaskMonitor monitor) Perform language translation.voidsetProgram(ProgramDB program) Callback from program used to indicate all manager have been created.
-
Constructor Details
-
FunctionManagerDB
public FunctionManagerDB(DBHandle dbHandle, AddressMap addrMap, OpenMode openMode, Lock lock, TaskMonitor monitor) throws VersionException, CancelledException, IOException Construct a new FunctionManager- Parameters:
dbHandle- data base handleaddrMap- address map for the programopenMode- CREATE, UPDATE, READ_ONLY, or UPGRADElock- the program synchronization lockmonitor-- Throws:
VersionException- if function manager's version does not match its expected versionCancelledException- if the function table is being upgraded and the user canceled the upgrade processIOException- if there was a problem accessing the database
-
-
Method Details
-
getProgram
Description copied from interface:FunctionManagerReturns this manager's program- Specified by:
getProgramin interfaceFunctionManager- Returns:
- the program
-
getCallingConventionNames
Description copied from interface:FunctionManagerGet the ordered list of defined calling convention names. The reserved names "unknown" and "default" are not included. The returned collection may not include all names referenced by various functions and function-definitions. This set is limited to those defined by the associated compiler specification. SeeDataTypeManager.getDefinedCallingConventionNames().For a set of all known names (including those that are not defined by compiler spec) see
DataTypeManager.getKnownCallingConventionNames().- Specified by:
getCallingConventionNamesin interfaceFunctionManager- Returns:
- the calling convention names.
-
getDefaultCallingConvention
Description copied from interface:FunctionManagerGets the default calling convention's prototype model in this program.- Specified by:
getDefaultCallingConventionin interfaceFunctionManager- Returns:
- the default calling convention prototype model or null.
-
getCallingConvention
Description copied from interface:FunctionManagerGets the prototype model of the calling convention with the specified name in this program- Specified by:
getCallingConventionin interfaceFunctionManager- Parameters:
name- the calling convention name- Returns:
- the named function calling convention prototype model or null.
-
createExternalFunction
public Function createExternalFunction(Address extSpaceAddr, String name, Namespace nameSpace, String extData, SourceType source) throws InvalidInputException Transform an existing external symbol into an external function. This method should only be invoked by an ExternalSymbol- Parameters:
extSpaceAddr- the external space address to use when creating this external. Any other symbol using this address must first be deleted. Results are unpredictable if this is not done.name- the external function namenameSpace- the external function namespaceextData- the external data string to store additional info (seeExternalLocationDB)source- the source of this external.- Returns:
- external function
- Throws:
InvalidInputException- if the name is invalid
-
createFunction
public Function createFunction(String name, Address entryPoint, AddressSetView body, SourceType source) throws InvalidInputException, OverlappingFunctionException Description copied from interface:FunctionManagerCreate a function with the given body at entry point within the global namespace.- Specified by:
createFunctionin interfaceFunctionManager- Parameters:
name- the name of the new function or null for default nameentryPoint- entry point of functionbody- addresses contained in the function bodysource- the source of this function- Returns:
- new function or null if one or more functions overlap the specified body address set.
- Throws:
InvalidInputException- if the name has invalid charactersOverlappingFunctionException- if the address set of the body overlaps an existing function
-
createFunction
public Function createFunction(String name, Namespace nameSpace, Address entryPoint, AddressSetView body, SourceType source) throws InvalidInputException, OverlappingFunctionException Description copied from interface:FunctionManagerCreate a function with the given body at entry point.- Specified by:
createFunctionin interfaceFunctionManager- Parameters:
name- the name of the new function or null for default namenameSpace- the nameSpace in which to create the functionentryPoint- entry point of functionbody- addresses contained in the function bodysource- the source of this function- Returns:
- new function or null if one or more functions overlap the specified body address set.
- Throws:
InvalidInputException- if the name has invalid charactersOverlappingFunctionException- if the address set of the body overlaps an existing function
-
createThunkFunction
public Function createThunkFunction(String name, Namespace nameSpace, Address entryPoint, AddressSetView body, Function thunkedFunction, SourceType source) throws OverlappingFunctionException Description copied from interface:FunctionManagerCreate a thunk function with the given body at entry point.- Specified by:
createThunkFunctionin interfaceFunctionManager- Parameters:
name- the name of the new function or null for default namenameSpace- the nameSpace in which to create the functionentryPoint- entry point of functionbody- addresses contained in the function bodythunkedFunction- 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:FunctionManagerReturns the total number of functions in the program including external functions- Specified by:
getFunctionCountin interfaceFunctionManager- Returns:
- the count
-
removeFunction
Description copied from interface:FunctionManagerRemove a function defined at entryPoint- Specified by:
removeFunctionin interfaceFunctionManager- Parameters:
entryPoint- the entry point- Returns:
- true if the function was removed
-
functionTagsChanged
public void functionTagsChanged() -
functionNamespaceChanged
public void functionNamespaceChanged(long key) -
doRemoveFunction
public boolean doRemoveFunction(long key) -
getFunction
Get the function with the given key.- Specified by:
getFunctionin interfaceFunctionManager- 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
Description copied from interface:FunctionManagerGet the function which resides at the specified address or is referenced from the specified address- Specified by:
getReferencedFunctionin interfaceFunctionManager- Parameters:
address- function address or address of pointer to a function.- Returns:
- referenced function or null
-
getFunctionAt
Description copied from interface:FunctionManagerGet the function at entryPoint- Specified by:
getFunctionAtin interfaceFunctionManager- Parameters:
entryPoint- the entry point- Returns:
- null if there is no function at entryPoint
-
getFunctionContaining
Description copied from interface:FunctionManagerGet a function containing an address.- Specified by:
getFunctionContainingin interfaceFunctionManager- Parameters:
addr- address within the function- Returns:
- function containing this address, null otherwise
-
getFunctions
Description copied from interface:FunctionManagerReturns an iterator over all non-external functions in address (entry point) order- Specified by:
getFunctionsin interfaceFunctionManager- Parameters:
forward- true means to iterate in ascending address order- Returns:
- the iterator
-
getFunctions
Description copied from interface:FunctionManagerGet an iterator over non-external functions starting at an address and ordered by entry address- Specified by:
getFunctionsin interfaceFunctionManager- Parameters:
start- starting addressforward- true means to iterate in ascending address order- Returns:
- an iterator over functions.
-
getFunctions
Description copied from interface:FunctionManagerGet an iterator over functions with entry points in the specified address set. Function are ordered based upon entry address.- Specified by:
getFunctionsin interfaceFunctionManager- Parameters:
asv- address set to iterate overforward- true means to iterate in ascending address order- Returns:
- an iterator over functions.
-
getFunctionsNoStubs
Description copied from interface:FunctionManagerReturns an iterator over all REAL functions in address (entry point) order (real functions have instructions, and aren't stubs)- Specified by:
getFunctionsNoStubsin interfaceFunctionManager- Parameters:
forward- true means to iterate in ascending address order- Returns:
- the iterator
-
getFunctionsNoStubs
Description copied from interface:FunctionManagerGet an iterator over REAL functions starting at an address and ordered by entry address (real functions have instructions, and aren't stubs).- Specified by:
getFunctionsNoStubsin interfaceFunctionManager- Parameters:
start- starting addressforward- true means to iterate in ascending address order- Returns:
- an iterator over functions.
-
getFunctionsNoStubs
Description copied from interface:FunctionManagerGet 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:
getFunctionsNoStubsin interfaceFunctionManager- Parameters:
asv- address set to iterate overforward- true means to iterate in ascending address order- Returns:
- an iterator over functions.
-
getExternalFunctions
Description copied from interface:FunctionManagerGet an iterator over all external functions. Functions returned have no particular order.- Specified by:
getExternalFunctionsin interfaceFunctionManager- Returns:
- an iterator over external functions
-
isInFunction
Description copied from interface:FunctionManagerCheck if this address contains a function.- Specified by:
isInFunctionin interfaceFunctionManager- Parameters:
addr- address to check- Returns:
- true if this address is contained in a function.
-
moveAddressRange
public void moveAddressRange(Address fromAddr, Address toAddr, long length, TaskMonitor monitor) throws CancelledException Description copied from interface:FunctionManagerMove all objects within an address range to a new location- Specified by:
moveAddressRangein interfaceFunctionManager- Specified by:
moveAddressRangein interfaceManagerDB- Parameters:
fromAddr- the first address of the range to be movedtoAddr- the address where to the range is to be movedlength- the number of addresses to movemonitor- the task monitor to use in any upgrade operations- Throws:
CancelledException- if the user cancelled the operation via the task monitor
-
deleteAddressRange
public void deleteAddressRange(Address startAddr, Address endAddr, TaskMonitor monitor) throws CancelledException Description copied from interface:ManagerDBDelete all objects which have been applied to the address range startAddr to endAddr and update the database accordingly. The specified start and end addresses must form a valid range within a singleAddressSpace.- Specified by:
deleteAddressRangein interfaceManagerDB- Parameters:
startAddr- the first address in the range.endAddr- the last address in the range.monitor- the task monitor to use in any upgrade operations.- Throws:
CancelledException- if the user cancelled the operation via the task monitor.
-
setProgram
Description copied from interface:ManagerDBCallback from program used to indicate all manager have been created. When this method is invoked, all managers have been instantiated but may not be fully initialized.- Specified by:
setProgramin interfaceManagerDB- Parameters:
program- the program is set when all the initializations have been completed.
-
programReady
public void programReady(OpenMode openMode, int currentRevision, TaskMonitor monitor) throws IOException, CancelledException Description copied from interface:ManagerDBCallback 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:
programReadyin interfaceManagerDB- 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:
IOException- if a database io error occurs.CancelledException- if the user cancelled the operation via the task monitor.
-
initSignatureSource
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:
CancelledExceptionIOException
-
removeExplicitThisParameters
public void removeExplicitThisParameters(TaskMonitor monitor) throws CancelledException, 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:
CancelledExceptionIOException
-
invalidateCache
public void invalidateCache(boolean all) Description copied from interface:FunctionManagerClears all data caches- Specified by:
invalidateCachein interfaceFunctionManager- Specified by:
invalidateCachein interfaceManagerDB- 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
Description copied from interface:FunctionManagerReturn an iterator over functions that overlap the given address set.- Specified by:
getFunctionsOverlappingin interfaceFunctionManager- 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:FunctionManagerAttempts 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:
getReferencedVariablein interfaceFunctionManager- Parameters:
instrAddr- the instruction addressstorageAddr- the storage addresssize- varnode size in bytes (1 is assumed if value <= 0)isRead- true if the reference is a read reference- Returns:
- referenced variable or null if one not found
-
replaceDataTypes
-
isThunk
public boolean isThunk(long key) -
getThunkedFunctionId
public long getThunkedFunctionId(long functionId) -
getThunkFunctionIds
Returns list of thunk function keys which reference the specified referencedFunctionKey- Parameters:
referencedFunctionId-- Returns:
- list of thunk function IDs or null
-
setLanguage
public void setLanguage(LanguageTranslator translator, TaskMonitor monitor) throws CancelledException Perform language translation. Update function return storage specifications to reflect address space and register mappings- Parameters:
translator-monitor-- Throws:
CancelledException
-
getFunctionTagManager
Description copied from interface:FunctionManagerReturns the function tag manager- Specified by:
getFunctionTagManagerin interfaceFunctionManager- Returns:
- the function tag manager
-