Search in sources :

Example 1 with FunctionNode

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

the class OutputGraphGenerator method createLoggedView.

/**
   * 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 createLoggedView(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 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);
        FunctionNode sourceNode = nodes.get(call.getFunction());
        if (sourceNode == null) {
            sourceNode = view.createFunctionNode(call.getFunction());
            nodes.put(call.getFunction(), sourceNode);
        }
        for (final ResolvedFunction targetFunction : targets) {
            final Function function = targetFunction.getFunction();
            final MemoryModule memoryModule = targetFunction.getMemoryModule();
            if (function != null) {
                FunctionNode targetNode = nodes.get(function);
                if (targetNode == null) {
                    targetNode = view.createFunctionNode(function);
                    nodes.put(function, targetNode);
                }
                try {
                    sourceNode.appendComment(start.toString(16).toUpperCase() + " -> " + function.getAddress().toHexString().toUpperCase());
                } catch (CouldntSaveDataException | CouldntLoadDataException e) {
                    e.printStackTrace();
                }
                view.createEdge(sourceNode, targetNode, EdgeType.JumpUnconditional);
            } else if (memoryModule != null) {
                final String targetString = String.format("%s!%s", targetFunction.getMemoryModule().getName(), targetFunction.getAddress().toHexString().toUpperCase());
                try {
                    sourceNode.appendComment(start.toString(16).toUpperCase() + " -> " + targetString);
                } catch (CouldntSaveDataException | CouldntLoadDataException e) {
                    e.printStackTrace();
                }
            } else {
                final String targetString = "???!" + targetFunction.getAddress().toHexString().toUpperCase();
                try {
                    sourceNode.appendComment(start.toString(16).toUpperCase() + " -> " + targetString);
                } catch (CouldntSaveDataException | CouldntLoadDataException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    for (final Module module : target.getModules()) {
        final Callgraph callgraph = module.getCallgraph();
        for (final FunctionEdge edge : callgraph.getEdges()) {
            final FunctionNode source = nodes.get(edge.getSource().getFunction());
            final FunctionNode targetNode = nodes.get(edge.getTarget().getFunction());
            if ((source != null) && (targetNode != null)) {
                view.createEdge(source, targetNode, EdgeType.JumpUnconditional);
            }
        }
    }
    return view;
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) CouldntSaveDataException(com.google.security.zynamics.binnavi.API.disassembly.CouldntSaveDataException) CouldntLoadDataException(com.google.security.zynamics.binnavi.API.disassembly.CouldntLoadDataException) FunctionNode(com.google.security.zynamics.binnavi.API.disassembly.FunctionNode) View(com.google.security.zynamics.binnavi.API.disassembly.View) MemoryModule(com.google.security.zynamics.binnavi.API.debug.MemoryModule) 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) BigInteger(java.math.BigInteger) Module(com.google.security.zynamics.binnavi.API.disassembly.Module) MemoryModule(com.google.security.zynamics.binnavi.API.debug.MemoryModule)

Example 2 with FunctionNode

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

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

Example 4 with FunctionNode

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

the class BreakpointHelpers method getBreakpoints.

/**
   * Returns the addresses of a view where breakpoints are set.
   *
   * @param debugger The debugger that set the breakpoint.
   * @param view The view to search through.
   * @param type Type of the breakpoints to search for.
   *
   * @return The addresses of the view where breakpoints of a given type are set.
   */
private static List<Address> getBreakpoints(final Debugger debugger, final View view, final BreakpointType type) {
    Preconditions.checkNotNull(debugger, "Error: Debugger argument can not be null");
    Preconditions.checkNotNull(view, "Error: View argument can not be null");
    final BreakpointManager manager = debugger.getBreakpointManager();
    final List<Address> breakpoints = new ArrayList<Address>();
    for (final ViewNode node : view.getGraph().getNodes()) {
        if (node instanceof CodeNode) {
            breakpoints.addAll(getBreakpoints(debugger, (CodeNode) node, type));
        } else if (node instanceof FunctionNode) {
            final FunctionNode fnode = (FunctionNode) node;
            final BreakpointAddress address = new BreakpointAddress(fnode.getFunction().getNative().getModule(), new UnrelocatedAddress(fnode.getFunction().getNative().getAddress()));
            if (manager.getNative().hasBreakpoint(type, address)) {
                breakpoints.add(new Address(address.getAddress().getAddress().toBigInteger()));
            }
        }
    }
    return breakpoints;
}
Also used : CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) Address(com.google.security.zynamics.binnavi.API.disassembly.Address) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) CodeNode(com.google.security.zynamics.binnavi.API.disassembly.CodeNode) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) ArrayList(java.util.ArrayList) FunctionNode(com.google.security.zynamics.binnavi.API.disassembly.FunctionNode) ViewNode(com.google.security.zynamics.binnavi.API.disassembly.ViewNode) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress)

Aggregations

FunctionNode (com.google.security.zynamics.binnavi.API.disassembly.FunctionNode)4 Function (com.google.security.zynamics.binnavi.API.disassembly.Function)3 MemoryModule (com.google.security.zynamics.binnavi.API.debug.MemoryModule)2 Callgraph (com.google.security.zynamics.binnavi.API.disassembly.Callgraph)2 CodeNode (com.google.security.zynamics.binnavi.API.disassembly.CodeNode)2 FunctionEdge (com.google.security.zynamics.binnavi.API.disassembly.FunctionEdge)2 Module (com.google.security.zynamics.binnavi.API.disassembly.Module)2 View (com.google.security.zynamics.binnavi.API.disassembly.View)2 BigInteger (java.math.BigInteger)2 HashMap (java.util.HashMap)2 Set (java.util.Set)2 Address (com.google.security.zynamics.binnavi.API.disassembly.Address)1 BasicBlock (com.google.security.zynamics.binnavi.API.disassembly.BasicBlock)1 CouldntLoadDataException (com.google.security.zynamics.binnavi.API.disassembly.CouldntLoadDataException)1 CouldntSaveDataException (com.google.security.zynamics.binnavi.API.disassembly.CouldntSaveDataException)1 FunctionBlock (com.google.security.zynamics.binnavi.API.disassembly.FunctionBlock)1 ViewEdge (com.google.security.zynamics.binnavi.API.disassembly.ViewEdge)1 ViewNode (com.google.security.zynamics.binnavi.API.disassembly.ViewNode)1 BreakpointAddress (com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress)1 UnrelocatedAddress (com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress)1