Skip to content

Ghidra is a software reverse engineering (SRE) framework

Fix for recent Copy action change

dragonmacher8a79fdd9bdf2
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 f242ee29e8..ed42dd89d8 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
@@ -35,15 +35,16 @@ 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.*;
+import ghidra.app.decompiler.ClangFuncNameToken;
+import ghidra.app.decompiler.ClangToken;
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.program.model.listing.Program;
+import ghidra.program.util.ProgramLocation;
+import ghidra.program.util.ProgramSelection;
import ghidra.util.task.TaskMonitor;
public class DecompilerClipboardProvider extends ByteCopier
@@ -65,6 +66,20 @@ public class DecompilerClipboardProvider extends ByteCopier
private Set<ChangeListener> listeners = new CopyOnWriteArraySet<>();
private int spaceCharWidthInPixels = 7;
+ void setLocation(ProgramLocation location) {
+ currentLocation = location;
+ }
+
+ void setSelection(ProgramSelection selection) {
+ currentSelection = selection;
+ }
+
+ void setProgram(Program p) {
+ currentProgram = p;
+ currentLocation = null;
+ currentSelection = null;
+ }
+
public DecompilerClipboardProvider(DecompilePlugin plugin, DecompilerProvider provider) {
this.provider = provider;
this.tool = plugin.getTool();
@@ -97,22 +112,17 @@ public class DecompilerClipboardProvider extends ByteCopier
}
private String getCursorText() {
+ if (currentProgram == null) {
+ return null; // disposed
+ }
+
DecompilerPanel panel = provider.getDecompilerPanel();
ClangToken token = panel.getTokenAtCursor();
if (token == null) {
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) {
+ if (token instanceof ClangFuncNameToken functionToken) {
Function function = DecompilerUtils.getFunction(currentProgram, functionToken);
if (function != null) {
return function.getName();
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerProvider.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerProvider.java
index f938e188e8..e52b6c73b2 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerProvider.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerProvider.java
@@ -399,6 +399,7 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapter
if (program != null) {
program.removeListener(this);
}
+
program = newProgram;
currentLocation = null;
currentSelection = null;
@@ -408,6 +409,8 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapter
ToolOptions opt = tool.getOptions(OPTIONS_TITLE);
decompilerOptions.grabFromToolAndProgram(fieldOptions, opt, program);
}
+
+ clipboardProvider.setProgram(program);
}
@Override
@@ -417,6 +420,8 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapter
contextChanged();
controller.setSelection(selection);
}
+
+ clipboardProvider.setSelection(selection);
}
@Override
@@ -440,6 +445,7 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapter
void setLocation(ProgramLocation loc, ViewerPosition viewerPosition) {
Address currentAddress = currentLocation != null ? currentLocation.getAddress() : null;
currentLocation = loc;
+ clipboardProvider.setLocation(currentLocation);
Address newAddress = currentLocation != null ? currentLocation.getAddress() : null;
if (viewerPosition == null) {
viewerPosition = pendingViewerPosition;