mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 18:29:37 +02:00
Changed graph api to use vertex and edge object instead of ids.
This commit is contained in:
parent
3cd26120a3
commit
592b8a3cfc
14 changed files with 292 additions and 283 deletions
|
@ -157,13 +157,13 @@ public class BlockGraphTask extends Task {
|
|||
|
||||
if (location != null) {
|
||||
// initialize the graph location, but don't have the graph send an event
|
||||
String id = listener.getVertexIdForAddress(location.getAddress());
|
||||
display.setLocationFocus(id, EventTrigger.INTERNAL_ONLY);
|
||||
AttributedVertex vertex = listener.getVertex(location.getAddress());
|
||||
display.setFocusedVertex(vertex, EventTrigger.INTERNAL_ONLY);
|
||||
}
|
||||
if (selection != null && !selection.isEmpty()) {
|
||||
List<String> selectedVertices = listener.getVertices(selection);
|
||||
Set<AttributedVertex> selectedVertices = listener.getVertices(selection);
|
||||
if (selectedVertices != null) {
|
||||
// intialize the graph selection, but don't have the graph send an event
|
||||
// initialize the graph selection, but don't have the graph send an event
|
||||
display.selectVertices(selectedVertices, EventTrigger.INTERNAL_ONLY);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,28 +54,28 @@ public class BlockModelGraphDisplayListener extends AddressBasedGraphDisplayList
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String getVertexIdForAddress(Address address) {
|
||||
protected String getVertexId(Address address) {
|
||||
try {
|
||||
CodeBlock[] blocks = blockModel.getCodeBlocksContaining(address, TaskMonitor.DUMMY);
|
||||
if (blocks != null && blocks.length > 0) {
|
||||
return super.getVertexIdForAddress(blocks[0].getFirstStartAddress());
|
||||
return super.getVertexId(blocks[0].getFirstStartAddress());
|
||||
}
|
||||
}
|
||||
catch (CancelledException e) {
|
||||
// Will not happen with dummyMonitor
|
||||
// Model has already done the work when the graph was created
|
||||
}
|
||||
return super.getVertexIdForAddress(address);
|
||||
return super.getVertexId(address);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getVertices(AddressSetView addrSet) {
|
||||
protected Set<AttributedVertex> getVertices(AddressSetView addrSet) {
|
||||
if (addrSet.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
// Identify all blocks which have an entry point within the selection address set
|
||||
ArrayList<String> blockList = new ArrayList<String>();
|
||||
Set<AttributedVertex> vertices = new HashSet<>();
|
||||
try {
|
||||
SymbolTable symTable = program.getSymbolTable();
|
||||
CodeBlockIterator cbIter =
|
||||
|
@ -91,7 +91,10 @@ public class BlockModelGraphDisplayListener extends AddressBasedGraphDisplayList
|
|||
else {
|
||||
addrString = addr.toString();
|
||||
}
|
||||
blockList.add(addrString);
|
||||
AttributedVertex vertex = graphDisplay.getGraph().getVertex(addrString);
|
||||
if (vertex != null) {
|
||||
vertices.add(vertex);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (CancelledException e) {
|
||||
|
@ -99,18 +102,18 @@ public class BlockModelGraphDisplayListener extends AddressBasedGraphDisplayList
|
|||
// Model has already done the work when the graph was created
|
||||
}
|
||||
|
||||
return blockList;
|
||||
return vertices;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AddressSet getAddressSetForVertices(List<String> vertexIds) {
|
||||
protected AddressSet getAddresses(Set<AttributedVertex> vertices) {
|
||||
AddressSet addrSet = new AddressSet();
|
||||
|
||||
try {
|
||||
// for each address string, translate it into a block
|
||||
// and add it to the address set.
|
||||
for (String vertexId : vertexIds) {
|
||||
Address blockAddr = getAddressForVertexId(vertexId);
|
||||
for (AttributedVertex vertex : vertices) {
|
||||
Address blockAddr = getAddress(vertex);
|
||||
if (!isValidAddress(blockAddr)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -150,8 +153,8 @@ public class BlockModelGraphDisplayListener extends AddressBasedGraphDisplayList
|
|||
}
|
||||
|
||||
private void updateVertexName(VertexGraphActionContext context) {
|
||||
String vertexId = context.getClickedVertex().getId();
|
||||
Address address = getAddressForVertexId(vertexId);
|
||||
AttributedVertex vertex = context.getClickedVertex();
|
||||
Address address = getAddress(vertex);
|
||||
Symbol symbol = program.getSymbolTable().getPrimarySymbol(address);
|
||||
|
||||
if (symbol == null) {
|
||||
|
@ -165,8 +168,8 @@ public class BlockModelGraphDisplayListener extends AddressBasedGraphDisplayList
|
|||
}
|
||||
|
||||
@Override
|
||||
public GraphDisplayListener cloneWith(GraphDisplay graphDisplay) {
|
||||
return new BlockModelGraphDisplayListener(tool, blockModel, graphDisplay);
|
||||
public GraphDisplayListener cloneWith(GraphDisplay newGraphDisplay) {
|
||||
return new BlockModelGraphDisplayListener(tool, blockModel, newGraphDisplay);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue