Search in sources :

Example 11 with Function

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

the class OutputGraphGenerator method createCompleteView.

/**
   * Creates a view that shows all nodes and edges from the original call graph in addition to the
   * newly resolved functions.
   * 
   * @param target The target whose indirect modules were resolved.
   * @param indirectCallAddresses The addresses of the indirect call objects from the target.
   * @param resolvedAddresses The resolved function addresses.
   * 
   * @return The generated view.
   */
public static View createCompleteView(final ICallResolverTarget target, final List<IndirectCall> indirectCallAddresses, final Map<BigInteger, Set<ResolvedFunction>> resolvedAddresses) {
    final View view = target.createView();
    final Map<Function, FunctionNode> nodes = new HashMap<Function, FunctionNode>();
    for (final Module module : target.getModules()) {
        for (final Function function : module.getFunctions()) {
            final FunctionNode node = view.createFunctionNode(function);
            nodes.put(function, node);
        }
        final Callgraph callgraph = module.getCallgraph();
        for (final FunctionEdge edge : callgraph.getEdges()) {
            final FunctionNode sourceNode = nodes.get(edge.getSource().getFunction());
            final FunctionNode targetNode = nodes.get(edge.getTarget().getFunction());
            view.createEdge(sourceNode, targetNode, EdgeType.JumpUnconditional);
        }
    }
    for (final Entry<BigInteger, Set<ResolvedFunction>> element : resolvedAddresses.entrySet()) {
        final BigInteger start = element.getKey();
        final Set<ResolvedFunction> targets = element.getValue();
        final IndirectCall call = IndirectCallResolver.findIndirectCall(target.getDebugger(), indirectCallAddresses, start);
        final FunctionNode sourceNode = nodes.get(call.getFunction());
        if (sourceNode != null) {
            for (final ResolvedFunction targetFunction : targets) {
                final Function function = targetFunction.getFunction();
                if (function != null) {
                    final FunctionNode targetNode = nodes.get(function);
                    final ViewEdge edge = view.createEdge(sourceNode, targetNode, EdgeType.JumpUnconditional);
                    edge.setColor(Color.RED);
                }
            }
        }
    }
    return view;
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) FunctionNode(com.google.security.zynamics.binnavi.API.disassembly.FunctionNode) View(com.google.security.zynamics.binnavi.API.disassembly.View) Function(com.google.security.zynamics.binnavi.API.disassembly.Function) Callgraph(com.google.security.zynamics.binnavi.API.disassembly.Callgraph) FunctionEdge(com.google.security.zynamics.binnavi.API.disassembly.FunctionEdge) ViewEdge(com.google.security.zynamics.binnavi.API.disassembly.ViewEdge) BigInteger(java.math.BigInteger) Module(com.google.security.zynamics.binnavi.API.disassembly.Module) MemoryModule(com.google.security.zynamics.binnavi.API.debug.MemoryModule)

Example 12 with Function

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

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

the class PathFinderTest method testRecursiveTarget.

@Test
public void testRecursiveTarget() throws CouldntLoadDataException, PartialLoadException {
    // Tests pathfinding from a simple function to a self-recursive function
    // SetCommConfig
    final Function startFunction = findFunction(m_kernel32, 0x7C866E7B);
    final BasicBlock startBlock = findBlock(startFunction, 0x7C866EF3);
    // SetCommState
    final Function endFunction = findFunction(m_kernel32, 0x7C865E16);
    final BasicBlock endBlock = findBlock(endFunction, 0x7C866106);
    final View view = PathFinder.createPath(m_kernel32, startBlock, endBlock, null, null);
    assertEquals(2 + /** calling function **/
    66 + /** called function **/
    3, /** split blocks **/
    view.getGraph().nodeCount());
    assertEquals(99 + /** called function **/
    1 + /** calling target function **/
    3 + 3, /** recursive calls and returns **/
    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 14 with Function

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

the class PathFinderTest method testPassingFunctionReturn.

@Test
public void testPassingFunctionReturn() throws CouldntLoadDataException, PartialLoadException {
    // Tests pathfinding from one function to another function while passing one function
    // and having a target block that is a RETURN block.
    //
    // What should happen here is that the pathfinding algorithm stops when it reaches
    // the RETURN node. That is consecutive calls to the target function should not
    // be part of the pathfinding result.
    // 0x1004565 -> 0x1003C92 -> 0x100398D
    final Function startFunction = findFunction(m_notepad, 0x1004565);
    final BasicBlock startBlock = findBlock(startFunction, 0x1004629);
    final Function endFunction = findFunction(m_notepad, 0x100398D);
    final BasicBlock endBlock = findBlock(endFunction, 0x10039D9);
    final View view = PathFinder.createPath(m_notepad, startBlock, endBlock, null, null);
    assertEquals(14, view.getGraph().nodeCount());
    assertEquals(19, 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 15 with Function

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

the class PathFinderTest method testInsideFunction.

// @Test
// public void testFoo() throws CouldntLoadDataException, CouldntSaveDataException
// {
// // TODO: Bring this test back in msw3prt.idb
//
// final Function startFunction = findFunction(m_foo, 0x5FEF8426);
// final BasicBlock startBlock = findBlock(startFunction, 0x5FEF8426);
//
// final Function endFunction = findFunction(m_foo, 0x5FEFF06D);
// final BasicBlock endBlock = findBlock(endFunction, 0x5FEFF0DB);
//
// final View view = PathFinder.createPath(m_foo, startBlock, endBlock, null, null);
//
// assertEquals(46, view.getGraph().nodeCount());
// assertEquals(49, view.getGraph().edgeCount());
// }
@Test
public void testInsideFunction() throws CouldntLoadDataException, PartialLoadException {
    // Tests path finding from the beginning to the end of a single function
    final Function startFunction = findFunction(m_notepad, 0x01002B87);
    final BasicBlock startBlock = findBlock(startFunction, 0x1002B87);
    final BasicBlock endBlock = findBlock(startFunction, 0x100336A);
    final View view = PathFinder.createPath(m_notepad, startBlock, endBlock, null, null);
    assertEquals(96, view.getGraph().nodeCount());
    assertEquals(150, 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)

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