Class Application

java.lang.Object
ghidra.framework.Application

public class Application extends Object
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.initalizeApplication(layout, configuration);
 
  • 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

      public 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.
      Parameters:
      logFile - application log file, if null the default application.log will be stored within the user's application settings directory
      scriptLogFile - 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

      public static ApplicationLayout getApplicationLayout()
    • getModuleContainingResourceFile

      public static ResourceFile getModuleContainingResourceFile(ResourceFile file)
    • getModuleContainingClass

      public static ResourceFile getModuleContainingClass(String className)
    • getModuleContainingClass

      public static ResourceFile getModuleContainingClass(Class<?> c)
    • getMyModuleRootDirectory

      public static ResourceFile 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

      public static String getName()
      Returns the name of the application.
      Returns:
      the name of the application.
    • getApplicationProperty

      public static String getApplicationProperty(String propertyName)
      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

      public static Collection<ResourceFile> 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

      public static ResourceFile 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 via getApplicationRootDirectories().

      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

      public static File getUserSettingsDirectory()
      Returns the File containing the user configuration settings for this application.
      Returns:
      the File containing the user configuration settings for this application.
    • getUserSettingsFiles

      public static List<File> 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.
      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

      public static File 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

      public static File 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

      public static File createTempFile(String prefix, String suffix) throws IOException
      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 long
      suffix - The suffix string to be used in generating the file's name; may be null, in which case the suffix ".tmp" will be used
      Returns:
      A File denoting a newly-created empty file
      Throws:
      IllegalArgumentException - If the prefix argument contains fewer than three characters
      IOException - If a file could not be created
      See Also:
    • getModuleRootDirectories

      public static Collection<ResourceFile> 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

      public static ResourceFile 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

      public static ResourceFile getModuleRootDir(String moduleName)
      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

      public static String getApplicationVersion()
      Returns the version of this build.
      Returns:
      the version of this build.
    • getBuildDate

      public static String getBuildDate()
      Returns the date this build was created.
      Returns:
      the date this build was created.
    • getApplicationReleaseName

      public static String getApplicationReleaseName()
      Returns the release name for this build.
      Returns:
      the application release name.
    • getApplicationSourceRevisions

      public static Map<String,String> 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

      public static Collection<ResourceFile> getLibraryDirectories()
      Returns a collection of module library directories. Library directories are optional for a module.
      Returns:
      a collection of module library directories.
    • findFilesByExtensionInApplication

      public static List<ResourceFile> findFilesByExtensionInApplication(String extension)
      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

      public static ResourceFile findDataFileInAnyModule(String relativePath)
      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

      public 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.
      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

      public 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.
      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

      public static List<ResourceFile> findModuleSubDirectories(String relativePath)
      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:
      Throws:
      FileNotFoundException - if the directory does not exist
      IOException - 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 exist
      IOException - if an error occurred trying to access the directory.
    • getModuleDataFile

      public static ResourceFile getModuleDataFile(String relativeDataPath) throws FileNotFoundException
      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 module
      exactFilename - the name of the OS file within the module.
      Returns:
      the OS specific file.
      Throws:
      OSFileNotFoundException - if the file does not exist.
    • getOSFile

      public static File getOSFile(String exactFilename) throws OSFileNotFoundException
      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.