fixing the graphing feature to initialize the graph with the current

selection and location
This commit is contained in:
ghidravore 2020-07-14 13:08:43 -04:00
parent 7ec583a4e8
commit 262b1c1d16
4 changed files with 28 additions and 11 deletions

View file

@ -25,6 +25,7 @@ import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.block.*;
import ghidra.program.model.listing.*;
import ghidra.program.model.symbol.*;
import ghidra.program.util.ProgramLocation;
import ghidra.program.util.ProgramSelection;
import ghidra.service.graph.*;
import ghidra.util.HTMLUtilities;
@ -103,6 +104,7 @@ public class BlockGraphTask extends Task {
private final static String ENTRY_NEXUS_NAME = "Entry Points";
private CodeBlockModel blockModel;
private AddressSetView selection;
private ProgramLocation location;
private GraphDisplayProvider graphService;
private boolean reuseGraph;
private boolean appendGraph;
@ -112,9 +114,10 @@ public class BlockGraphTask extends Task {
public BlockGraphTask(String actionName, boolean graphEntryPointNexus, boolean showCode,
boolean reuseGraph,
boolean appendGraph, PluginTool tool, ProgramSelection selection,
CodeBlockModel blockModel, GraphDisplayProvider graphService) {
boolean reuseGraph, boolean appendGraph, PluginTool tool, ProgramSelection selection,
ProgramLocation location, CodeBlockModel blockModel,
GraphDisplayProvider graphService) {
super("Graph Program", true, false, true);
this.actionName = actionName;
@ -127,6 +130,7 @@ public class BlockGraphTask extends Task {
this.graphService = graphService;
this.colorizingService = tool.getService(ColorizingService.class);
this.selection = selection;
this.location = location;
this.program = blockModel.getProgram();
}
@ -139,8 +143,10 @@ public class BlockGraphTask extends Task {
monitor.setMessage("Generating Graph...");
try {
GraphDisplay display = graphService.getGraphDisplay(reuseGraph, monitor);
display.setGraphDisplayListener(
new BlockModelGraphDisplayListener(tool, blockModel, display));
BlockModelGraphDisplayListener listener =
new BlockModelGraphDisplayListener(tool, blockModel, display);
display.setGraphDisplayListener(listener);
if (showCode) {
display.defineVertexAttribute(CODE_ATTRIBUTE);
display.defineVertexAttribute(SYMBOLS_ATTRIBUTE);
@ -148,6 +154,16 @@ public class BlockGraphTask extends Task {
codeLimitPerBlock + 1);
}
display.setGraph(graph, actionName, appendGraph, monitor);
if (location != null) {
display.setLocation(listener.getVertexIdForAddress(location.getAddress()));
}
if (selection != null && !selection.isEmpty()) {
List<String> selectedVertices = listener.getVertices(selection);
if (selectedVertices != null) {
display.selectVertices(selectedVertices);
}
}
}
catch (GraphException e) {
if (!monitor.isCancelled()) {

View file

@ -298,7 +298,8 @@ public class ProgramGraphPlugin extends ProgramPlugin
blockModelService.getNewModelByName(modelName, currentProgram, true);
BlockGraphTask task =
new BlockGraphTask(actionName, graphEntryPointNexus, showCode, reuseGraph,
appendToGraph, tool, currentSelection, model, defaultGraphService);
appendToGraph, tool, currentSelection, currentLocation, model,
defaultGraphService);
task.setCodeLimitPerBlock(codeLimitPerBlock);
new TaskLauncher(task, tool.getToolFrame());
}

View file

@ -43,7 +43,7 @@ public class BlockGraphEventTest extends AbstractBlockGraphTest {
TestGraphService graphService = new TestGraphService();
BlockGraphTask task =
new BlockGraphTask("test", false, false, false, false,
tool, null, model, graphService);
tool, null, null, model, graphService);
task.monitoredRun(TaskMonitor.DUMMY);

View file

@ -38,7 +38,7 @@ public class BlockGraphTaskTest extends AbstractBlockGraphTest {
TestGraphService graphService = new TestGraphService();
BlockGraphTask task =
new BlockGraphTask("test", false, DONT_SHOW_CODE, false, false,
tool, null, model, graphService);
tool, null, null, model, graphService);
task.monitoredRun(TaskMonitor.DUMMY);
@ -99,7 +99,7 @@ public class BlockGraphTaskTest extends AbstractBlockGraphTest {
TestGraphService graphService = new TestGraphService();
BlockGraphTask task =
new BlockGraphTask("test", false, SHOW_CODE, false, false,
tool, null, model, graphService);
tool, null, null, model, graphService);
task.monitoredRun(TaskMonitor.DUMMY);
@ -152,7 +152,7 @@ public class BlockGraphTaskTest extends AbstractBlockGraphTest {
TestGraphService graphService = new TestGraphService();
BlockGraphTask task =
new BlockGraphTask("test", false, false, false, false,
tool, null, model, graphService);
tool, null, null, model, graphService);
task.monitoredRun(TaskMonitor.DUMMY);
@ -199,7 +199,7 @@ public class BlockGraphTaskTest extends AbstractBlockGraphTest {
ProgramSelection sel = new ProgramSelection(addr(0x1002239), addr(0x1002247));
BlockGraphTask task =
new BlockGraphTask("test", false, DONT_SHOW_CODE, false, false,
tool, sel, model, graphService);
tool, sel, null, model, graphService);
task.monitoredRun(TaskMonitor.DUMMY);