Class ExtensionUtils
- java.lang.Object
-
- ghidra.framework.plugintool.dialog.ExtensionUtils
-
public class ExtensionUtils extends java.lang.Object
Utility class for managing Ghidra Extensions.Extensions are defined as any archive or folder that contains an
extension.properties
file. This properties file can contain the following attributes:- name (required)
- description
- author
- createdOn (format: mm/dd/yyyy)
ExtensionTableProvider
. Installation consists of unzipping the extension archive to an installation folder, currentlyGhidra/Extensions
. To uninstall, the unpacked folder is simply removed.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
PROPERTIES_FILE_NAME
static java.lang.String
PROPERTIES_FILE_NAME_UNINSTALLED
-
Constructor Summary
Constructors Constructor Description ExtensionUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
cleanupUninstalledExtensions()
Attempts to delete any extension directories that do not contain a Module.manifest file.static ExtensionDetails
createExtensionDetailsFromProperties(java.util.Properties props)
Extracts properties from a Java Properties file to create anExtensionDetails
object.static ExtensionDetails
createExtensionDetailsFromPropertyFile(ResourceFile resourceFile)
Extracts information from a Java Properties file to create anExtensionDetails
object.static ExtensionDetails
createExtensionDetailsFromPropertyFile(java.io.File file)
Extracts information from a Java Properties file to create anExtensionDetails
object.static java.util.List<ResourceFile>
findExtensionPropertyFiles(ResourceFile sourceFile, boolean includeUninstalled)
Returns a list of files representing all theextension.properties
files found under a given directory.static void
findFilesWithName(java.io.File root, java.lang.String fileName, java.util.List<java.io.File> foundFiles)
static java.util.Set<ExtensionDetails>
getArchivedExtensions()
Returns all archived extensions.static java.util.Set<ExtensionDetails>
getExtensions()
Returns a set of all extensions known to Ghidra, represented byExtensionDetails
objects.static java.util.Set<ExtensionDetails>
getExtensionsInstalledSinceLastToolLaunch(PluginTool tool)
Finds any extensions that have been installed since the last time a given tool was launched.static java.util.Set<ExtensionDetails>
getInstalledExtensions(boolean includeUninstalled)
Returns all installed extensions.static java.util.Properties
getPropertiesFromArchive(java.io.File file)
Given a zip file, returns theProperties
defined in the embedded extension.properties file.static boolean
install(ResourceFile rFile)
Installs the given extension file.static boolean
install(ExtensionDetails extension, boolean overwrite)
Installs the given extension.static boolean
isExtension(ResourceFile rFile)
Returns true if the given file or directory is a valid ghidra extension.static boolean
isInstalled(java.lang.String extensionName)
Returns true if an extension with the given name exists in the install folder.static boolean
isZip(java.io.File file)
Returns true if the given file is a valid .zip archive.static boolean
removeStateFiles(ExtensionDetails extension)
Recursively searches a given directory for any module manifest and extension properties files that are in an installed state and converts them to an uninstalled state.static boolean
restoreStateFiles(java.io.File rootDir)
Recursively searches a given directory for any module manifest and extension properties files that are in an uninstalled state and restores them.static boolean
uninstall(ExtensionDetails extension)
Uninstalls a given extension.
-
-
-
Method Detail
-
getExtensions
public static java.util.Set<ExtensionDetails> getExtensions() throws ExtensionException
Returns a set of all extensions known to Ghidra, represented byExtensionDetails
objects. This will include all installed AND archived extensions.Note that this method will only look in the known extension folder locations:
If users install extensions from other locations, the installed version of the extension will be known, but the source archive location will not be retained.- Returns:
- list of unique extensions
- Throws:
ExtensionException
- if extensions cannot be retrieved
-
getInstalledExtensions
public static java.util.Set<ExtensionDetails> getInstalledExtensions(boolean includeUninstalled) throws ExtensionException
Returns all installed extensions. These are all the extensions found inApplicationLayout.getExtensionInstallationDir()
.- Parameters:
includeUninstalled
- if true, include extensions that have been marked for removal- Returns:
- set of installed extensions
- Throws:
ExtensionException
- if the extension details cannot be retrieved
-
getArchivedExtensions
public static java.util.Set<ExtensionDetails> getArchivedExtensions() throws ExtensionException
Returns all archived extensions. These are all the extensions found inApplicationLayout.getExtensionArchiveDir()
.- Returns:
- set of archived extensions
- Throws:
ExtensionException
- if the extension details cannot be retrieved
-
isInstalled
public static boolean isInstalled(java.lang.String extensionName)
Returns true if an extension with the given name exists in the install folder.- Parameters:
extensionName
- the name of the extension- Returns:
- true if installed
-
install
public static boolean install(ResourceFile rFile)
Installs the given extension file. This can be either an archive (zip) or a directory that contains an extension.properties file.- Parameters:
rFile
- the extension to install- Returns:
- true if the extension was successfully installed
-
install
public static boolean install(ExtensionDetails extension, boolean overwrite)
Installs the given extension.- Parameters:
extension
- the extension to installoverwrite
- if true, any existing extension will be overwritten- Returns:
- true if the install was successful
-
uninstall
public static boolean uninstall(ExtensionDetails extension)
Uninstalls a given extension.- Parameters:
extension
- the extension to uninstall- Returns:
- true if successfully uninstalled
-
isExtension
public static boolean isExtension(ResourceFile rFile) throws ExtensionException
Returns true if the given file or directory is a valid ghidra extension.Note: This means that the zip or directory contains an extension.properties file.
- Parameters:
rFile
- the resource zip or directory to inspect- Returns:
- true if the given file represents a valid extension
- Throws:
ExtensionException
- if there's an error processing a zip file
-
isZip
public static boolean isZip(java.io.File file) throws ExtensionException
Returns true if the given file is a valid .zip archive.- Parameters:
file
- the file to test- Returns:
- true if file is a valid zip
- Throws:
ExtensionException
- if there's an error reading the zip file
-
findExtensionPropertyFiles
public static java.util.List<ResourceFile> findExtensionPropertyFiles(ResourceFile sourceFile, boolean includeUninstalled)
Returns a list of files representing all theextension.properties
files found under a given directory. This will ONLY search the given directory and its immediate children. The conops are as follows:- If sourceFile is a directory and it contains an extension.properties file, then that file is returned
- If sourceFile does not contain an extension.properties file, then any immediate directories are searched (ignoring Skeleton directory)
Note: This will NOT search zip files. If you have a zip, call
getPropertiesFromArchive(File)
instead.- Parameters:
sourceFile
- the directory to inspectincludeUninstalled
- if true, include extensions that have been marked for removal- Returns:
- list of extension.properties files
-
removeStateFiles
public static boolean removeStateFiles(ExtensionDetails extension)
Recursively searches a given directory for any module manifest and extension properties files that are in an installed state and converts them to an uninstalled state. Specifically, the following will be renamed:- Module.manifest to Module.manifest.uninstalled
- extension.properties = extension.properties.uninstalled
- Parameters:
extension
- the extension to modify- Returns:
- false if any renames fail
-
restoreStateFiles
public static boolean restoreStateFiles(java.io.File rootDir)
Recursively searches a given directory for any module manifest and extension properties files that are in an uninstalled state and restores them. Specifically, the following will be renamed:- Module.manifest.uninstalled to Module.manifest
- extension.properties.uninstalled = extension.properties
- Parameters:
rootDir
- the directory to search- Returns:
- false if any renames fail
-
findFilesWithName
public static void findFilesWithName(java.io.File root, java.lang.String fileName, java.util.List<java.io.File> foundFiles)
- Parameters:
root
- the starting directory to search recursivelyfileName
- the file name search forfoundFiles
- list of all matching files
-
getPropertiesFromArchive
public static java.util.Properties getPropertiesFromArchive(java.io.File file) throws ExtensionException
Given a zip file, returns theProperties
defined in the embedded extension.properties file.- Parameters:
file
- the extension archive file- Returns:
- the properties file, or null if doesn't exist
- Throws:
ExtensionException
- if there's a problem unpacking the zip file
-
createExtensionDetailsFromPropertyFile
public static ExtensionDetails createExtensionDetailsFromPropertyFile(java.io.File file)
Extracts information from a Java Properties file to create anExtensionDetails
object.- Parameters:
file
- the file to parse- Returns:
- a new extension details object
-
getExtensionsInstalledSinceLastToolLaunch
public static java.util.Set<ExtensionDetails> getExtensionsInstalledSinceLastToolLaunch(PluginTool tool)
Finds any extensions that have been installed since the last time a given tool was launched.- Parameters:
tool
- the tool to check- Returns:
- set of new extensions
-
createExtensionDetailsFromPropertyFile
public static ExtensionDetails createExtensionDetailsFromPropertyFile(ResourceFile resourceFile)
Extracts information from a Java Properties file to create anExtensionDetails
object.- Parameters:
resourceFile
- the resource file file to parse- Returns:
- a new extension details object
-
cleanupUninstalledExtensions
public static void cleanupUninstalledExtensions()
Attempts to delete any extension directories that do not contain a Module.manifest file. This indicates that the extension was slated to be uninstalled by the user.- See Also:
ExtensionTableModel#uninstallExtension
-
createExtensionDetailsFromProperties
public static ExtensionDetails createExtensionDetailsFromProperties(java.util.Properties props)
Extracts properties from a Java Properties file to create anExtensionDetails
object.- Parameters:
props
- the java properties object- Returns:
- a new extension details object
-
-