Search in sources :

Example 11 with BasicBlock

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

the class PathFinderTest method testRecursivePath.

@Test
public void testRecursivePath() throws CouldntLoadDataException, PartialLoadException {
    // Tests pathfinding from a simple function to a simple function through
    // a recursive path
    // GetVolumePathNameA
    final Function startFunction = findFunction(m_kernel32, 0x7C82E8B2);
    final BasicBlock startBlock = findBlock(startFunction, 0x7C82E8B2);
    final Function endFunction = findFunction(m_kernel32, 0x7C8092B0);
    final BasicBlock endBlock = findBlock(endFunction, 0x7C8092B0);
    final View view = PathFinder.createPath(m_kernel32, startBlock, endBlock, null, null);
    assertEquals(1247, view.getGraph().nodeCount());
    assertEquals(1988, view.getGraph().edgeCount());
}
Also used : Function(com.google.security.zynamics.binnavi.API.disassembly.Function) BasicBlock(com.google.security.zynamics.binnavi.API.disassembly.BasicBlock) View(com.google.security.zynamics.binnavi.API.disassembly.View) Test(org.junit.Test)

Example 12 with BasicBlock

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

the class PathFinderTest method testFirstBlock.

@Test
public void testFirstBlock() throws CouldntLoadDataException, PartialLoadException {
    // Tests 100337E -> 1005179 -> 1007568 where all calls are in the first block
    // of the respective functions.
    // Tests path finding from the beginning to the end of a single function
    final Function startFunction = findFunction(m_notepad, 0x100337E);
    final BasicBlock startBlock = findBlock(startFunction, 0x10033C2);
    final Function endFunction = findFunction(m_notepad, 0x1007568);
    final BasicBlock endBlock = findBlock(endFunction, 0x1007568);
    final View view = PathFinder.createPath(m_notepad, startBlock, endBlock, null, null);
    assertEquals(3, view.getGraph().nodeCount());
    assertEquals(2, view.getGraph().edgeCount());
}
Also used : Function(com.google.security.zynamics.binnavi.API.disassembly.Function) BasicBlock(com.google.security.zynamics.binnavi.API.disassembly.BasicBlock) View(com.google.security.zynamics.binnavi.API.disassembly.View) Test(org.junit.Test)

Example 13 with BasicBlock

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

the class PathFinder method findEntryExitNodes.

/**
 * Finds the entry nodes and exit nodes of all functions that lie on the path. This is necessary
 * for function inlining.
 *
 * @param passedFunctions All functions that lie on the path.
 * @param nodeMap Maps between the basic blocks of the functions and their corresponding code
 *        nodes.
 * @param functionMap Keeps track to what function a view node belongs to.
 * @param entryNodes Keeps track of the entry nodes of all functions.
 * @param exitNodes Keeps track of the exit nodes of all functions.
 */
private static void findEntryExitNodes(final Collection<FunctionBlock> passedFunctions, final Map<BasicBlock, ViewNode> nodeMap, final Map<ViewNode, Function> functionMap, final Map<Function, ViewNode> entryNodes, final ArrayListMultimap<Function, ViewNode> exitNodes) {
    // actually do have basic blocks.
    for (final FunctionBlock functionBlock : passedFunctions) {
        final Function function = functionBlock.getFunction();
        if (function.getType() != FunctionType.Import) {
            entryNodes.put(function, nodeMap.get(findEntryNode(function)));
            for (final BasicBlock block : findExitNode(function.getGraph())) {
                exitNodes.put(function, nodeMap.get(block));
            }
        }
    }
    // Afterwards we find the entry and exit nodes of the imported functions.
    for (final Map.Entry<ViewNode, Function> p : functionMap.entrySet()) {
        final Function function = p.getValue();
        if (function.getType() == FunctionType.Import) {
            final ViewNode node = p.getKey();
            entryNodes.put(function, node);
            exitNodes.put(function, node);
        }
    }
}
Also used : Function(com.google.security.zynamics.binnavi.API.disassembly.Function) BasicBlock(com.google.security.zynamics.binnavi.API.disassembly.BasicBlock) ViewNode(com.google.security.zynamics.binnavi.API.disassembly.ViewNode) HashMap(java.util.HashMap) Map(java.util.Map) FunctionBlock(com.google.security.zynamics.binnavi.API.disassembly.FunctionBlock)

Example 14 with BasicBlock

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

the class PathFinder method createInitialBlocks.

/**
 * Creates the initial nodes for all basic blocks in the passed functions.
 *
 * @param view The view where the nodes are created.
 *
 * @param passedFunctions All functions that lie on the path.
 * @param nodeMap Maps basic blocks of the functions on the path to their corresponding view
 *        nodes.
 * @param functionMap Keeps track to what function a node belongs to.
 *
 * @throws CouldntLoadDataException Thrown if a function could not be loaded.
 */
private static void createInitialBlocks(final View view, final Collection<FunctionBlock> passedFunctions, final Map<BasicBlock, ViewNode> nodeMap, final Map<ViewNode, Function> functionMap) throws CouldntLoadDataException {
    for (final FunctionBlock functionBlock : passedFunctions) {
        final Function function = functionBlock.getFunction();
        if (function.getType() == FunctionType.Import) {
            // Imported functions to not have any basic blocks, for those functions
            // we simply create a function node.
            final FunctionNode newNode = view.createFunctionNode(function);
            functionMap.put(newNode, function);
        // TODO (timkornau): Assign a proper color to the node.
        // TODO (timkornau): Properly treat forwarded functions.
        } else {
            function.load();
            for (final BasicBlock block : function.getGraph().getNodes()) {
                final CodeNode newNode = view.createCodeNode(function, block.getInstructions());
                newNode.setColor(DEFAULT_BLOCK_COLOR);
                nodeMap.put(block, newNode);
                functionMap.put(newNode, function);
            }
        }
    }
}
Also used : Function(com.google.security.zynamics.binnavi.API.disassembly.Function) CodeNode(com.google.security.zynamics.binnavi.API.disassembly.CodeNode) FunctionNode(com.google.security.zynamics.binnavi.API.disassembly.FunctionNode) BasicBlock(com.google.security.zynamics.binnavi.API.disassembly.BasicBlock) FunctionBlock(com.google.security.zynamics.binnavi.API.disassembly.FunctionBlock)

Aggregations

BasicBlock (com.google.security.zynamics.binnavi.API.disassembly.BasicBlock)14 Function (com.google.security.zynamics.binnavi.API.disassembly.Function)13 View (com.google.security.zynamics.binnavi.API.disassembly.View)10 Test (org.junit.Test)9 FunctionBlock (com.google.security.zynamics.binnavi.API.disassembly.FunctionBlock)3 ViewNode (com.google.security.zynamics.binnavi.API.disassembly.ViewNode)3 ViewEdge (com.google.security.zynamics.binnavi.API.disassembly.ViewEdge)2 HashMap (java.util.HashMap)2 CodeNode (com.google.security.zynamics.binnavi.API.disassembly.CodeNode)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 IProgressThread (com.google.security.zynamics.binnavi.API.helpers.IProgressThread)1 IInstruction (com.google.security.zynamics.zylib.disassembly.IInstruction)1 Map (java.util.Map)1