use of com.google.security.zynamics.binnavi.API.disassembly.ViewEdge in project binnavi by google.
the class PathFinder method splitBlock.
/**
* Splits a code node into two nodes at a function call. If the input node really is split, it is
* removed from the view. If the input node is not split (because the calling instruction is the
* last instruction of the code node) then the view nodes remain unchanged.
*
* @param view The view the code node belongs to.
* @param function The function the code node belongs to.
* @param node The node to split.
* @param instruction The calling instruction after which the node is split.
*
* @return A node pair that contains the two new nodes or the input node and null if the input
* node was not split.
*/
private static NodePair splitBlock(final View view, final Function function, final CodeNode node, final Instruction instruction) {
boolean before = true;
final List<Instruction> beforeInstructions = new ArrayList<Instruction>();
final List<Instruction> afterInstructions = new ArrayList<Instruction>();
for (final Instruction nodeInstruction : node.getInstructions()) {
if (before) {
beforeInstructions.add(nodeInstruction);
} else {
afterInstructions.add(nodeInstruction);
}
if (nodeInstruction == instruction) {
before = false;
}
}
if (afterInstructions.isEmpty()) {
return new NodePair(node, null);
} else {
final CodeNode firstNode = view.createCodeNode(function, beforeInstructions);
final CodeNode secondNode = view.createCodeNode(function, afterInstructions);
firstNode.setColor(node.getColor());
secondNode.setColor(DEFAULT_BLOCK_COLOR);
for (final ViewEdge edge : node.getIncomingEdges()) {
final ViewEdge newEdge = view.createEdge(edge.getSource(), firstNode, edge.getType());
newEdge.setColor(edge.getColor());
}
for (final ViewEdge edge : node.getOutgoingEdges()) {
final ViewEdge newEdge = view.createEdge(secondNode, edge.getTarget(), edge.getType());
newEdge.setColor(edge.getColor());
}
view.deleteNode(node);
return new NodePair(firstNode, secondNode);
}
}
Aggregations