diff --git a/Ghidra/Features/Base/src/main/java/ghidra/plugin/importer/ProgramMappingService.java b/Ghidra/Features/Base/src/main/java/ghidra/plugin/importer/ProgramMappingService.java index d4545f7081..de007208f6 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/plugin/importer/ProgramMappingService.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/plugin/importer/ProgramMappingService.java @@ -20,24 +20,24 @@ import java.net.MalformedURLException; import java.util.*; import ghidra.app.services.ProgramManager; -import ghidra.formats.gfilesystem.*; +import ghidra.formats.gfilesystem.FSRL; +import ghidra.formats.gfilesystem.FileSystemService; import ghidra.framework.main.AppInfo; import ghidra.framework.model.*; import ghidra.framework.options.Options; import ghidra.program.model.listing.Program; import ghidra.util.Msg; -import ghidra.util.SystemUtilities; import ghidra.util.datastruct.FixedSizeHashMap; import ghidra.util.exception.CancelledException; import ghidra.util.task.TaskMonitor; /** - * Provides a best-effort[1] mapping / association between Ghidra Program/DomainFile objects and - * GFilesystem files (identified by their {@link FSRL}). + * Provides a best-effort[1] mapping / association between Ghidra Program/DomainFile + * objects and GFilesystem files (identified by their {@link FSRL}). *
- * As there is no current feature that allows you to quickly query the metadata of Programs/DomainFile - * objects in the current project, finding a Program by its MD5 or by a original source location - * string is not easily possible. + * As there is no current feature that allows you to quickly query the metadata of + * Programs/DomainFile objects in the current project, finding a Program by its MD5 or by a + * original source location string is not easily possible. *
* Threadsafe. *
@@ -64,7 +64,7 @@ public class ProgramMappingService {
new FixedSizeHashMap<>(FSRL_TO_PATH_MAP_SIZE);
private ProgramMappingService() {
- // nada
+ // utils class; cannot instantiate
}
/**
@@ -90,8 +90,7 @@ public class ProgramMappingService {
public static boolean isFileOpen(FSRL fsrl) {
String expectedMD5 = fsrl.getMD5();
- List
* @param fsrl {@link FSRL} to search for
- * @return {@link DomainFile} that was previously associated via {@link #createAssociation(FSRL, DomainFile)}
- * and friends.
+ * @return {@link DomainFile} that was previously associated via
+ * {@link #createAssociation(FSRL, DomainFile)} and friends.
*/
public static DomainFile getCachedDomainFileFor(FSRL fsrl) {
- String doPath = null;
+ String path = null;
synchronized (fsrlToProjectPathMap) {
- doPath = fsrlToProjectPathMap.get(fsrl);
- if (doPath == null && fsrl.getMD5() != null) {
+ path = fsrlToProjectPathMap.get(fsrl);
+ if (path == null && fsrl.getMD5() != null) {
fsrl = fsrl.withMD5(null);
- doPath = fsrlToProjectPathMap.get(fsrl);
+ path = fsrlToProjectPathMap.get(fsrl);
}
}
- if (doPath != null) {
- DomainFile domainFile = AppInfo.getActiveProject().getProjectData().getFile(doPath);
- if (domainFile == null) {
- // The domainFile will be null if the cached path is no longer valid. Remove
- // the stale path from the cache.
- synchronized (fsrlToProjectPathMap) {
- if (SystemUtilities.isEqual(fsrlToProjectPathMap.get(fsrl), doPath)) {
- fsrlToProjectPathMap.remove(fsrl);
- }
- }
- }
- return domainFile;
- }
- return null;
+ if (path == null) {
+ return null;
+ }
+
+ DomainFile domainFile = getProjectFile(path);
+ if (domainFile == null) {
+ // The domainFile will be null if the cached path is no longer valid. Remove
+ // the stale path from the cache.
+ synchronized (fsrlToProjectPathMap) {
+ if (Objects.equals(fsrlToProjectPathMap.get(fsrl), path)) {
+ fsrlToProjectPathMap.remove(fsrl);
+ }
+ }
+ }
+ return domainFile;
}
/**
@@ -245,7 +245,8 @@ public class ProgramMappingService {
* must release the consumer when done.
* @param programManager {@link ProgramManager} that will be used to open DomainFiles
* if necessary.
- * @param openState one of {@link ProgramManager#OPEN_VISIBLE}, {@link ProgramManager#OPEN_HIDDEN}, {@link ProgramManager#OPEN_VISIBLE}
+ * @param openState one of {@link ProgramManager#OPEN_VISIBLE},
+ * {@link ProgramManager#OPEN_HIDDEN}, {@link ProgramManager#OPEN_VISIBLE}
* @return {@link Program} which was imported from the specified FSRL, or null if not found.
*/
public static Program findMatchingProgramOpenIfNeeded(FSRL fsrl, Object consumer,
@@ -265,7 +266,8 @@ public class ProgramMappingService {
* must release the consumer when done.
* @param programManager {@link ProgramManager} that will be used to open DomainFiles
* if necessary.
- * @param openState one of {@link ProgramManager#OPEN_VISIBLE}, {@link ProgramManager#OPEN_HIDDEN}, {@link ProgramManager#OPEN_VISIBLE}
+ * @param openState one of {@link ProgramManager#OPEN_VISIBLE},
+ * {@link ProgramManager#OPEN_HIDDEN}, {@link ProgramManager#OPEN_VISIBLE}
* @return {@link Program} which was imported from the specified FSRL, or null if not found.
*/
public static Program findMatchingProgramOpenIfNeeded(FSRL fsrl, DomainFile domainFile,
@@ -306,7 +308,7 @@ public class ProgramMappingService {
// use a temp consumer to hold the domainObject open because the caller-supplied
// consumer might already have been used to open one of the files we are querying.
Object tmpConsumer = new Object();
- List