Search in sources :

Example 56 with INaviCodeNode

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

the class View method createNode.

// ! Clones an existing node.
/**
   * Creates a new view node by cloning an existing view node.
   *
   * @param node The node to clone.
   *
   * @return The cloned node.
   */
public ViewNode createNode(final ViewNode node) {
    Preconditions.checkNotNull(node, "Error: Node argument can not be null");
    if (node instanceof CodeNode) {
        final List<INaviInstruction> instructionsList = new ArrayList<INaviInstruction>();
        for (final Instruction instruction : ((CodeNode) node).getInstructions()) {
            Preconditions.checkNotNull(instruction, "Error: Instruction list contains a null-element");
            instructionsList.add(instruction.getNative());
        }
        CCodeNode newNode;
        try {
            newNode = naviView.getContent().createCodeNode(((INaviCodeNode) node.getNative()).getParentFunction(), instructionsList);
        } catch (final MaybeNullException e) {
            newNode = naviView.getContent().createCodeNode(null, instructionsList);
        }
        adjustAttributes(node, newNode);
        return cachedNodes.get(newNode);
    } else if (node instanceof FunctionNode) {
        final CFunctionNode newNode = naviView.getContent().createFunctionNode(((INaviFunctionNode) node.getNative()).getFunction());
        adjustAttributes(node, newNode);
        return cachedNodes.get(newNode);
    } else if (node instanceof TextNode) {
        final CTextNode newNode = naviView.getContent().createTextNode(((TextNode) node).getComments());
        adjustAttributes(node, newNode);
        return cachedNodes.get(newNode);
    } else if (node instanceof GroupNode) {
        throw new IllegalStateException("Group nodes can not be cloned");
    } else {
        throw new IllegalStateException("Error: Unknown node type");
    }
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) ArrayList(java.util.ArrayList) CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) INaviTextNode(com.google.security.zynamics.binnavi.disassembly.INaviTextNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 57 with INaviCodeNode

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

the class CNodeFunctions method splitAfter.

/**
   * Splits a node.
   * 
   * @param view View the node belongs to.
   * @param originalNode Node to split.
   * @param instruction Instruction after which the node is split.
   */
public static void splitAfter(final INaviView view, final INaviCodeNode originalNode, final INaviInstruction instruction) {
    final Iterable<INaviInstruction> oldInstructions = originalNode.getInstructions();
    if (instruction == Iterables.getLast(oldInstructions)) {
        return;
    }
    // Step I: Find out what instructions belong to the new upper block and what
    // instructions belong to the new lower block.
    final List<INaviInstruction> upperInstructions = new ArrayList<INaviInstruction>();
    final List<INaviInstruction> lowerInstructions = new ArrayList<INaviInstruction>();
    List<INaviInstruction> currentInstructions = upperInstructions;
    for (final INaviInstruction oldInstruction : oldInstructions) {
        currentInstructions.add(oldInstruction);
        if (oldInstruction == instruction) {
            currentInstructions = lowerInstructions;
        }
    }
    // Step II: Create the two new code nodes.
    INaviFunction parentFunction = null;
    try {
        parentFunction = originalNode.getParentFunction();
    } catch (final MaybeNullException e) {
    // No parent function
    }
    final INaviCodeNode newNode1 = view.getContent().createCodeNode(parentFunction, upperInstructions);
    final INaviCodeNode newNode2 = view.getContent().createCodeNode(parentFunction, lowerInstructions);
    newNode1.setColor(originalNode.getColor());
    newNode1.setBorderColor(originalNode.getBorderColor());
    newNode2.setColor(originalNode.getColor());
    // Step III: Transfer node comments and instruction comments from the old node
    // to the new nodes.
    transferLocalCodeNodeComments(originalNode, newNode1, newNode2);
    // Step IV: Connect the two new nodes.
    view.getContent().createEdge(newNode1, newNode2, EdgeType.JUMP_UNCONDITIONAL);
    for (final INaviEdge incomingEdge : originalNode.getIncomingEdges()) {
        view.getContent().createEdge(incomingEdge.getSource(), newNode1, incomingEdge.getType());
    }
    for (final INaviEdge outgoingEdge : originalNode.getOutgoingEdges()) {
        view.getContent().createEdge(newNode2, outgoingEdge.getTarget(), outgoingEdge.getType());
    }
    // Step VI: Get rid of the old node.
    view.getContent().deleteNode(originalNode);
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) ArrayList(java.util.ArrayList) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 58 with INaviCodeNode

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

the class CMenuBuilder method addSelectionMenus.

/**
   * Adds menus related to node selection to a given node context menu.
   *
   * @param menu The node context menu to extend.
   * @param graph The graph the clicked node belongs to.
   * @param node The clicked node.
   */
public static void addSelectionMenus(final JPopupMenu menu, final ZyGraph graph, final NaviNode node) {
    Preconditions.checkNotNull(menu, "IE02144: Menu argument can not be null");
    Preconditions.checkNotNull(graph, "IE02145: Graph argument can not be null");
    Preconditions.checkNotNull(node, "IE02146: Node argument can not be null");
    final JMenu selectionMenu = new JMenu("Selection");
    selectionMenu.add(CActionProxy.proxy(new CActionSelectNodePredecessors(graph, node)));
    selectionMenu.add(CActionProxy.proxy(new CActionSelectNodeSuccessors(graph, node)));
    if (graph.getSelectedNodes().size() > 0) {
        selectionMenu.add(CActionProxy.proxy(new CGroupAction(graph)));
    }
    if (node.getRawNode() instanceof INaviCodeNode) {
        try {
            final INaviFunction parentFunction = ((INaviCodeNode) node.getRawNode()).getParentFunction();
            selectionMenu.add(CActionProxy.proxy(new CActionSelectSameParentFunction(graph, parentFunction)));
        } catch (final MaybeNullException exception) {
        // Obviously we can not select nodes of the same parent function if there
        // is no parent function.
        }
    } else if (node.getRawNode() instanceof INaviFunctionNode) {
        final INaviFunction function = ((INaviFunctionNode) node.getRawNode()).getFunction();
        selectionMenu.add(CActionProxy.proxy(new CActionSelectSameFunctionType(graph, function.getType())));
    }
    menu.add(selectionMenu);
    menu.addSeparator();
}
Also used : CActionSelectNodeSuccessors(com.google.security.zynamics.binnavi.ZyGraph.Menus.Actions.CActionSelectNodeSuccessors) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) CActionSelectSameParentFunction(com.google.security.zynamics.binnavi.ZyGraph.Menus.Actions.CActionSelectSameParentFunction) CGroupAction(com.google.security.zynamics.binnavi.Gui.GraphWindows.Actions.CGroupAction) CActionSelectSameFunctionType(com.google.security.zynamics.binnavi.ZyGraph.Menus.Actions.CActionSelectSameFunctionType) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) JMenu(javax.swing.JMenu) CActionSelectNodePredecessors(com.google.security.zynamics.binnavi.ZyGraph.Menus.Actions.CActionSelectNodePredecessors)

