mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-06 03:50:02 +02:00
GT-3547 - Patch dir fix - review fixes
This commit is contained in:
parent
3dced733df
commit
87bda2b34d
14 changed files with 149 additions and 531 deletions
|
@ -40,11 +40,6 @@ public class Preferences {
|
|||
*/
|
||||
private final static String USER_PLUGIN_PATH = "UserPluginPath";
|
||||
|
||||
/**
|
||||
* Preference name of the user plugin jar directory.
|
||||
*/
|
||||
public final static String USER_PLUGIN_JAR_DIRECTORY = "UserPluginJarDirectory";
|
||||
|
||||
/**
|
||||
* Preference name for the last opened archive directory.
|
||||
*/
|
||||
|
@ -194,6 +189,8 @@ public class Preferences {
|
|||
* <p>
|
||||
* Note: all <code>getProperty(...)</code> methods will first check {@link System#getProperty(String)}
|
||||
* for a value first. This allows users to override preferences from the command-line.
|
||||
* @param name the property name
|
||||
* @return the current property value; null if not set
|
||||
*/
|
||||
public static String getProperty(String name) {
|
||||
// prefer system properties, which enables uses to override preferences from the command-line
|
||||
|
@ -210,6 +207,9 @@ public class Preferences {
|
|||
* <p>
|
||||
* Note: all <code>getProperty(...)</code> methods will first check {@link System#getProperty(String)}
|
||||
* for a value first. This allows users to override preferences from the command-line.
|
||||
* @param name the property name
|
||||
* @param defaultValue the default value
|
||||
* @return the property value; default value if not set
|
||||
*
|
||||
* @see #getProperty(String, String, boolean)
|
||||
*/
|
||||
|
@ -289,6 +289,7 @@ public class Preferences {
|
|||
|
||||
/**
|
||||
* Get the filename that will be used in the store() method.
|
||||
* @return the filename
|
||||
*/
|
||||
public static String getFilename() {
|
||||
return filename;
|
||||
|
@ -297,7 +298,7 @@ public class Preferences {
|
|||
/**
|
||||
* Set the filename so that when the store() method is called, the
|
||||
* preferences are written to this file.
|
||||
* @param name
|
||||
* @param name the filename
|
||||
*/
|
||||
public static void setFilename(String name) {
|
||||
filename = name;
|
||||
|
@ -305,6 +306,7 @@ public class Preferences {
|
|||
|
||||
/**
|
||||
* Store the preferences in a file for the current filename.
|
||||
* @return true if the file was written
|
||||
* @throws RuntimeException if the preferences filename was not set
|
||||
*/
|
||||
public static boolean store() {
|
||||
|
@ -346,6 +348,7 @@ public class Preferences {
|
|||
/**
|
||||
* Return the paths in the UserPluginPath property.
|
||||
* Return zero length array if this property is not set.
|
||||
* @return the paths
|
||||
*
|
||||
*/
|
||||
public static String[] getPluginPaths() {
|
||||
|
@ -359,6 +362,7 @@ public class Preferences {
|
|||
|
||||
/**
|
||||
* Set the paths to be used as the UserPluginPath property.
|
||||
* @param paths the paths
|
||||
*/
|
||||
public static void setPluginPaths(String[] paths) {
|
||||
if (paths == null || paths.length == 0) {
|
||||
|
@ -376,55 +380,6 @@ public class Preferences {
|
|||
properties.setProperty(USER_PLUGIN_PATH, sb.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the plugin path property.
|
||||
* @param pathProperty A string of paths separated by {@link File#pathSeparator} characters
|
||||
*/
|
||||
public static void setPluginPathProperty(String pathProperty) {
|
||||
properties.setProperty(USER_PLUGIN_PATH, pathProperty);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append path to the plugin path.
|
||||
* @param path the plugin path to add
|
||||
*/
|
||||
public static void addPluginPath(String path) {
|
||||
List<String> list = getPluginPathList();
|
||||
if (list == null) {
|
||||
setPluginPaths(new String[] { path });
|
||||
return;
|
||||
}
|
||||
if (!list.contains(path)) {
|
||||
list.add(path);
|
||||
String[] p = new String[list.size()];
|
||||
setPluginPaths(list.toArray(p));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append paths to the plugin path.
|
||||
* @param paths the plugin paths to add
|
||||
*/
|
||||
public static void addPluginPaths(String[] paths) {
|
||||
List<String> list = getPluginPathList();
|
||||
if (list == null) {
|
||||
setPluginPaths(paths);
|
||||
return;
|
||||
}
|
||||
boolean listChanged = false;
|
||||
for (String path : paths) {
|
||||
if (!list.contains(path)) {
|
||||
list.add(path);
|
||||
listChanged = true;
|
||||
}
|
||||
}
|
||||
// update plugin path property only if we added a path to the list
|
||||
if (listChanged) {
|
||||
String[] p = new String[list.size()];
|
||||
setPluginPaths(list.toArray(p));
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> getPluginPathList() {
|
||||
String path = properties.getProperty(USER_PLUGIN_PATH);
|
||||
if (path == null) {
|
||||
|
|
|
@ -17,8 +17,7 @@ package ghidra.util.classfinder;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.regex.Matcher;
|
||||
|
@ -28,7 +27,9 @@ import org.apache.commons.io.FilenameUtils;
|
|||
|
||||
import generic.jar.ResourceFile;
|
||||
import ghidra.framework.Application;
|
||||
import ghidra.framework.preferences.Preferences;
|
||||
import ghidra.util.Msg;
|
||||
import ghidra.util.SystemUtilities;
|
||||
import ghidra.util.exception.CancelledException;
|
||||
import ghidra.util.task.TaskMonitor;
|
||||
import utility.application.ApplicationLayout;
|
||||
|
@ -46,20 +47,13 @@ class ClassJar extends ClassLocation {
|
|||
Pattern.compile(".*/(.*)/(?:lib|build/libs)/(.+).jar");
|
||||
|
||||
private static final String PATCH_DIR_PATH_FORWARD_SLASHED = getPatchDirPath();
|
||||
|
||||
private static String getPatchDirPath() {
|
||||
ApplicationLayout layout = Application.getApplicationLayout();
|
||||
ResourceFile installDir = layout.getApplicationInstallationDir();
|
||||
ResourceFile patchDir = new ResourceFile(installDir, "Ghidra/patch");
|
||||
String patchPath = patchDir.getAbsolutePath();
|
||||
String forwardSlashed = patchPath.replaceAll("\\\\", "/");
|
||||
return forwardSlashed;
|
||||
}
|
||||
private static final Set<String> USER_PLUGIN_PATHS = loadUserPluginPaths();
|
||||
|
||||
private String path;
|
||||
|
||||
ClassJar(String path, TaskMonitor monitor) throws CancelledException {
|
||||
this.path = path;
|
||||
loadUserPluginPaths();
|
||||
|
||||
scanJar(monitor);
|
||||
}
|
||||
|
@ -105,10 +99,22 @@ class ClassJar extends ClassLocation {
|
|||
if (pathName.contains("ExternalLibraries")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// Dev and Production Mode
|
||||
//
|
||||
String forwardSlashedPathName = pathName.replaceAll("\\\\", "/");
|
||||
if (isUserPluginJar(forwardSlashedPathName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (SystemUtilities.isInDevelopmentMode()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Production Mode - allow users to enter code in the 'patch' directory
|
||||
//
|
||||
String forwardSlashedPathName = pathName.replaceAll("\\\\", "/");
|
||||
if (isPatchJar(forwardSlashedPathName)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -123,6 +129,10 @@ class ClassJar extends ClassLocation {
|
|||
return true;
|
||||
}
|
||||
|
||||
private static boolean isUserPluginJar(String pathName) {
|
||||
return USER_PLUGIN_PATHS.contains(pathName);
|
||||
}
|
||||
|
||||
// Note: the path is expected to be using forward slashes
|
||||
private static boolean isPatchJar(String pathName) {
|
||||
String jarDirectory = FilenameUtils.getFullPathNoEndSeparator(pathName);
|
||||
|
@ -168,4 +178,27 @@ class ClassJar extends ClassLocation {
|
|||
public String toString() {
|
||||
return path;
|
||||
}
|
||||
|
||||
private static String getPatchDirPath() {
|
||||
ApplicationLayout layout = Application.getApplicationLayout();
|
||||
ResourceFile patchDir = layout.getPatchDir();
|
||||
if (patchDir == null) {
|
||||
return "<no patch dir>"; // not in a distribution
|
||||
}
|
||||
String patchPath = patchDir.getAbsolutePath();
|
||||
String forwardSlashed = patchPath.replaceAll("\\\\", "/");
|
||||
return forwardSlashed;
|
||||
}
|
||||
|
||||
private static Set<String> loadUserPluginPaths() {
|
||||
Set<String> result = new HashSet<>();
|
||||
String[] paths = Preferences.getPluginPaths();
|
||||
for (String pathName : paths) {
|
||||
// note: lower case because our client uses lower case for paths
|
||||
String forwardSlashed = pathName.replaceAll("\\\\", "/").toLowerCase();
|
||||
result.add(forwardSlashed);
|
||||
}
|
||||
return Collections.unmodifiableSet(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue