mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 02:09:44 +02:00
Adding capbility to add DockingActions to GraphDisplay. Also, wired in the help for existing actions.
This commit is contained in:
parent
b647c6cd5b
commit
532a1d4fd0
24 changed files with 1142 additions and 533 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue