GP-3852: Preventing installation of extension source directories

This commit is contained in:
dragonmacher 2023-09-20 18:01:14 -04:00
parent 0f7300aac0
commit b639053178
2 changed files with 23 additions and 15 deletions

View file

@ -166,6 +166,18 @@ public class ExtensionTableProvider extends DialogComponentProvider {
private boolean installExtensions(List<File> files) { private boolean installExtensions(List<File> files) {
boolean didInstall = false; boolean didInstall = false;
for (File file : files) { for (File file : files) {
// A sanity check for users that try to install an extension from a source folder
// instead of a fully built extension.
if (new File(file, "build.gradle").isFile()) {
Msg.showWarn(this, null, "Invalid Extension", "The selected extension folder " +
"contains a 'build.gradle' file.\nGhidra does not support installing " +
"extensions in source form.\nPlease build the extension and install its zip " +
"file.");
didInstall = false;
continue;
}
boolean success = ExtensionUtils.install(file); boolean success = ExtensionUtils.install(file);
didInstall |= success; didInstall |= success;
} }
@ -200,7 +212,7 @@ public class ExtensionTableProvider extends DialogComponentProvider {
} }
/** /**
* Filter for a {@link GhidraFileChooser} that restricts selection to those files that are * Filter for a {@link GhidraFileChooser} that restricts selection to those files that are
* Ghidra Extensions (zip files with an extension.properties file) or folders. * Ghidra Extensions (zip files with an extension.properties file) or folders.
*/ */
private class ExtensionFileFilter implements GhidraFileFilter { private class ExtensionFileFilter implements GhidraFileFilter {

View file

@ -54,9 +54,9 @@ import utility.application.ApplicationLayout;
* </ul> * </ul>
* *
* <p> * <p>
* Extensions may be installed/uninstalled by users at runtime, using the * Extensions may be installed/uninstalled by users at runtime, using the
* {@link ExtensionTableProvider}. Installation consists of unzipping the extension archive to an * {@link ExtensionTableProvider}. Installation consists of unzipping the extension archive to an
* installation folder, currently <code>{ghidra user settings dir}/Extensions</code>. To uninstall, * installation folder, currently <code>{ghidra user settings dir}/Extensions</code>. To uninstall,
* the unpacked folder is simply removed. * the unpacked folder is simply removed.
*/ */
public class ExtensionUtils { public class ExtensionUtils {
@ -71,7 +71,7 @@ public class ExtensionUtils {
private static final Logger log = LogManager.getLogger(ExtensionUtils.class); private static final Logger log = LogManager.getLogger(ExtensionUtils.class);
/** /**
* Performs extension maintenance. This should be called at startup, before any plugins or * Performs extension maintenance. This should be called at startup, before any plugins or
* extension points are loaded. * extension points are loaded.
*/ */
public static void initializeExtensions() { public static void initializeExtensions() {
@ -87,7 +87,7 @@ public class ExtensionUtils {
/** /**
* Gets all known extensions that have not been marked for removal. * Gets all known extensions that have not been marked for removal.
* *
* @return set of installed extensions * @return set of installed extensions
*/ */
public static Set<ExtensionDetails> getActiveInstalledExtensions() { public static Set<ExtensionDetails> getActiveInstalledExtensions() {
@ -148,8 +148,8 @@ public class ExtensionUtils {
/** /**
* Returns all archive extensions. These are all the extensions found in * Returns all archive extensions. These are all the extensions found in
* {@link ApplicationLayout#getExtensionArchiveDir}. This are added to an installation as * {@link ApplicationLayout#getExtensionArchiveDir}. This are added to an installation as
* part of the build processes. * part of the build processes.
* <p> * <p>
* Archived extensions may be zip files and directories. * Archived extensions may be zip files and directories.
* *
@ -221,7 +221,7 @@ public class ExtensionUtils {
} }
/** /**
* Installs the given extension file. This can be either an archive (zip) or a directory that * Installs the given extension file. This can be either an archive (zip) or a directory that
* contains an extension.properties file. * contains an extension.properties file.
* *
* @param file the extension to install * @param file the extension to install
@ -515,10 +515,6 @@ public class ExtensionUtils {
if (file.isDirectory() && file.canRead()) { if (file.isDirectory() && file.canRead()) {
File propertyFile = new File(file, PROPERTIES_FILE_NAME); File propertyFile = new File(file, PROPERTIES_FILE_NAME);
if (propertyFile.isFile()) { if (propertyFile.isFile()) {
if (new File(file, "build.gradle").isFile()) {
log.error("Extension source directories are not valid extensions");
return null;
}
return tryToLoadExtensionFromProperties(propertyFile); return tryToLoadExtensionFromProperties(propertyFile);
} }
} }
@ -580,7 +576,7 @@ public class ExtensionUtils {
* Searching the child directories of a directory allows clients to pick an extension parent * Searching the child directories of a directory allows clients to pick an extension parent
* directory that contains multiple extension directories. * directory that contains multiple extension directories.
* *
* @param installDir the directory that contains extension subdirectories * @param installDir the directory that contains extension subdirectories
* @return list of extension.properties files * @return list of extension.properties files
*/ */
private static List<File> findExtensionPropertyFiles(File installDir) { private static List<File> findExtensionPropertyFiles(File installDir) {
@ -601,7 +597,7 @@ public class ExtensionUtils {
} }
/** /**
* Returns an extension.properties or extension.properties.uninstalled file if the given * Returns an extension.properties or extension.properties.uninstalled file if the given
* directory contains one. * directory contains one.
* *
* @param dir the directory to search * @param dir the directory to search