Ghidra is a software reverse engineering (SRE) framework
fixing the graphing feature to initialize the graph with the current selection and location
ghidravore262b1c1d1677
diff --git a/Ghidra/Features/ProgramGraph/src/main/java/ghidra/graph/program/BlockGraphTask.java b/Ghidra/Features/ProgramGraph/src/main/java/ghidra/graph/program/BlockGraphTask.javaindex 188bda0f42..d69d045693 100644--- a/Ghidra/Features/ProgramGraph/src/main/java/ghidra/graph/program/BlockGraphTask.java+++ b/Ghidra/Features/ProgramGraph/src/main/java/ghidra/graph/program/BlockGraphTask.java@@ -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()) {diff --git a/Ghidra/Features/ProgramGraph/src/main/java/ghidra/graph/program/ProgramGraphPlugin.java b/Ghidra/Features/ProgramGraph/src/main/java/ghidra/graph/program/ProgramGraphPlugin.javaindex d23b2f14e3..fbfda93055 100644--- a/Ghidra/Features/ProgramGraph/src/main/java/ghidra/graph/program/ProgramGraphPlugin.java+++ b/Ghidra/Features/ProgramGraph/src/main/java/ghidra/graph/program/ProgramGraphPlugin.java@@ -298,7 +298,8 @@ public class ProgramGraphPlugin extends ProgramPluginblockModelService.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());}diff --git a/Ghidra/Features/ProgramGraph/src/test/java/ghidra/graph/program/BlockGraphEventTest.java b/Ghidra/Features/ProgramGraph/src/test/java/ghidra/graph/program/BlockGraphEventTest.javaindex c078f68ec5..888948c729 100644--- a/Ghidra/Features/ProgramGraph/src/test/java/ghidra/graph/program/BlockGraphEventTest.java+++ b/Ghidra/Features/ProgramGraph/src/test/java/ghidra/graph/program/BlockGraphEventTest.java@@ -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);diff --git a/Ghidra/Features/ProgramGraph/src/test/java/ghidra/graph/program/BlockGraphTaskTest.java b/Ghidra/Features/ProgramGraph/src/test/java/ghidra/graph/program/BlockGraphTaskTest.javaindex 0c92cf0029..4130370ad1 100644--- a/Ghidra/Features/ProgramGraph/src/test/java/ghidra/graph/program/BlockGraphTaskTest.java+++ b/Ghidra/Features/ProgramGraph/src/test/java/ghidra/graph/program/BlockGraphTaskTest.java@@ -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);