Search in sources :

Example 16 with Function

use of com.google.security.zynamics.binnavi.API.disassembly.Function 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 17 with Function

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

the class PathFinderTest method testToImportedFunction.

@Test
public void testToImportedFunction() throws CouldntLoadDataException, PartialLoadException {
    // Tests from the beginning of a function to an imported function
    final Function startFunction = findFunction(m_notepad, 0x0100398D);
    final BasicBlock startBlock = findBlock(startFunction, 0x100398D);
    final Function endFunction = findFunction(m_notepad, 0x1001000);
    endFunction.load();
    final View view = PathFinder.createPath(m_notepad, startBlock, null, null, endFunction);
    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 18 with Function

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

the class OutputListGenerator method generate.

/**
   * Generates a string that shows the resolved functions.
   * 
   * @param resolvedAddresses The function resolver result.
   * 
   * @return The string that shows the resolved functions.
   */
public static String generate(final Map<BigInteger, Set<ResolvedFunction>> resolvedAddresses) {
    assert resolvedAddresses != null;
    final StringBuffer buffer = new StringBuffer();
    buffer.append("Resolved the following indirect calls:\n");
    for (final Entry<BigInteger, Set<ResolvedFunction>> element : sort(resolvedAddresses.entrySet())) {
        final BigInteger start = element.getKey();
        final Set<ResolvedFunction> targets = element.getValue();
        buffer.append(String.format("%08X ->\n", start.longValue()));
        for (final ResolvedFunction target : targets) {
            if (target.getFunction() != null) {
                final Function function = target.getFunction();
                final Address functionAddress = function.getAddress();
                final String functionName = function.getModule().getName() + "!" + function.getName();
                buffer.append(String.format("  %08X (%s)\n", functionAddress.toLong(), functionName));
            } else if (target.getMemoryModule() != null) {
                final MemoryModule module = target.getMemoryModule();
                final Address functionAddress = target.getAddress();
                final String functionName = module.getName() + "!???";
                buffer.append(String.format("  %08X (%s)\n", functionAddress.toLong(), functionName));
            } else {
                final Address address = target.getAddress();
                buffer.append(String.format("  %s (%s)\n", address.toHexString().toUpperCase(), "???!???"));
            }
        }
    }
    return buffer.toString();
}
Also used : Function(com.google.security.zynamics.binnavi.API.disassembly.Function) Set(java.util.Set) Address(com.google.security.zynamics.binnavi.API.disassembly.Address) BigInteger(java.math.BigInteger) MemoryModule(com.google.security.zynamics.binnavi.API.debug.MemoryModule)

Example 19 with Function

use of com.google.security.zynamics.binnavi.API.disassembly.Function 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 20 with Function

use of com.google.security.zynamics.binnavi.API.disassembly.Function 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

Function (com.google.security.zynamics.binnavi.API.disassembly.Function)22 BasicBlock (com.google.security.zynamics.binnavi.API.disassembly.BasicBlock)13 View (com.google.security.zynamics.binnavi.API.disassembly.View)13 Test (org.junit.Test)9 HashMap (java.util.HashMap)6 FunctionBlock (com.google.security.zynamics.binnavi.API.disassembly.FunctionBlock)5 ViewEdge (com.google.security.zynamics.binnavi.API.disassembly.ViewEdge)5 MemoryModule (com.google.security.zynamics.binnavi.API.debug.MemoryModule)4 Address (com.google.security.zynamics.binnavi.API.disassembly.Address)4 Module (com.google.security.zynamics.binnavi.API.disassembly.Module)4 ViewNode (com.google.security.zynamics.binnavi.API.disassembly.ViewNode)4 FunctionNode (com.google.security.zynamics.binnavi.API.disassembly.FunctionNode)3 BigInteger (java.math.BigInteger)3 Set (java.util.Set)3 Callgraph (com.google.security.zynamics.binnavi.API.disassembly.Callgraph)2 CodeNode (com.google.security.zynamics.binnavi.API.disassembly.CodeNode)2 CouldntSaveDataException (com.google.security.zynamics.binnavi.API.disassembly.CouldntSaveDataException)2 FunctionEdge (com.google.security.zynamics.binnavi.API.disassembly.FunctionEdge)2 Instruction (com.google.security.zynamics.binnavi.API.disassembly.Instruction)2 BlockEdge (com.google.security.zynamics.binnavi.API.disassembly.BlockEdge)1