Class ExtensionUtils
java.lang.Object
ghidra.framework.plugintool.dialog.ExtensionUtils
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, currently
Ghidra/Extensions. To uninstall, the unpacked folder is simply removed.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidAttempts to delete any extension directories that do not contain a Module.manifest file.static ExtensionDetailsExtracts properties from a Java Properties file to create anExtensionDetailsobject.static ExtensionDetailscreateExtensionDetailsFromPropertyFile(ResourceFile resourceFile) Extracts information from a Java Properties file to create anExtensionDetailsobject.static ExtensionDetailsExtracts information from a Java Properties file to create anExtensionDetailsobject.static List<ResourceFile>findExtensionPropertyFiles(ResourceFile sourceFile, boolean includeUninstalled) Returns a list of files representing all theextension.propertiesfiles found under a given directory.static voidfindFilesWithName(File root, String fileName, List<File> foundFiles) static Set<ExtensionDetails>Returns all archived extensions.static Set<ExtensionDetails>Returns a set of all extensions known to Ghidra, represented byExtensionDetailsobjects.static Set<ExtensionDetails>Finds any extensions that have been installed since the last time a given tool was launched.static Set<ExtensionDetails>getInstalledExtensions(boolean includeUninstalled) Returns all installed extensions.static PropertiesgetPropertiesFromArchive(File file) Given a zip file, returns thePropertiesdefined in the embedded extension.properties file.static booleaninstall(ResourceFile rFile) Installs the given extension file.static booleaninstall(ExtensionDetails extension, boolean overwrite) Installs the given extension.static booleanisExtension(ResourceFile rFile) Returns true if the given file or directory is a valid ghidra extension.static booleanisInstalled(String extensionName) Returns true if an extension with the given name exists in the install folder.static booleanReturns true if the given file is a valid .zip archive.static booleanremoveStateFiles(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 booleanrestoreStateFiles(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 booleanuninstall(ExtensionDetails extension) Uninstalls a given extension.static booleanvalidateExtensionVersion(String extensionVersion) Compares the given extension version to the current Ghidra version.
-
Field Details
-
PROPERTIES_FILE_NAME
-
PROPERTIES_FILE_NAME_UNINSTALLED
-
-
Constructor Details
-
ExtensionUtils
public ExtensionUtils()
-
-
Method Details
-
getExtensions
Returns a set of all extensions known to Ghidra, represented byExtensionDetailsobjects. 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 Set<ExtensionDetails> getInstalledExtensions(boolean includeUninstalled) throws ExtensionException Returns all installed extensions. These are all the extensions found inApplicationLayout.getExtensionInstallationDirs().- 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
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
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
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
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
Uninstalls a given extension.- Parameters:
extension- the extension to uninstall- Returns:
- true if successfully uninstalled
-
validateExtensionVersion
Compares the given extension version to the current Ghidra version. If they are different, then the user will be prompted to confirm the installation. This method will return true if the versions match or the user has chosen to install anyway.- Parameters:
extensionVersion- the extension version- Returns:
- true if the versions match or the user has chosen to install anyway
-
isExtension
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
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 List<ResourceFile> findExtensionPropertyFiles(ResourceFile sourceFile, boolean includeUninstalled) Returns a list of files representing all theextension.propertiesfiles 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
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
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
- Parameters:
root- the starting directory to search recursivelyfileName- the file name search forfoundFiles- list of all matching files
-
getPropertiesFromArchive
Given a zip file, returns thePropertiesdefined 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
Extracts information from a Java Properties file to create anExtensionDetailsobject.- Parameters:
file- the file to parse- Returns:
- a new extension details object
-
getExtensionsInstalledSinceLastToolLaunch
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
Extracts information from a Java Properties file to create anExtensionDetailsobject.- 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. -
createExtensionDetailsFromProperties
Extracts properties from a Java Properties file to create anExtensionDetailsobject.- Parameters:
props- the java properties object- Returns:
- a new extension details object
-