Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-4373 - Fixed Cut/Paste bug in the Data Types tree when filtered

dragonmacherda9a885a15fe
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/actions/CutAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/actions/CutAction.java
index d973fff0b9..4dd7e9ea5a 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/actions/CutAction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/actions/CutAction.java
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
- * REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,10 +15,6 @@
*/
package ghidra.app.plugin.core.datamgr.actions;
-import ghidra.app.plugin.core.datamgr.DataTypeManagerPlugin;
-import ghidra.app.plugin.core.datamgr.DataTypesActionContext;
-import ghidra.app.plugin.core.datamgr.tree.DataTypeTreeNode;
-
import java.awt.datatransfer.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
@@ -36,6 +31,9 @@ import docking.widgets.tree.GTree;
import docking.widgets.tree.GTreeNode;
import docking.widgets.tree.support.GTreeNodeTransferable;
import docking.widgets.tree.support.GTreeTransferHandler;
+import ghidra.app.plugin.core.datamgr.DataTypeManagerPlugin;
+import ghidra.app.plugin.core.datamgr.DataTypesActionContext;
+import ghidra.app.plugin.core.datamgr.tree.DataTypeTreeNode;
public class CutAction extends DockingAction {
private Clipboard clipboard;
@@ -50,6 +48,7 @@ public class CutAction extends DockingAction {
setEnabled(true);
clipboardOwner = new ClipboardOwner() {
+ @Override
public void lostOwnership(Clipboard currentClipboard, Transferable transferable) {
GTreeNodeTransferable gtTransferable = (GTreeNodeTransferable) transferable;
List<GTreeNode> nodeList = gtTransferable.getAllData();
@@ -86,7 +85,7 @@ public class CutAction extends DockingAction {
// cut to clipboard
TreePath[] paths = gTree.getSelectionPaths();
- List<GTreeNode> nodeList = createList(paths);
+ List<GTreeNode> nodeList = createList(gTree, paths);
clearClipboard();
@@ -103,12 +102,13 @@ public class CutAction extends DockingAction {
}
}
- private ArrayList<GTreeNode> createList(TreePath[] paths) {
- ArrayList<GTreeNode> list = new ArrayList<GTreeNode>();
+ private ArrayList<GTreeNode> createList(GTree gTree, TreePath[] paths) {
+ ArrayList<GTreeNode> list = new ArrayList<>();
if (paths != null) {
- for (int i = 0; i < paths.length; i++) {
- GTreeNode node = (GTreeNode) paths[i].getLastPathComponent();
- list.add(node);
+ for (TreePath path : paths) {
+ GTreeNode node = (GTreeNode) path.getLastPathComponent();
+ GTreeNode modelNode = gTree.getModelNode(node);
+ list.add(modelNode);
}
}
return list;
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/actions/PasteAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/actions/PasteAction.java
index 05e584ba1a..d0dfe535b9 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/actions/PasteAction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/actions/PasteAction.java
@@ -4,9 +4,9 @@
* 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.
@@ -19,8 +19,7 @@ import java.awt.datatransfer.*;
import java.awt.dnd.DnDConstants;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
-import java.util.Collections;
-import java.util.List;
+import java.util.*;
import javax.swing.KeyStroke;
import javax.swing.tree.TreePath;
@@ -124,7 +123,7 @@ public class PasteAction extends DockingAction {
for (GTreeNode cutNode : nodeList) {
DataTypeTreeNode dataTypeTreeNode = (DataTypeTreeNode) cutNode;
ArchiveNode archiveNode = dataTypeTreeNode.getArchiveNode();
- if (archiveNode != destinationArchiveNode) {
+ if (!Objects.equals(archiveNode, destinationArchiveNode)) {
return true; // is invalid
}
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/actions/CutAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/actions/CutAction.java
index 1079a51a5e..ff54947c61 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/actions/CutAction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/actions/CutAction.java
@@ -86,7 +86,7 @@ public class CutAction extends SymbolTreeContextAction {
clearClipboardFromPreviousCut();
- List<GTreeNode> transferableList = createList(selectionPaths);
+ List<GTreeNode> transferableList = createList(context.getSymbolTree(), selectionPaths);
setClipboardContents(context.getSymbolTree(), provider.getClipboard(), transferableList);
setNodesCut(transferableList, true);
@@ -109,12 +109,13 @@ public class CutAction extends SymbolTreeContextAction {
}
}
- private List<GTreeNode> createList(TreePath[] paths) {
+ private List<GTreeNode> createList(GTree gTree, TreePath[] paths) {
ArrayList<GTreeNode> list = new ArrayList<>();
if (paths != null) {
for (TreePath element : paths) {
GTreeNode node = (GTreeNode) element.getLastPathComponent();
- list.add(node);
+ GTreeNode modelNode = gTree.getModelNode(node);
+ list.add(modelNode);
}
}
return list;
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/SymbolNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/SymbolNode.java
index fa2b687df9..b431195094 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/SymbolNode.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/SymbolNode.java
@@ -94,6 +94,7 @@ public class SymbolNode extends SymbolTreeNode {
@Override
public void setNodeCut(boolean isCut) {
this.isCut = isCut;
+ fireNodeChanged();
}
@Override
@@ -223,7 +224,7 @@ public class SymbolNode extends SymbolTreeNode {
int transactionID = program.startTransaction("Rename Symbol");
try {
- // The symbol node rename does not support moving symbols into the
+ // The symbol node rename does not support moving symbols into the
// Global space since this implies a simple rename
Namespace namespace = createNewNamespace(symbolPath.getParent());
if (!namespace.isGlobal()) {
@@ -292,7 +293,7 @@ public class SymbolNode extends SymbolTreeNode {
return nameCompare;
}
- // sort alphabetically first
+ // sort alphabetically first
if (nameCompare != 0) {
return nameCompare;
}