Search in sources :

Example 6 with FunctionBlock

use of com.google.security.zynamics.binnavi.API.disassembly.FunctionBlock in project binnavi by google.

the class PathFinder method findPassedFunctions.

/**
 * Determines all functions that lie on all possible paths between a given start function and a
 * given target function.
 *
 * @param callgraph The Call graph that contains all function call information.
 * @param startFunction The start function of the path.
 * @param targetFunction The target function of the path.
 *
 * @return A set of all functions that are passed on the possible paths between the start function
 *         and the end function.
 */
private static LinkedHashSet<FunctionBlock> findPassedFunctions(final Callgraph callgraph, final Function startFunction, final Function targetFunction) {
    // Find the graph nodes that correspond to the functions in the graph
    final FunctionBlock sourceCallgraphNode = findBlock(callgraph, startFunction);
    final FunctionBlock targetCallgraphNode = findBlock(callgraph, targetFunction);
    Logger.info("Source block: %s\n", sourceCallgraphNode.getFunction().getName());
    Logger.info("Target block: %s\n", targetCallgraphNode.getFunction().getName());
    // Passed functions = Intersection of the successors of the start function and the predecessors
    // of the target function.
    final Collection<FunctionBlock> successorFunctions = GraphAlgorithms.getSuccessors(sourceCallgraphNode);
    final Collection<FunctionBlock> predecessorFunctions = GraphAlgorithms.getPredecessors(targetCallgraphNode);
    final LinkedHashSet<FunctionBlock> sharedFunctions = new LinkedHashSet<FunctionBlock>(successorFunctions);
    sharedFunctions.retainAll(predecessorFunctions);
    sharedFunctions.add(sourceCallgraphNode);
    sharedFunctions.add(targetCallgraphNode);
    return sharedFunctions;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) FunctionBlock(com.google.security.zynamics.binnavi.API.disassembly.FunctionBlock)

Aggregations

FunctionBlock (com.google.security.zynamics.binnavi.API.disassembly.FunctionBlock)6 Function (com.google.security.zynamics.binnavi.API.disassembly.Function)5 BasicBlock (com.google.security.zynamics.binnavi.API.disassembly.BasicBlock)3 ViewEdge (com.google.security.zynamics.binnavi.API.disassembly.ViewEdge)3 ViewNode (com.google.security.zynamics.binnavi.API.disassembly.ViewNode)3 CodeNode (com.google.security.zynamics.binnavi.API.disassembly.CodeNode)2 HashMap (java.util.HashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 BlockEdge (com.google.security.zynamics.binnavi.API.disassembly.BlockEdge)1 CouldntSaveDataException (com.google.security.zynamics.binnavi.API.disassembly.CouldntSaveDataException)1 FunctionNode (com.google.security.zynamics.binnavi.API.disassembly.FunctionNode)1 Instruction (com.google.security.zynamics.binnavi.API.disassembly.Instruction)1 View (com.google.security.zynamics.binnavi.API.disassembly.View)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1