Search in sources :

Example 6 with ViewEdge

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);
    }
}
Also used : CodeNode(com.google.security.zynamics.binnavi.API.disassembly.CodeNode) ArrayList(java.util.ArrayList) ViewEdge(com.google.security.zynamics.binnavi.API.disassembly.ViewEdge) Instruction(com.google.security.zynamics.binnavi.API.disassembly.Instruction)

Aggregations

ViewEdge (com.google.security.zynamics.binnavi.API.disassembly.ViewEdge)6 Function (com.google.security.zynamics.binnavi.API.disassembly.Function)5 FunctionBlock (com.google.security.zynamics.binnavi.API.disassembly.FunctionBlock)3 View (com.google.security.zynamics.binnavi.API.disassembly.View)3 ViewNode (com.google.security.zynamics.binnavi.API.disassembly.ViewNode)3 BasicBlock (com.google.security.zynamics.binnavi.API.disassembly.BasicBlock)2 CodeNode (com.google.security.zynamics.binnavi.API.disassembly.CodeNode)2 Instruction (com.google.security.zynamics.binnavi.API.disassembly.Instruction)2 HashMap (java.util.HashMap)2 MemoryModule (com.google.security.zynamics.binnavi.API.debug.MemoryModule)1 BlockEdge (com.google.security.zynamics.binnavi.API.disassembly.BlockEdge)1 Callgraph (com.google.security.zynamics.binnavi.API.disassembly.Callgraph)1 CouldntSaveDataException (com.google.security.zynamics.binnavi.API.disassembly.CouldntSaveDataException)1 FunctionEdge (com.google.security.zynamics.binnavi.API.disassembly.FunctionEdge)1 FunctionNode (com.google.security.zynamics.binnavi.API.disassembly.FunctionNode)1 Module (com.google.security.zynamics.binnavi.API.disassembly.Module)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1