Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-0 Eliminated Open/Close Tool Event and corrected ProgramSaveManager.canClose failure to save

ghidra135880027aedc
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/events/CloseProgramPluginEvent.java b/Ghidra/Features/Base/src/main/java/ghidra/app/events/CloseProgramPluginEvent.java
index 36aff6b3b6..d039488aa6 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/events/CloseProgramPluginEvent.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/events/CloseProgramPluginEvent.java
@@ -18,16 +18,11 @@ package ghidra.app.events;
import java.lang.ref.WeakReference;
import ghidra.framework.plugintool.PluginEvent;
-import ghidra.framework.plugintool.ToolEventName;
import ghidra.program.model.listing.Program;
/**
- * Event for telling a tool to open a program
- * <p>
- * This event shares a common tool-event name with the {@link OpenProgramPluginEvent}
- * so that they have a single shared tool connection.
+ * Event for telling a tool to close a program
*/
-@ToolEventName(OpenProgramPluginEvent.TOOL_EVENT_NAME) // this allows the event to be considered for tool connection
public class CloseProgramPluginEvent extends PluginEvent {
static final String NAME = "Close Program";
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/events/DualProgramLocationPluginEvent.java b/Ghidra/Features/Base/src/main/java/ghidra/app/events/DualProgramLocationPluginEvent.java
deleted file mode 100644
index 9b45a30013..0000000000
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/events/DualProgramLocationPluginEvent.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/* ###
- * IP: GHIDRA
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package ghidra.app.events;
-
-import ghidra.framework.plugintool.PluginEvent;
-import ghidra.framework.plugintool.ToolEventName;
-import ghidra.program.model.listing.Program;
-import ghidra.program.util.ProgramLocation;
-
-/**
- * This plugin event class provides program location information for
- * plugins that send information to two or more tools containing associated addresses.
- */
-@ToolEventName(DualProgramLocationPluginEvent.NAME) // this allows the event to be considered for tool connection
-public final class DualProgramLocationPluginEvent extends PluginEvent {
-
- /**
- * Name of this plugin event.
- */
- public static final String NAME = "DualProgramLocation";
-
- private ProgramLocation loc;
- private String programName;
-
- /**
- * Construct a new DualProgramLocationPluginEvent.
- * @param src the name of the plugin that generated this event.
- * @param loc the ProgramLocation object that contains the new location.
- * @param programName the name of the program for which the loc object refers.
- */
- public DualProgramLocationPluginEvent(String src, ProgramLocation loc, String programName) {
- super(src, NAME);
- this.loc = loc;
- this.programName = programName;
- }
-
- /**
- * Construct a new DualProgramLocationPluginEvent.
- * @param src the name of the plugin that generated this event.
- * @param loc the ProgramLocation object that contains the new location.
- * @param program the program for which the loc object refers.
- */
- public DualProgramLocationPluginEvent(String src, ProgramLocation loc, Program program) {
- super(src, NAME);
- this.loc = loc;
- this.programName = program.getName();
- }
-
- /**
- * Returns the ProgramLocation stored in this event.
- */
- public ProgramLocation getLocation() {
- return loc;
- }
-
- /**
- * Returns the Program object that the location refers to.
- */
- public String getProgramName() {
- return programName;
- }
-
-}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/events/OpenProgramPluginEvent.java b/Ghidra/Features/Base/src/main/java/ghidra/app/events/OpenProgramPluginEvent.java
index ad67b55586..9cbf4c14dc 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/events/OpenProgramPluginEvent.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/events/OpenProgramPluginEvent.java
@@ -18,20 +18,14 @@ package ghidra.app.events;
import java.lang.ref.WeakReference;
import ghidra.framework.plugintool.PluginEvent;
-import ghidra.framework.plugintool.ToolEventName;
import ghidra.program.model.listing.Program;
/**
* Event for telling a tool to open a program
- * <p>
- * This event shares a common tool-event name with the {@link OpenProgramPluginEvent}
- * so that they have a single shared tool connection.
*/
-@ToolEventName(OpenProgramPluginEvent.TOOL_EVENT_NAME) // this allows the event to be considered for tool connection
public class OpenProgramPluginEvent extends PluginEvent {
static final String NAME = "Open Program";
- static final String TOOL_EVENT_NAME = "Open/Close Program";
private WeakReference<Program> programRef;
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/progmgr/ProgramSaveManager.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/progmgr/ProgramSaveManager.java
index f9a5dc6523..393e932cec 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/progmgr/ProgramSaveManager.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/progmgr/ProgramSaveManager.java
@@ -66,8 +66,7 @@ class ProgramSaveManager {
* the user
*/
boolean canClose(Program program) {
- if (program == null ||
- (program.getDomainFile().getConsumers().size() > 1 && !tool.hasToolListeners())) {
+ if (!isOnlyToolConsumer(program)) {
return true;
}
if (acquireSaveLock(program, "Close")) {
@@ -105,9 +104,7 @@ class ProgramSaveManager {
return saveChangedPrograms(saveList);
}
finally {
- Iterator<Program> it = lockList.iterator();
- while (it.hasNext()) {
- Program p = it.next();
+ for (Program p : lockList) {
p.unlock();
}
}
@@ -378,10 +375,9 @@ class ProgramSaveManager {
"The Program is currently being modified by the following actions/tasks:\n ");
TransactionInfo t = program.getCurrentTransactionInfo();
List<String> list = t.getOpenSubTransactions();
- Iterator<String> it = list.iterator();
- while (it.hasNext()) {
+ for (String element : list) {
buf.append("\n ");
- buf.append(it.next());
+ buf.append(element);
}
buf.append("\n \n");
buf.append("WARNING! The above task(s) should be cancelled before attempting a " +
@@ -412,10 +408,9 @@ class ProgramSaveManager {
"The Program is currently being modified by the following actions/tasks:\n ");
TransactionInfo t = program.getCurrentTransactionInfo();
List<String> list = t.getOpenSubTransactions();
- Iterator<String> it = list.iterator();
- while (it.hasNext()) {
+ for (String element : list) {
buf.append("\n ");
- buf.append(it.next());
+ buf.append(element);
}
buf.append("\n \n");
buf.append(