Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-4165 openCachedProgram improvement for program upgrade condition

ghidra10aa96ce89213
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/progmgr/ProgramManagerPlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/progmgr/ProgramManagerPlugin.java
index ec510d6b57..b3c5d69e94 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/progmgr/ProgramManagerPlugin.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/progmgr/ProgramManagerPlugin.java
@@ -304,11 +304,9 @@ public class ProgramManagerPlugin extends Plugin implements ProgramManager, Opti
program = programMgr.getOpenProgram(locator);
if (program != null) {
program.addConsumer(consumer);
- if (!program.isChanged()) {
- // Don't put modified programs into the cache.
- // NOTE: This will prevent upgraded programs from being added to the cache
- // which are already open in the tool. This could be improved if we could
- // distinguish between upgrade and non-upgrade changes.
+ if (!program.isChanged() || ProgramUtilities.isChangedWithUpgradeOnly(program)) {
+ // Don't put modified programs into the cache unless the only change
+ // corresponds to an upgrade during its instantiation.
programCache.put(locator, program);
}
return program;
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/ProgramUtilities.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/ProgramUtilities.java
index ccfbedc131..e19e230502 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/ProgramUtilities.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/ProgramUtilities.java
@@ -15,6 +15,8 @@
*/
package ghidra.program.util;
+import java.util.*;
+
import ghidra.program.model.address.Address;
import ghidra.program.model.listing.*;
import ghidra.program.model.mem.MemoryAccessException;
@@ -23,8 +25,6 @@ import ghidra.util.*;
import ghidra.util.exception.DuplicateNameException;
import ghidra.util.exception.InvalidInputException;
-import java.util.*;
-
/**
* General utility class that provides convenience methods
* to deal with Program objects.
@@ -173,4 +173,18 @@ public class ProgramUtilities {
Msg.error(ProgramUtilities.class, "Unexpected Exception", e);
}
}
+
+ /**
+ * Determine if a program has a single unsaved change which corresponds to an
+ * upgrade which occured during instantiation.
+ * @param program the program to be checked for an unsaved upgrade condition.
+ * @return true if program upgraded and has not been saved, else false
+ */
+ public static boolean isChangedWithUpgradeOnly(Program program) {
+ // The only non-undoable change is an upgrade that occurs during instantiation
+ if (!program.isChanged()) {
+ return false;
+ }
+ return !program.canUndo();
+ }
}