mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-09-28 17:11:11 -09:00
Fix for recent Copy action change
This commit is contained in:
@@ -35,15 +35,16 @@ import docking.widgets.fieldpanel.LayoutModel;
|
|||||||
import docking.widgets.fieldpanel.internal.PaintContext;
|
import docking.widgets.fieldpanel.internal.PaintContext;
|
||||||
import docking.widgets.fieldpanel.support.FieldRange;
|
import docking.widgets.fieldpanel.support.FieldRange;
|
||||||
import docking.widgets.fieldpanel.support.FieldSelection;
|
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.decompiler.component.*;
|
||||||
import ghidra.app.services.ClipboardContentProviderService;
|
import ghidra.app.services.ClipboardContentProviderService;
|
||||||
import ghidra.app.util.ByteCopier;
|
import ghidra.app.util.ByteCopier;
|
||||||
import ghidra.app.util.ClipboardType;
|
import ghidra.app.util.ClipboardType;
|
||||||
import ghidra.program.model.address.Address;
|
|
||||||
import ghidra.program.model.listing.Function;
|
import ghidra.program.model.listing.Function;
|
||||||
import ghidra.program.model.symbol.Symbol;
|
import ghidra.program.model.listing.Program;
|
||||||
import ghidra.program.model.symbol.SymbolTable;
|
import ghidra.program.util.ProgramLocation;
|
||||||
|
import ghidra.program.util.ProgramSelection;
|
||||||
import ghidra.util.task.TaskMonitor;
|
import ghidra.util.task.TaskMonitor;
|
||||||
|
|
||||||
public class DecompilerClipboardProvider extends ByteCopier
|
public class DecompilerClipboardProvider extends ByteCopier
|
||||||
@@ -65,6 +66,20 @@ public class DecompilerClipboardProvider extends ByteCopier
|
|||||||
private Set<ChangeListener> listeners = new CopyOnWriteArraySet<>();
|
private Set<ChangeListener> listeners = new CopyOnWriteArraySet<>();
|
||||||
private int spaceCharWidthInPixels = 7;
|
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) {
|
public DecompilerClipboardProvider(DecompilePlugin plugin, DecompilerProvider provider) {
|
||||||
this.provider = provider;
|
this.provider = provider;
|
||||||
this.tool = plugin.getTool();
|
this.tool = plugin.getTool();
|
||||||
@@ -97,22 +112,17 @@ public class DecompilerClipboardProvider extends ByteCopier
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getCursorText() {
|
private String getCursorText() {
|
||||||
|
if (currentProgram == null) {
|
||||||
|
return null; // disposed
|
||||||
|
}
|
||||||
|
|
||||||
DecompilerPanel panel = provider.getDecompilerPanel();
|
DecompilerPanel panel = provider.getDecompilerPanel();
|
||||||
ClangToken token = panel.getTokenAtCursor();
|
ClangToken token = panel.getTokenAtCursor();
|
||||||
if (token == null) {
|
if (token == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (token instanceof ClangLabelToken) {
|
if (token instanceof ClangFuncNameToken functionToken) {
|
||||||
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);
|
Function function = DecompilerUtils.getFunction(currentProgram, functionToken);
|
||||||
if (function != null) {
|
if (function != null) {
|
||||||
return function.getName();
|
return function.getName();
|
||||||
|
|||||||
@@ -399,6 +399,7 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapter
|
|||||||
if (program != null) {
|
if (program != null) {
|
||||||
program.removeListener(this);
|
program.removeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
program = newProgram;
|
program = newProgram;
|
||||||
currentLocation = null;
|
currentLocation = null;
|
||||||
currentSelection = null;
|
currentSelection = null;
|
||||||
@@ -408,6 +409,8 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapter
|
|||||||
ToolOptions opt = tool.getOptions(OPTIONS_TITLE);
|
ToolOptions opt = tool.getOptions(OPTIONS_TITLE);
|
||||||
decompilerOptions.grabFromToolAndProgram(fieldOptions, opt, program);
|
decompilerOptions.grabFromToolAndProgram(fieldOptions, opt, program);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clipboardProvider.setProgram(program);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -417,6 +420,8 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapter
|
|||||||
contextChanged();
|
contextChanged();
|
||||||
controller.setSelection(selection);
|
controller.setSelection(selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clipboardProvider.setSelection(selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -440,6 +445,7 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapter
|
|||||||
void setLocation(ProgramLocation loc, ViewerPosition viewerPosition) {
|
void setLocation(ProgramLocation loc, ViewerPosition viewerPosition) {
|
||||||
Address currentAddress = currentLocation != null ? currentLocation.getAddress() : null;
|
Address currentAddress = currentLocation != null ? currentLocation.getAddress() : null;
|
||||||
currentLocation = loc;
|
currentLocation = loc;
|
||||||
|
clipboardProvider.setLocation(currentLocation);
|
||||||
Address newAddress = currentLocation != null ? currentLocation.getAddress() : null;
|
Address newAddress = currentLocation != null ? currentLocation.getAddress() : null;
|
||||||
if (viewerPosition == null) {
|
if (viewerPosition == null) {
|
||||||
viewerPosition = pendingViewerPosition;
|
viewerPosition = pendingViewerPosition;
|
||||||
|
|||||||
Reference in New Issue
Block a user