Example 59 with INaviCodeNode

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

the class CFollowInDumpMenu method addFollowInDumpMenu.

/**
   * Adds the menu that follow in dump menu for the clicked instruction.
   *
   * @param menu The code node menu that is extended.
   * @param model The graph model that provides information about the graph.
   * @param node The node whose menu is created.
   * @param clickedObject The object that was clicked.
   * @param y The y-coordinate of the click.
   */
public static void addFollowInDumpMenu(final JPopupMenu menu, final CGraphModel model, final NaviNode node, final Object clickedObject, final double y) {
    Preconditions.checkNotNull(menu, "IE02371: menu argument can not be null");
    Preconditions.checkNotNull(model, "IE02372: model argument can not be null");
    Preconditions.checkNotNull(node, "IE02373: node argument can not be null");
    final int line = node.positionToRow(y);
    if (line == -1) {
        return;
    }
    final INaviCodeNode codeNode = (INaviCodeNode) node.getRawNode();
    final INaviInstruction instruction = CCodeNodeHelpers.lineToInstruction(codeNode, line);
    if (instruction != null) {
        final IDebugger debugger = CGraphDebugger.getDebugger(model.getDebuggerProvider(), instruction);
        if ((debugger != null) && (clickedObject instanceof COperandTreeNode)) {
            final TargetProcessThread activeThread = debugger.getProcessManager().getActiveThread();
            if (activeThread != null) {
                final CDebugPerspectiveModel viewModel = (CDebugPerspectiveModel) model.getGraphPanel().getViewModel().getModel(PerspectiveType.DebugPerspective);
                final COperandTreeNode treeNode = (COperandTreeNode) clickedObject;
                final boolean added = addFollowInDumpMenu(menu, viewModel, debugger, activeThread, instruction.getModule(), treeNode);
                if (added) {
                    menu.addSeparator();
                }
            }
        }
    }
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) CDebugPerspectiveModel(com.google.security.zynamics.binnavi.Gui.GraphWindows.Panels.CDebugPerspectiveModel) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) IDebugger(com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 60 with INaviCodeNode

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

the class CDebuggerPainter method updateSingleNodeDebuggerHighlighting.

/**
   * Updates the debugger highlighting for a single node
   *
   * @param graph The graph in which the node is located
   * @param address The address of the breakpoint
   * @param node The node in which the breakpoint is located.
   */
public static void updateSingleNodeDebuggerHighlighting(final ZyGraph graph, final UnrelocatedAddress address, final NaviNode node) {
    Preconditions.checkNotNull(graph, "IE01192: Graph argument can not be null");
    Preconditions.checkNotNull(address, "IE01216: Address argument can not be null");
    final INaviViewNode rawNode = node.getRawNode();
    if (rawNode instanceof ICodeNode) {
        final INaviCodeNode codeNode = (INaviCodeNode) rawNode;
        updateDebuggerHighlighting(graph, address, node, codeNode);
    } else if (rawNode instanceof INaviFunctionNode) {
        final INaviFunctionNode functionNode = (INaviFunctionNode) rawNode;
        updateDebuggerHighlighting(address, node, functionNode);
    }
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) ICodeNode(com.google.security.zynamics.zylib.gui.zygraph.nodes.ICodeNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode)

Aggregations

INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)70 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)25 Test (org.junit.Test)23 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)21 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)18 INaviFunctionNode (com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode)17 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)14 ArrayList (java.util.ArrayList)13 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)12 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)12 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)11 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)9 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)9 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)9 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)9 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)8 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)8 CodeNodeCommentNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.CodeNodeCommentNotificationContainer)6 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)5 CommentNotification (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification)5