mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-09-28 17:11:11 -09:00
Adding capbility to add DockingActions to GraphDisplay. Also, wired in the help for existing actions.
This commit is contained in:
@@ -113,7 +113,6 @@ public class BlockGraphTask extends Task {
|
||||
private String actionName;
|
||||
private Program program;
|
||||
|
||||
|
||||
public BlockGraphTask(String actionName, boolean graphEntryPointNexus, boolean showCode,
|
||||
boolean reuseGraph, boolean appendGraph, PluginTool tool, ProgramSelection selection,
|
||||
ProgramLocation location, CodeBlockModel blockModel,
|
||||
@@ -210,7 +209,6 @@ public class BlockGraphTask extends Task {
|
||||
return graph;
|
||||
}
|
||||
|
||||
|
||||
private CodeBlockIterator getBlockIterator() throws CancelledException {
|
||||
if (selection == null || selection.isEmpty()) {
|
||||
return blockModel.getCodeBlocks(taskMonitor);
|
||||
@@ -218,7 +216,8 @@ public class BlockGraphTask extends Task {
|
||||
return blockModel.getCodeBlocksContaining(selection, taskMonitor);
|
||||
}
|
||||
|
||||
private Address graphBlock(AttributedGraph graph, CodeBlock curBB, List<AttributedVertex> entries)
|
||||
private Address graphBlock(AttributedGraph graph, CodeBlock curBB,
|
||||
List<AttributedVertex> entries)
|
||||
throws CancelledException {
|
||||
|
||||
Address[] startAddrs = curBB.getStartAddresses();
|
||||
@@ -255,7 +254,6 @@ public class BlockGraphTask extends Task {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected AttributedVertex graphBasicBlock(AttributedGraph graph, CodeBlock curBB)
|
||||
throws CancelledException {
|
||||
|
||||
@@ -297,7 +295,8 @@ public class BlockGraphTask extends Task {
|
||||
return fromVertex;
|
||||
}
|
||||
|
||||
private void setEdgeColor(AttributedEdge edge, AttributedVertex fromVertex, AttributedVertex toVertex) {
|
||||
private void setEdgeColor(AttributedEdge edge, AttributedVertex fromVertex,
|
||||
AttributedVertex toVertex) {
|
||||
// color the edge: first on the 'from' vertex, then try to 'to' vertex
|
||||
String fromColor = fromVertex.getAttribute("Color");
|
||||
String toColor = toVertex.getAttribute("Color");
|
||||
@@ -309,7 +308,7 @@ public class BlockGraphTask extends Task {
|
||||
edge.setAttribute("Color", toColor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private String getVertexId(CodeBlock bb) {
|
||||
|
||||
@@ -17,14 +17,15 @@ package ghidra.graph.program;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import docking.action.builder.ActionBuilder;
|
||||
import ghidra.app.plugin.core.graph.AddressBasedGraphDisplayListener;
|
||||
import ghidra.app.util.AddEditDialog;
|
||||
import ghidra.framework.plugintool.PluginTool;
|
||||
import ghidra.program.model.address.*;
|
||||
import ghidra.program.model.block.*;
|
||||
import ghidra.program.model.symbol.Symbol;
|
||||
import ghidra.program.model.symbol.SymbolTable;
|
||||
import ghidra.service.graph.GraphDisplay;
|
||||
import ghidra.service.graph.GraphDisplayListener;
|
||||
import ghidra.service.graph.*;
|
||||
import ghidra.util.exception.CancelledException;
|
||||
import ghidra.util.task.TaskMonitor;
|
||||
|
||||
@@ -39,6 +40,17 @@ public class BlockModelGraphDisplayListener extends AddressBasedGraphDisplayList
|
||||
GraphDisplay display) {
|
||||
super(tool, blockModel.getProgram(), display);
|
||||
this.blockModel = blockModel;
|
||||
addActions(display);
|
||||
}
|
||||
|
||||
private void addActions(GraphDisplay display) {
|
||||
display.addAction(new ActionBuilder("Rename Vertex", "Block Graph")
|
||||
.popupMenuPath("Rename Vertex")
|
||||
.withContext(VertexGraphActionContext.class)
|
||||
// only enable action when vertex corresponds to an address
|
||||
.enabledWhen(c -> getAddress(c.getClickedVertex().getId()) != null)
|
||||
.onAction(this::updateVertexName)
|
||||
.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -137,4 +149,24 @@ public class BlockModelGraphDisplayListener extends AddressBasedGraphDisplayList
|
||||
return program.getMemory().contains(addr) || addr.isExternalAddress();
|
||||
}
|
||||
|
||||
private void updateVertexName(VertexGraphActionContext context) {
|
||||
String vertexId = context.getClickedVertex().getId();
|
||||
Address address = getAddressForVertexId(vertexId);
|
||||
Symbol symbol = program.getSymbolTable().getPrimarySymbol(address);
|
||||
|
||||
if (symbol == null) {
|
||||
AddEditDialog dialog = new AddEditDialog("Create Label", tool);
|
||||
dialog.addLabel(address, program, context.getComponentProvider());
|
||||
}
|
||||
else {
|
||||
AddEditDialog dialog = new AddEditDialog("Edit Label", tool);
|
||||
dialog.editLabel(symbol, program, context.getComponentProvider());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphDisplayListener cloneWith(GraphDisplay graphDisplay) {
|
||||
return new BlockModelGraphDisplayListener(tool, blockModel, graphDisplay);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package ghidra.graph.program;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import docking.action.DockingAction;
|
||||
import docking.widgets.EventTrigger;
|
||||
import ghidra.service.graph.*;
|
||||
import ghidra.util.exception.CancelledException;
|
||||
@@ -110,4 +111,20 @@ public class TestGraphDisplay implements GraphDisplay {
|
||||
public void selectionChanged(List<String> vertexIds) {
|
||||
listener.selectionChanged(vertexIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAction(DockingAction action) {
|
||||
// do nothing, actions are not supported by this display
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFocusedVertexId() {
|
||||
return currentFocusedVertex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSelectedVertexIds() {
|
||||
return new HashSet<String>(currentSelection);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user