Package ghidra.framework
Class Application
java.lang.Object
ghidra.framework.Application
The Application class provides a variety of static convenience methods for accessing Application
elements that can be used once the
initializeApplication(utility.application.ApplicationLayout, ghidra.framework.ApplicationConfiguration)
call has been made.
In order to initialize an application, an ApplicationLayout
and an
ApplicationConfiguration
must be provided. The layout and configuration come in a
variety of flavors, and are what makes the Application class usable across a range of tools.
Example use case:
ApplicationLayout layout = new GhidraApplicationLayout(); ApplicationConfiguration configuration = new GhidraApplicationConfiguration(); Application.initializeApplication(layout, configuration);
-
Method Summary
Modifier and TypeMethodDescriptionstatic File
createTempFile
(String prefix, String suffix) Creates a new empty file in the Application's temp directory, using the given prefix and suffix strings to generate its name.static ResourceFile
findDataFileInAnyModule
(String relativePath) Finds the first file that exists with the relative path in any module.static List
<ResourceFile> findFilesByExtension
(String moduleName, String extension) Returns a list of all files with the given extension that are located in the named module.static List
<ResourceFile> findFilesByExtensionInApplication
(String extension) Returns all files within any module's data directory that end with the given extension.static List
<ResourceFile> findFilesByExtensionInMyModule
(String extension) Returns a list of all files with the given extension that are located in the module of the calling class.static List
<ResourceFile> findModuleSubDirectories
(String relativePath) Returns a list of all directories in any module that have the given module relative path.static ApplicationLayout
static String
getApplicationProperty
(String propertyName) Returns the value of the give application property name.static String
Returns the release name for this build.static Collection
<ResourceFile> Returns a list of the application root directories.static ResourceFile
Returns the application root directory.Return the source repository revisions used in the build process or null if not applicable.static String
Returns the version of this build.static String
Returns the date this build was created.static ResourceFile
Returns the installation directory.static Collection
<ResourceFile> Returns a collection of module library directories.static ResourceFile
static ResourceFile
getModuleContainingClass
(String className) static ResourceFile
static ResourceFile
getModuleDataFile
(String relativeDataPath) Returns the file relative to the calling class's module's data directorystatic ResourceFile
getModuleDataFile
(String moduleName, String relativeDataPath) Returns the file relative to the named module's data directory.static ResourceFile
getModuleDataSubDirectory
(String relativePath) Returns the directory relative to the calling class's module's data directory.static ResourceFile
getModuleDataSubDirectory
(String moduleName, String relativePath) Return the directory relative the the name module's data directory.static ResourceFile
getModuleFile
(String moduleName, String relativePath) Returns the file relative to the named module's directory.static ResourceFile
getModuleRootDir
(String moduleName) Return the module root directory for the module with the given name.static Collection
<ResourceFile> Returns a collection of all the module root directories.static ResourceFile
getModuleSubDirectory
(String moduleName, String relativePath) Return the directory relative the the name module's directory.static ResourceFile
Returns the module root directory that contains the class that called this method.static String
getName()
Returns the name of the application.static File
Returns the specified OS specific file.static File
Returns the OS specific file within the given module with the given name.static File
Returns the cache directory specific to the user and the application.static File
Returns the File containing the user configuration settings for this application.getUserSettingsFiles
(String dirName, String fileExtension) Returns a list of files in a setting subdirectory that have the given file extension, copying files from older versions of Ghidra if the settings dir is not yet established.static File
Returns the temporary directory specific to the user and the application.static void
initializeApplication
(ApplicationLayout layout, ApplicationConfiguration configuration) Initializes the application.static void
initializeLogging
(File logFile, File scriptLogFile) If the Application was previously initialized with logging disabled, this method may be used to perform delayed logging initialization.static boolean
Checks whether or not the application is in "single jar" mode.static boolean
Checks to see if the application has been initialized.static boolean
Returns true if this build was not built through the official build process, but instead was created using the "buildLocal" call.
-
Method Details
-
initializeApplication
public static void initializeApplication(ApplicationLayout layout, ApplicationConfiguration configuration) Initializes the application. The static methods of this class cannot be used until the application is initialized.- Parameters:
layout
- The application layout to be used by the application.configuration
- The application configuration to be used by the application.
-
isInitialized
public static boolean isInitialized()Checks to see if the application has been initialized.- Returns:
- true if the application has been initialized; otherwise, false.
-
initializeLogging
If the Application was previously initialized with logging disabled, this method may be used to perform delayed logging initialization.- Parameters:
logFile
- application log file, if null the default application.log will be stored within the user's application settings directoryscriptLogFile
- scripting log file, if null the default script.log will be stored within the user's application settings directory- Throws:
AssertException
- if Application has not yet been initialized, or logging was previously configured for the application.
-
getApplicationLayout
-
getModuleContainingResourceFile
-
getModuleContainingClass
-
getModuleContainingClass
-
getMyModuleRootDirectory
Returns the module root directory that contains the class that called this method.- Returns:
- the module root directory that contains the class that called this method.
-
getName
Returns the name of the application.- Returns:
- the name of the application.
-
getApplicationProperty
Returns the value of the give application property name.- Parameters:
propertyName
- the name of the application property to retrieve.- Returns:
- the value of the give application property name.
-
getApplicationRootDirectories
Returns a list of the application root directories. An application root directory is a directory containing one or more modules. Applications support multiple application root directories so that it can contain modules that don't have a common file system root. This is useful if the application contains modules from more than one source code repository. Application roots are returned in the order they appear in the classpath.- Returns:
- a list of root directories containing modules for this application.
-
getApplicationRootDirectory
Returns the application root directory. An application root directory is a directory containing one or more modules. In development mode there may be multiple application root directories, which can be retrieved viagetApplicationRootDirectories()
.In an installation of the application, there will only be one application root directory.
Note: Be sure you understand that there may be multiple application root directories in development mode. In general you should not be using this method for searching for files yourself, but instead using the various
find*
methods of this class.- Returns:
- Returns the application root directory.
- See Also:
-
getUserSettingsDirectory
Returns the File containing the user configuration settings for this application.- Returns:
- the File containing the user configuration settings for this application.
-
getUserSettingsFiles
Returns a list of files in a setting subdirectory that have the given file extension, copying files from older versions of Ghidra if the settings dir is not yet established.- Parameters:
dirName
- the name of the settings subdirectory.fileExtension
- the file name suffix- Returns:
- a list of files in a setting sub directory that have the given file extension
-
getUserTempDirectory
Returns the temporary directory specific to the user and the application. This directory may be removed at system reboot or during periodic system cleanup of unused temp files. This directory is specific to the application name but not the version. Resources stored within this directory should utilize some form of access locking or unique naming. Transient resources should be deleted when no longer in use.- Returns:
- temp directory
-
getUserCacheDirectory
Returns the cache directory specific to the user and the application. The intention is for directory contents to be preserved, however the specific location is platform specific and contents may be removed when not in use. This directory is specific to the application name but not the version. Resources stored within this directory should utilize some form of access locking and/or unique naming.- Returns:
- cache directory
-
createTempFile
Creates a new empty file in the Application's temp directory, using the given prefix and suffix strings to generate its name.- Parameters:
prefix
- The prefix string to be used in generating the file's name; must be at least three characters longsuffix
- The suffix string to be used in generating the file's name; may benull
, in which case the suffix".tmp"
will be used- Returns:
- A
File
denoting a newly-created empty file - Throws:
IllegalArgumentException
- If theprefix
argument contains fewer than three charactersIOException
- If a file could not be created- See Also:
-
getModuleRootDirectories
Returns a collection of all the module root directories. A module root directory is the top-level directory of a module.- Returns:
- a collection of all the module root directories.
-
getInstallationDirectory
Returns the installation directory. In an installation, there is only one application root and its parent is the installation directory. If not an installation, then this call doesn't really make sense, but it will return the parent of the first installation root.- Returns:
- the directory
-
getModuleRootDir
Return the module root directory for the module with the given name.- Parameters:
moduleName
- the name of the module.- Returns:
- the module root directory for the module with the given name or null if not found.
-
isTestBuild
public static boolean isTestBuild()Returns true if this build was not built through the official build process, but instead was created using the "buildLocal" call.- Returns:
- true if this build was not built using the official build process.
-
inSingleJarMode
public static boolean inSingleJarMode()Checks whether or not the application is in "single jar" mode.- Returns:
- true if the application is in "single jar" mode; otherwise, false.
-
getApplicationVersion
Returns the version of this build.- Returns:
- the version of this build.
-
getBuildDate
Returns the date this build was created.- Returns:
- the date this build was created.
-
getApplicationReleaseName
Returns the release name for this build.- Returns:
- the application release name.
-
getApplicationSourceRevisions
Return the source repository revisions used in the build process or null if not applicable.- Returns:
- source revision map or null if not applicable
-
getLibraryDirectories
Returns a collection of module library directories. Library directories are optional for a module.- Returns:
- a collection of module library directories.
-
findFilesByExtensionInApplication
Returns all files within any module's data directory that end with the given extension.- Parameters:
extension
- the extension of files to be found.- Returns:
- all files within any module's data directory that end with the given extension.
-
findDataFileInAnyModule
Finds the first file that exists with the relative path in any module.- Parameters:
relativePath
- the path from the module root- Returns:
- the first file that exists with the relative path in any module.
-
findFilesByExtensionInMyModule
Returns a list of all files with the given extension that are located in the module of the calling class.- Parameters:
extension
- the filename extension for which to find file.s- Returns:
- a list of all files with the given extension that are located in the module of the calling class.
-
findFilesByExtension
Returns a list of all files with the given extension that are located in the named module.- Parameters:
moduleName
- the name of the module for which to look for files with the given extension.extension
- the filename extension for which to find file.s- Returns:
- a list of all files with the given extension that are located in the named module.
-
findModuleSubDirectories
Returns a list of all directories in any module that have the given module relative path. For example, a relative path of "foo/bar" will return all directories that are of the form<module root>/data/foo/bar
- Parameters:
relativePath
- the module relative path to search for.- Returns:
- a list of all directories in any module that have the given module relative path.
-
getModuleDataSubDirectory
public static ResourceFile getModuleDataSubDirectory(String relativePath) throws FileNotFoundException, IOException Returns the directory relative to the calling class's module's data directory.- Parameters:
relativePath
- the path relative the module's data directory- Returns:
- the directory
- Throws:
FileNotFoundException
- if the directory does not exist.IOException
- if an error occurred trying to access the directory.
-
getModuleDataSubDirectory
public static ResourceFile getModuleDataSubDirectory(String moduleName, String relativePath) throws FileNotFoundException, IOException Return the directory relative the the name module's data directory. (i.e. "/data" will be prepended to the given path)- Parameters:
moduleName
- the name of the module.relativePath
- the path relative to the module's data directory.- Returns:
- @return the directory
- Throws:
FileNotFoundException
- if the directory does not existIOException
- if an error occurred trying to access the directory.
-
getModuleSubDirectory
public static ResourceFile getModuleSubDirectory(String moduleName, String relativePath) throws FileNotFoundException, IOException Return the directory relative the the name module's directory.- Parameters:
moduleName
- the name of the module.relativePath
- the path relative to the module's root directory.- Returns:
- the directory
- Throws:
FileNotFoundException
- if the directory does not existIOException
- if an error occurred trying to access the directory.
-
getModuleDataFile
Returns the file relative to the calling class's module's data directory- Parameters:
relativeDataPath
- the path relative the to module's data directory- Returns:
- the file
- Throws:
FileNotFoundException
- if the file or module does not exist.
-
getModuleDataFile
public static ResourceFile getModuleDataFile(String moduleName, String relativeDataPath) throws FileNotFoundException Returns the file relative to the named module's data directory. (i.e. "data/" will be prepended to the give path)- Parameters:
moduleName
- the name of the module.relativeDataPath
- the path relative to the module's data directory.- Returns:
- the file
- Throws:
FileNotFoundException
- if the file does not exist.
-
getModuleFile
public static ResourceFile getModuleFile(String moduleName, String relativePath) throws FileNotFoundException Returns the file relative to the named module's directory.- Parameters:
moduleName
- the name of the module.relativePath
- the path relative to the module's data directory.- Returns:
- the file
- Throws:
FileNotFoundException
- if the file does not exist.
-
getOSFile
public static File getOSFile(String moduleName, String exactFilename) throws OSFileNotFoundException Returns the OS specific file within the given module with the given name.- Parameters:
moduleName
- the name of the moduleexactFilename
- the name of the OS file within the module.- Returns:
- the OS specific file.
- Throws:
OSFileNotFoundException
- if the file does not exist.
-
getOSFile
Returns the specified OS specific file. It is first searched for in the calling class's module. If it is not found there, it is searched for in all modules.- Parameters:
exactFilename
- the name of the OS specific file.- Returns:
- the OS specific file.
- Throws:
OSFileNotFoundException
- if the file does not exist.
-