diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/graph/AddressBasedGraphDisplayListener.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/graph/AddressBasedGraphDisplayListener.java index f7f7185206..0e6b40ca8b 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/graph/AddressBasedGraphDisplayListener.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/graph/AddressBasedGraphDisplayListener.java @@ -120,6 +120,10 @@ public abstract class AddressBasedGraphDisplayListener return null; } String id = getVertexId(address); + if (id == null) { + return null; + } + return graphDisplay.getGraph().getVertex(id); } @@ -202,6 +206,9 @@ public abstract class AddressBasedGraphDisplayListener private void handleSymbolAddedOrRenamed(Address address, Symbol symbol) { AttributedVertex vertex = getVertex(address); + if (vertex == null) { + return; + } graphDisplay.updateVertexName(vertex, symbol.getName()); } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/test/ToyProgramBuilder.java b/Ghidra/Features/Base/src/main/java/ghidra/test/ToyProgramBuilder.java index 83e08c570e..00ce20c00f 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/test/ToyProgramBuilder.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/test/ToyProgramBuilder.java @@ -15,14 +15,14 @@ */ package ghidra.test; +import java.util.ArrayList; +import java.util.List; + import ghidra.program.database.ProgramBuilder; import ghidra.program.model.address.*; import ghidra.program.model.listing.Program; import ghidra.program.model.mem.MemoryAccessException; -import java.util.ArrayList; -import java.util.List; - public class ToyProgramBuilder extends ProgramBuilder { private static final String TOY_LANGUAGE_ID_BE = "Toy:BE:32:builder"; @@ -106,7 +106,7 @@ public class ToyProgramBuilder extends ProgramBuilder { /** * Get address in default ram space * @param offset address offset - * @return address + * @return the address */ public Address getAddress(long offset) { return defaultSpace.getAddress(offset); diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ASTGraphTask.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ASTGraphTask.java index 2ed6c445fe..f034c1faeb 100644 --- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ASTGraphTask.java +++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ASTGraphTask.java @@ -123,13 +123,7 @@ public class ASTGraphTask extends Task { graphType == GraphType.DATA_FLOW_GRAPH ? "AST Data Flow" : "AST Control Flow"; description = description + " for " + hfunction.getFunction().getName(); display.setGraph(graph, description, false, monitor); - // set the graph location - if (location != null) { - AttributedVertex vertex = displayListener.getVertex(location); - // update graph location, but don't have it send out event - display.setFocusedVertex(vertex, EventTrigger.INTERNAL_ONLY); - } - + setGraphLocation(display, displayListener); } catch (GraphException e) { Msg.showError(this, null, "Graph Error", e.getMessage()); @@ -140,6 +134,20 @@ public class ASTGraphTask extends Task { } + private void setGraphLocation(GraphDisplay display, ASTGraphDisplayListener displayListener) { + if (location == null) { + return; + } + + AttributedVertex vertex = displayListener.getVertex(location); + if (vertex == null) { + return; // location not in graph + } + + // update graph location, but don't have it send out event + display.setFocusedVertex(vertex, EventTrigger.INTERNAL_ONLY); + } + protected void createDataFlowGraph(AttributedGraph graph, TaskMonitor monitor) throws CancelledException { Iterator opIter = hfunction.getPcodeOps(); diff --git a/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplay.java b/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplay.java index 8b1a361149..69f88d0c47 100644 --- a/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplay.java +++ b/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplay.java @@ -798,7 +798,7 @@ public class DefaultGraphDisplay implements GraphDisplay { configureViewerPreferredSize(); Swing.runNow(() -> { - // set the graph but defer the layoutalgorithm setting + // set the graph but defer the layout algorithm setting viewer.getVisualizationModel().setGraph(graph, false); configureFilters(); LayoutAlgorithm initialLayoutAlgorithm = @@ -809,8 +809,8 @@ public class DefaultGraphDisplay implements GraphDisplay { } /** - * Determines if a vertex is a root. For our purpose, a root either has no incomming edges - * or has at least one outgoing "favored" edge and no incomming "favored" edge + * Determines if a vertex is a root. For our purpose, a root either has no incoming edges + * or has at least one outgoing "favored" edge and no incoming "favored" edge * @param vertex the vertex to test if it is a root * @return true if the vertex is a root */ 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.java index c4266658d6..96b7215070 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 @@ -106,7 +106,7 @@ public class BlockGraphTask extends Task { private CodeBlockModel blockModel; private AddressSetView selection; private ProgramLocation location; - private GraphDisplayProvider graphService; + private GraphDisplayProvider graphProvider; private boolean reuseGraph; private boolean appendGraph; private PluginTool tool; @@ -116,7 +116,7 @@ public class BlockGraphTask extends Task { public BlockGraphTask(String actionName, boolean graphEntryPointNexus, boolean showCode, boolean reuseGraph, boolean appendGraph, PluginTool tool, ProgramSelection selection, ProgramLocation location, CodeBlockModel blockModel, - GraphDisplayProvider graphService) { + GraphDisplayProvider graphProvider) { super("Graph Program", true, false, true); this.actionName = actionName; @@ -127,7 +127,7 @@ public class BlockGraphTask extends Task { this.appendGraph = appendGraph; this.tool = tool; this.blockModel = blockModel; - this.graphService = graphService; + this.graphProvider = graphProvider; this.colorizingService = tool.getService(ColorizingService.class); this.selection = selection; this.location = location; @@ -142,7 +142,7 @@ public class BlockGraphTask extends Task { AttributedGraph graph = createGraph(); monitor.setMessage("Generating Graph..."); try { - GraphDisplay display = graphService.getGraphDisplay(reuseGraph, monitor); + GraphDisplay display = graphProvider.getGraphDisplay(reuseGraph, monitor); BlockModelGraphDisplayListener listener = new BlockModelGraphDisplayListener(tool, blockModel, display); display.setGraphDisplayListener(listener); diff --git a/Ghidra/Features/ProgramGraph/src/test/java/ghidra/graph/program/AbstractBlockGraphTest.java b/Ghidra/Features/ProgramGraph/src/test/java/ghidra/graph/program/AbstractBlockGraphTest.java index e54a6467bc..064f8cfe94 100644 --- a/Ghidra/Features/ProgramGraph/src/test/java/ghidra/graph/program/AbstractBlockGraphTest.java +++ b/Ghidra/Features/ProgramGraph/src/test/java/ghidra/graph/program/AbstractBlockGraphTest.java @@ -30,6 +30,10 @@ import ghidra.program.model.mem.MemoryAccessException; import ghidra.test.*; public class AbstractBlockGraphTest extends AbstractGhidraHeadedIntegrationTest { + + protected static final String CALLER_FUNCTION_ADDRESS = "01002200"; + protected static final String SIMPLE_FUNCTION_ADDRESS = "01002239"; + protected PluginTool tool; protected ProgramDB program; protected TestEnv env; @@ -37,10 +41,6 @@ public class AbstractBlockGraphTest extends AbstractGhidraHeadedIntegrationTest private ToyProgramBuilder builder; protected CodeBrowserPlugin codeBrowser; - protected Address addr(long addr) { - return builder.getAddress(addr); - } - @Before public void setUp() throws Exception { @@ -50,7 +50,6 @@ public class AbstractBlockGraphTest extends AbstractGhidraHeadedIntegrationTest tool = env.getTool(); initializeTool(); - } @After @@ -80,14 +79,15 @@ public class AbstractBlockGraphTest extends AbstractGhidraHeadedIntegrationTest builder = new ToyProgramBuilder("sample", true); builder.createMemory("caller", "0x01002200", 8); builder.createMemory("simple", "0x01002239", 8); + builder.createMemory("not_graphed", "0x01002300", 8); - buildCallerFunction(builder); - buildSimpleFunction(builder); + buildCallerFunction(); + buildSimpleFunction(); program = builder.getProgram(); } - private void buildCallerFunction(ToyProgramBuilder builder) throws MemoryAccessException { + private void buildCallerFunction() throws MemoryAccessException { // just a function that calls another builder.addBytesNOP("0x01002200", 1); builder.addBytesCall("0x01002201", "0x01002239");// jump to C @@ -98,7 +98,7 @@ public class AbstractBlockGraphTest extends AbstractGhidraHeadedIntegrationTest builder.createLabel("0x01002200", "entry");// function label } - private void buildSimpleFunction(ToyProgramBuilder builder) throws MemoryAccessException { + private void buildSimpleFunction() throws MemoryAccessException { // just a function to render in the graph so that we can clear out settings/cache // 01002239 @@ -128,4 +128,12 @@ public class AbstractBlockGraphTest extends AbstractGhidraHeadedIntegrationTest builder.createLabel("0x01002239", "simple");// function label } + protected Address addr(long addr) { + return builder.getAddress(addr); + } + + protected Address addr(String addressString) { + return builder.addr(addressString); + } + } diff --git a/Ghidra/Test/IntegrationTest/src/test/java/ghidra/graph/GraphActionTest.java b/Ghidra/Test/IntegrationTest/src/test/java/ghidra/graph/GraphActionTest.java index f20f320360..39584dd51d 100644 --- a/Ghidra/Test/IntegrationTest/src/test/java/ghidra/graph/GraphActionTest.java +++ b/Ghidra/Test/IntegrationTest/src/test/java/ghidra/graph/GraphActionTest.java @@ -79,7 +79,7 @@ public class GraphActionTest extends AbstractGhidraHeadedIntegrationTest { assertTrue(selectedVertices.contains(b)); // now try and select a second vertex - context = new VertexGraphActionContext(graphComponentProvider, graph, null, null,d); + context = new VertexGraphActionContext(graphComponentProvider, graph, null, null, d); performAction(action, context, true); selectedVertices = display.getSelectedVertices(); assertEquals(2, selectedVertices.size()); @@ -197,7 +197,6 @@ public class GraphActionTest extends AbstractGhidraHeadedIntegrationTest { assertTrue(selectedVerticeIds.contains(c)); } - @Test public void testGrowSelectionIn() { select(d);