Package ghidra.program.database.external
Class ExternalManagerDB
- java.lang.Object
-
- ghidra.program.database.external.ExternalManagerDB
-
- All Implemented Interfaces:
ManagerDB
,ExternalManager
public class ExternalManagerDB extends java.lang.Object implements ManagerDB, ExternalManager
Manages the database for external references.
-
-
Constructor Summary
Constructors Constructor Description ExternalManagerDB(DBHandle handle, AddressMap addrMap, int openMode, Lock lock, TaskMonitor monitor)
Constructs a new ExternalManagerDB
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Library
addExternalLibraryName(java.lang.String name, SourceType source)
Adds a new external library nameExternalLocation
addExtFunction(Namespace extParentNamespace, java.lang.String extLabel, Address extAddr, SourceType sourceType)
Get or create an external function location associated with an library/file named extName and the label within that file specified by extLabelExternalLocation
addExtFunction(Namespace extNamespace, java.lang.String extLabel, Address extAddr, SourceType sourceType, boolean reuseExisting)
Get or create an external function location associated with an library/file named extName and the label within that file specified by extLabelExternalLocation
addExtFunction(java.lang.String extLibraryName, java.lang.String extLabel, Address extAddr, SourceType sourceType)
Get or create an external location associated with an library/file named extName and the label within that file specified by extLabelExternalLocation
addExtLocation(Namespace extParentNamespace, java.lang.String extLabel, Address extAddr, SourceType sourceType)
Get or create an external location in the indicated parent namespace with the specified name.ExternalLocation
addExtLocation(Namespace extParentNamespace, java.lang.String extLabel, Address extAddr, SourceType sourceType, boolean reuseExisting)
Get or create an external location in the indicated parent namespace with the specified name.ExternalLocation
addExtLocation(java.lang.String extLibraryName, java.lang.String extLabel, Address extAddr, SourceType sourceType)
Get or create an external location associated with an library/file named extName and the label within that file specified by extLabelboolean
contains(java.lang.String libraryName)
Determines if the indicated external library name is being managed (exists).void
deleteAddressRange(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.static java.lang.String
getDefaultExternalName(SymbolDB sym)
Get the default name for an external function or code symbolLibrary
getExternalLibrary(java.lang.String name)
Get the Library which corresponds to the specified namejava.lang.String[]
getExternalLibraryNames()
Returns an array of all external names for which locations have been defined.java.lang.String
getExternalLibraryPath(java.lang.String externalName)
Returns the file pathname associated with an external name.ExternalLocation
getExternalLocation(Namespace extNamespace, java.lang.String extLabel)
Get an external location.ExternalLocation
getExternalLocation(Symbol symbol)
Returns the external location associated with the given external symbolExternalLocation
getExternalLocation(java.lang.String extName, java.lang.String extLabel)
Get an external location.ExternalLocationIterator
getExternalLocations(Address memoryAddress)
Get an iterator over all external locations which have been associated to the specified memory addressjava.util.List<ExternalLocation>
getExternalLocations(Namespace libScope, java.lang.String extLabel)
Returns a list of External Locations matching the given label name in the given Namespace.ExternalLocationIterator
getExternalLocations(java.lang.String externalName)
Get an iterator over all external locations associated with the specified externalName.java.util.List<ExternalLocation>
getExternalLocations(java.lang.String libraryName, java.lang.String label)
Returns a list of External Locations matching the given label name in the given Library.ExternalLocation
getExtLocation(Address externalAddr)
Returns the external location associated with the given external addressExternalLocation
getUniqueExternalLocation(Namespace namespace, java.lang.String label)
Returns the unique external location associated with the given namespace and labelExternalLocation
getUniqueExternalLocation(java.lang.String libraryName, java.lang.String label)
Returns the unique external location associated with the given library name and labelvoid
invalidateCache(boolean all)
Clears all data caches.void
moveAddressRange(Address fromAddr, Address toAddr, long length, TaskMonitor monitor)
Move all objects within an address range to a new location.void
programReady(int openMode, int currentRevision, TaskMonitor monitor)
Callback from program made to each manager after the program has completed initialization.boolean
removeExternalLibrary(java.lang.String name)
Removes external name if no associated ExternalLocation's existboolean
removeExternalLocation(Address externalAddr)
Removes the external location at the given external addressvoid
setExternalPath(java.lang.String externalName, java.lang.String externalPath, boolean userDefined)
Sets the file pathname associated with an existing external name.void
setLanguage(LanguageTranslator translator, TaskMonitor monitor)
void
setProgram(ProgramDB program)
Callback from program used to indicate all manager have been created.void
updateExternalLibraryName(java.lang.String oldName, java.lang.String newName, SourceType source)
Update the external program for all references.
-
-
-
Constructor Detail
-
ExternalManagerDB
public ExternalManagerDB(DBHandle handle, AddressMap addrMap, int openMode, Lock lock, TaskMonitor monitor) throws CancelledException, java.io.IOException, VersionException
Constructs a new ExternalManagerDB- Parameters:
handle
- the open database handleaddrMap
- the address mapopenMode
- the program open mode.lock
- the program synchronization lockmonitor
- the progress monitor used when upgrading- Throws:
CancelledException
- if the user cancelled while an upgrade was occurringjava.io.IOException
- if a database io error occurs.VersionException
- if the database version does not match the expected version
-
-
Method Detail
-
setProgram
public void setProgram(ProgramDB program)
Description copied from interface:ManagerDB
Callback 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:
setProgram
in interfaceManagerDB
- Parameters:
program
- the program is set when all the initializations have been completed.
-
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 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:
java.io.IOException
- if a database io error occurs.CancelledException
- if the user cancelled the operation via the task monitor.
-
invalidateCache
public void invalidateCache(boolean all) throws java.io.IOException
Description copied from interface:ManagerDB
Clears all data caches.- Specified by:
invalidateCache
in 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.- Throws:
java.io.IOException
- if a database io error occurs.
-
deleteAddressRange
public void deleteAddressRange(Address startAddr, Address endAddr, TaskMonitor monitor) throws CancelledException
Description copied from interface:ManagerDB
Delete all objects which have been applied to the address range startAddr to endAddr and update the database accordingly.- Specified by:
deleteAddressRange
in 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.
-
moveAddressRange
public void moveAddressRange(Address fromAddr, Address toAddr, long length, TaskMonitor monitor) throws CancelledException
Description copied from interface:ManagerDB
Move all objects within an address range to a new location.- Specified by:
moveAddressRange
in interfaceManagerDB
- Parameters:
fromAddr
- the first address of the range to be moved.toAddr
- the address where to the range is to be moved.length
- the number of addresses to move.monitor
- the task monitor to use in any upgrade operations.- Throws:
CancelledException
- if the user cancelled the operation via the task monitor.
-
addExtLocation
public ExternalLocation addExtLocation(java.lang.String extLibraryName, java.lang.String extLabel, Address extAddr, SourceType sourceType) throws InvalidInputException, DuplicateNameException
Description copied from interface:ExternalManager
Get or create an external location associated with an library/file named extName and the label within that file specified by extLabel- Specified by:
addExtLocation
in interfaceExternalManager
- Parameters:
extLibraryName
- the external library nameextLabel
- the external labelextAddr
- the external addresssourceType
- the source type of this external library's symbol- Returns:
- external location
- Throws:
InvalidInputException
DuplicateNameException
- if another non-Library namespace has the same name
-
addExtLocation
public ExternalLocation addExtLocation(Namespace extParentNamespace, java.lang.String extLabel, Address extAddr, SourceType sourceType) throws InvalidInputException
Description copied from interface:ExternalManager
Get or create an external location in the indicated parent namespace with the specified name.- Specified by:
addExtLocation
in interfaceExternalManager
- Parameters:
extParentNamespace
- the external namespaceextLabel
- the external labelextAddr
- the external addresssourceType
- the source type of this external library's symbol- Returns:
- external location
- Throws:
InvalidInputException
-
addExtLocation
public ExternalLocation addExtLocation(Namespace extParentNamespace, java.lang.String extLabel, Address extAddr, SourceType sourceType, boolean reuseExisting) throws InvalidInputException
Description copied from interface:ExternalManager
Get or create an external location in the indicated parent namespace with the specified name.- Specified by:
addExtLocation
in interfaceExternalManager
- Parameters:
extParentNamespace
- the external namespaceextLabel
- the external labelextAddr
- the external addresssourceType
- the source type of this external library's symbolreuseExisting
- if true, this will return an existing matching external location instead of creating a new one.- Returns:
- external location
- Throws:
InvalidInputException
-
addExtFunction
public ExternalLocation addExtFunction(java.lang.String extLibraryName, java.lang.String extLabel, Address extAddr, SourceType sourceType) throws InvalidInputException, DuplicateNameException
Description copied from interface:ExternalManager
Get or create an external location associated with an library/file named extName and the label within that file specified by extLabel- Specified by:
addExtFunction
in interfaceExternalManager
- Parameters:
extLibraryName
- the external library nameextLabel
- the external labelextAddr
- the external addresssourceType
- the source type of this external library's symbol- Returns:
- external location
- Throws:
InvalidInputException
DuplicateNameException
- if another non-Library namespace has the same name
-
addExtFunction
public ExternalLocation addExtFunction(Namespace extParentNamespace, java.lang.String extLabel, Address extAddr, SourceType sourceType) throws InvalidInputException
Description copied from interface:ExternalManager
Get or create an external function location associated with an library/file named extName and the label within that file specified by extLabel- Specified by:
addExtFunction
in interfaceExternalManager
- Parameters:
extParentNamespace
- the external namespaceextLabel
- the external labelextAddr
- the external addresssourceType
- the source type of this external library's symbol- Returns:
- external location
- Throws:
InvalidInputException
-
addExtFunction
public ExternalLocation addExtFunction(Namespace extNamespace, java.lang.String extLabel, Address extAddr, SourceType sourceType, boolean reuseExisting) throws InvalidInputException
Description copied from interface:ExternalManager
Get or create an external function location associated with an library/file named extName and the label within that file specified by extLabel- Specified by:
addExtFunction
in interfaceExternalManager
- Parameters:
extNamespace
- the external namespaceextLabel
- the external labelsourceType
- the source type of this external library's symbolreuseExisting
- if true, will return any existing matching location instead of creating a new one. If false, will prefer to create a new one as long as the specified address is not null and not used in an existing location.- Returns:
- external location
- Throws:
InvalidInputException
-
getExternalLocations
public java.util.List<ExternalLocation> getExternalLocations(Namespace libScope, java.lang.String extLabel)
Description copied from interface:ExternalManager
Returns a list of External Locations matching the given label name in the given Namespace.- Specified by:
getExternalLocations
in interfaceExternalManager
- Parameters:
libScope
- the Namespace to searchextLabel
- the name of the labels to search for.- Returns:
- a list of External Locations matching the given label name in the given Namespace.
-
getExternalLocations
public java.util.List<ExternalLocation> getExternalLocations(java.lang.String libraryName, java.lang.String label)
Description copied from interface:ExternalManager
Returns a list of External Locations matching the given label name in the given Library.- Specified by:
getExternalLocations
in interfaceExternalManager
- Parameters:
libraryName
- the name of the librarylabel
- the name of the label- Returns:
- a list of External Locations matching the given label name in the given Library.
-
getUniqueExternalLocation
public ExternalLocation getUniqueExternalLocation(Namespace namespace, java.lang.String label)
Description copied from interface:ExternalManager
Returns the unique external location associated with the given namespace and label- Specified by:
getUniqueExternalLocation
in interfaceExternalManager
- Parameters:
namespace
- the namespacelabel
- the label of the external location- Returns:
- the unique external location or null
-
getUniqueExternalLocation
public ExternalLocation getUniqueExternalLocation(java.lang.String libraryName, java.lang.String label)
Description copied from interface:ExternalManager
Returns the unique external location associated with the given library name and label- Specified by:
getUniqueExternalLocation
in interfaceExternalManager
- Parameters:
libraryName
- the library namelabel
- the label of the external location- Returns:
- the unique external location or null
-
getExternalLocation
public ExternalLocation getExternalLocation(java.lang.String extName, java.lang.String extLabel)
Description copied from interface:ExternalManager
Get an external location.- Specified by:
getExternalLocation
in interfaceExternalManager
- Parameters:
extName
- the name of the library for which to get an external locationextLabel
- the name of the external location.- Returns:
- first matching external location
-
getExternalLocation
public ExternalLocation getExternalLocation(Namespace extNamespace, java.lang.String extLabel)
Description copied from interface:ExternalManager
Get an external location.- Specified by:
getExternalLocation
in interfaceExternalManager
- Parameters:
extNamespace
- the namespace containing the external label.extLabel
- the name of the external location.- Returns:
- first matching external location
-
getDefaultExternalName
public static java.lang.String getDefaultExternalName(SymbolDB sym)
Get the default name for an external function or code symbol- Parameters:
sym
-- Returns:
- default name
-
getExtLocation
public ExternalLocation getExtLocation(Address externalAddr)
Returns the external location associated with the given external address- Parameters:
externalAddr
- the external address.
-
getExternalLocation
public ExternalLocation getExternalLocation(Symbol symbol)
Description copied from interface:ExternalManager
Returns the external location associated with the given external symbol- Specified by:
getExternalLocation
in interfaceExternalManager
- Parameters:
symbol
- the external symbol.- Returns:
- the external location or null
-
removeExternalLocation
public boolean removeExternalLocation(Address externalAddr)
Removes the external location at the given external address- Parameters:
externalAddr
- the address at which to remove the external location.
-
removeExternalLibrary
public boolean removeExternalLibrary(java.lang.String name)
Description copied from interface:ExternalManager
Removes external name if no associated ExternalLocation's exist- Specified by:
removeExternalLibrary
in interfaceExternalManager
- Parameters:
name
- external library name- Returns:
- true if removed, false if unable to due to associated locations/references
-
updateExternalLibraryName
public void updateExternalLibraryName(java.lang.String oldName, java.lang.String newName, SourceType source) throws DuplicateNameException, InvalidInputException
Update the external program for all references.- Specified by:
updateExternalLibraryName
in interfaceExternalManager
- Parameters:
oldName
- old external program namenewName
- new external program namesource
- the source of this external library: Symbol.DEFAULT, Symbol.ANALYSIS, Symbol.IMPORTED, or Symbol.USER_DEFINED- Throws:
DuplicateNameException
InvalidInputException
-
addExternalLibraryName
public Library addExternalLibraryName(java.lang.String name, SourceType source) throws DuplicateNameException, InvalidInputException
Description copied from interface:ExternalManager
Adds a new external library name- Specified by:
addExternalLibraryName
in interfaceExternalManager
- Parameters:
name
- the new external library name to add.source
- the source of this external library- Returns:
- library
- Throws:
DuplicateNameException
- if another non-Library namespace has the same nameInvalidInputException
-
contains
public boolean contains(java.lang.String libraryName)
Description copied from interface:ExternalManager
Determines if the indicated external library name is being managed (exists).- Specified by:
contains
in interfaceExternalManager
- Parameters:
libraryName
- the external library name- Returns:
- true if the name is defined (whether it has a path or not).
-
getExternalLibraryNames
public java.lang.String[] getExternalLibraryNames()
Description copied from interface:ExternalManager
Returns an array of all external names for which locations have been defined.- Specified by:
getExternalLibraryNames
in interfaceExternalManager
- Returns:
- array of external names
-
getExternalLibrary
public Library getExternalLibrary(java.lang.String name)
Description copied from interface:ExternalManager
Get the Library which corresponds to the specified name- Specified by:
getExternalLibrary
in interfaceExternalManager
- Parameters:
name
- name of library- Returns:
- library or null if not found
-
getExternalLibraryPath
public java.lang.String getExternalLibraryPath(java.lang.String externalName)
Description copied from interface:ExternalManager
Returns the file pathname associated with an external name. Null is returned if either the external name does not exist or a pathname has not been set.- Specified by:
getExternalLibraryPath
in interfaceExternalManager
- Parameters:
externalName
- external name- Returns:
- project file pathname or null
-
setExternalPath
public void setExternalPath(java.lang.String externalName, java.lang.String externalPath, boolean userDefined) throws InvalidInputException
Description copied from interface:ExternalManager
Sets the file pathname associated with an existing external name.- Specified by:
setExternalPath
in interfaceExternalManager
- Parameters:
externalName
- the name of the library to associate with a file.externalPath
- the path to the program to be associated with the library name.userDefined
- true if the external path is being specified by the user- Throws:
InvalidInputException
-
getExternalLocations
public ExternalLocationIterator getExternalLocations(Address memoryAddress)
Description copied from interface:ExternalManager
Get an iterator over all external locations which have been associated to the specified memory address- Specified by:
getExternalLocations
in interfaceExternalManager
- Parameters:
memoryAddress
- memory address- Returns:
- external location iterator
-
getExternalLocations
public ExternalLocationIterator getExternalLocations(java.lang.String externalName)
Description copied from interface:ExternalManager
Get an iterator over all external locations associated with the specified externalName.- Specified by:
getExternalLocations
in interfaceExternalManager
- Parameters:
externalName
- the name of the library to get locations for- Returns:
- external location iterator
-
setLanguage
public void setLanguage(LanguageTranslator translator, TaskMonitor monitor) throws CancelledException
- Throws:
CancelledException
-
-