Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-6177 - Updated xref table delete action to not be enabled if only thunk ref types are selected

dragonmachereb8694d69237
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/CodeBrowserPlugin/CodeBrowser.htm b/Ghidra/Features/Base/src/main/help/help/topics/CodeBrowserPlugin/CodeBrowser.htm
index 35306b3db3..3300b4e33a 100644
--- a/Ghidra/Features/Base/src/main/help/help/topics/CodeBrowserPlugin/CodeBrowser.htm
+++ b/Ghidra/Features/Base/src/main/help/help/topics/CodeBrowserPlugin/CodeBrowser.htm
@@ -170,6 +170,13 @@
from the <A HREF="help/topics/Search/Query_Results_Dialog.htm#Remove_Items">Remove Items
</A> action, which will simply remove items from the table.
</P>
+
+ <BLOCKQUOTE>
+ <P><IMG border="0" src="help/shared/tip.png" alt="">If the <CODE>RefType</CODE> is
+ <CODE>THUNK</CODE>, then that reference cannot be deleted. However, it may be
+ <I>removed</I> from the table.</P>
+ </BLOCKQUOTE>
+
</BLOCKQUOTE>
</BLOCKQUOTE>
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/XReferenceUtils.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/XReferenceUtils.java
index cc3af7245a..347bf54af2 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/XReferenceUtils.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/XReferenceUtils.java
@@ -355,7 +355,21 @@ public class XReferenceUtils {
if (tableModel.isBusy()) {
return false;
}
- return table.getSelectedRowCount() > 0;
+ return hasNonThunkRefs(table);
+ }
+
+ private boolean hasNonThunkRefs(JTable table) {
+ int[] rows = table.getSelectedRows();
+ for (int row : rows) {
+ ReferenceEndpoint rowObject = tableModel.getRowObject(row);
+ Reference ref = rowObject.getReference();
+ RefType type = ref.getReferenceType();
+ if (type != RefType.THUNK) {
+ return true;
+ }
+
+ }
+ return false;
}
@Override
@@ -391,8 +405,13 @@ public class XReferenceUtils {
CompoundCmd<Program> compoundCmd = new CompoundCmd<>("Delete References");
for (int row : rows) {
ReferenceEndpoint endpoint = tableModel.getRowObject(row);
- deletedRowObjects.add(endpoint);
Reference ref = endpoint.getReference();
+ RefType type = ref.getReferenceType();
+ if (type == RefType.THUNK) {
+ continue; // we cannot delete THUNK types, as they are not real references
+ }
+
+ deletedRowObjects.add(endpoint);
RemoveReferenceCmd cmd = new RemoveReferenceCmd(ref);
compoundCmd.add(cmd);
}