Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-3540 - Updated the Decompiler to copy the full symbol name instead of the truncated template name

dragonmacherad7ff838f0c5
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerClipboardProvider.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerClipboardProvider.java
index 1a2bab4b18..f242ee29e8 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerClipboardProvider.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerClipboardProvider.java
@@ -29,17 +29,21 @@ import org.apache.commons.lang3.StringUtils;
import docking.ActionContext;
import docking.ComponentProvider;
+import docking.dnd.StringTransferable;
import docking.widgets.fieldpanel.Layout;
import docking.widgets.fieldpanel.LayoutModel;
import docking.widgets.fieldpanel.internal.PaintContext;
import docking.widgets.fieldpanel.support.FieldRange;
import docking.widgets.fieldpanel.support.FieldSelection;
-import ghidra.app.decompiler.ClangToken;
-import ghidra.app.decompiler.component.ClangTextField;
-import ghidra.app.decompiler.component.DecompilerPanel;
+import ghidra.app.decompiler.*;
+import ghidra.app.decompiler.component.*;
import ghidra.app.services.ClipboardContentProviderService;
import ghidra.app.util.ByteCopier;
import ghidra.app.util.ClipboardType;
+import ghidra.program.model.address.Address;
+import ghidra.program.model.listing.Function;
+import ghidra.program.model.symbol.Symbol;
+import ghidra.program.model.symbol.SymbolTable;
import ghidra.util.task.TaskMonitor;
public class DecompilerClipboardProvider extends ByteCopier
@@ -86,11 +90,10 @@ public class DecompilerClipboardProvider extends ByteCopier
@Override
public Transferable copy(TaskMonitor monitor) {
- if (!copyFromSelectionEnabled) {
- return createStringTransferable(getCursorText());
+ if (copyFromSelectionEnabled) {
+ return copyTextFromSelection(monitor);
}
-
- return copyText(monitor);
+ return new StringTransferable(getCursorText());
}
private String getCursorText() {
@@ -100,6 +103,22 @@ public class DecompilerClipboardProvider extends ByteCopier
return null;
}
+ if (token instanceof ClangLabelToken) {
+ Address a = token.getMinAddress();
+ SymbolTable st = currentProgram.getSymbolTable();
+ Symbol[] symbols = st.getSymbols(a);
+ if (symbols.length > 0) {
+ Symbol s = symbols[0];
+ return s.getName();
+ }
+ }
+ else if (token instanceof ClangFuncNameToken functionToken) {
+ Function function = DecompilerUtils.getFunction(currentProgram, functionToken);
+ if (function != null) {
+ return function.getName();
+ }
+ }
+
String text = token.getText();
return text;
}
@@ -119,7 +138,7 @@ public class DecompilerClipboardProvider extends ByteCopier
@Override
public Transferable copySpecial(ClipboardType copyType, TaskMonitor monitor) {
if (copyType == TEXT_TYPE) {
- return copyText(monitor);
+ return copyTextFromSelection(monitor);
}
return null;
@@ -161,7 +180,7 @@ public class DecompilerClipboardProvider extends ByteCopier
return false;
}
- private Transferable copyText(TaskMonitor monitor) {
+ private Transferable copyTextFromSelection(TaskMonitor monitor) {
return createStringTransferable(getText());
}