Search in sources :

Example 26 with INaviGroupNode

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

the class CNodeClickHandler method nodeClicked.

/**
   * Handles clicks on nodes.
   *
   * @param node The clicked node.
   * @param event The click event.
   * @param x The x-coordinate of the click.
   * @param y The y-coordinate of the click.
   * @param extensions List of objects that extend code node context menus.
   */
public void nodeClicked(final NaviNode node, final MouseEvent event, final double x, final double y, final List<ICodeNodeExtension> extensions) {
    if (event.getButton() == MouseEvent.BUTTON3) {
        handleRightClick(node, event, x, y, extensions);
    } else if ((event.getButton() == MouseEvent.BUTTON1) && (event.getClickCount() == 2) && event.isControlDown()) {
        final INaviViewNode rawNode = node.getRawNode();
        if (rawNode instanceof INaviFunctionNode) {
            final INaviFunction function = ((INaviFunctionNode) rawNode).getFunction();
            CGraphOpener.showFunction(m_model.getParent(), m_model.getViewContainer(), function);
        } else if (rawNode instanceof INaviCodeNode) {
            final INaviCodeNode cnode = (INaviCodeNode) rawNode;
            final int row = node.positionToRow(y - node.getY());
            final INaviInstruction instruction = CCodeNodeHelpers.lineToInstruction(cnode, row);
            if (instruction == null) {
                return;
            }
            final Set<IAddress> references = new HashSet<IAddress>();
            for (final INaviOperandTree operand : instruction.getOperands()) {
                collectReferences(operand.getRootNode(), references);
            }
            final List<INaviFunction> functions = m_model.getViewContainer().getFunctions();
            for (final INaviFunction function : functions) {
                for (final IAddress address : references) {
                    if (function.getAddress().equals(address)) {
                        CGraphOpener.showFunction(m_model.getParent(), m_model.getViewContainer(), function);
                    }
                }
            }
        }
    } else if (!m_model.getGraph().getEditMode().getLabelEventHandler().isActive() && (event.getButton() == MouseEvent.BUTTON1) && (event.getClickCount() == 2)) {
        if ((node.getRawNode() instanceof INaviGroupNode) && event.isShiftDown()) {
            final INaviGroupNode gnode = (INaviGroupNode) node.getRawNode();
            gnode.setCollapsed(!gnode.isCollapsed());
        } else {
            CGraphZoomer.zoomNode(m_model.getGraph(), node);
        }
    }
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) INaviOperandTree(com.google.security.zynamics.binnavi.disassembly.INaviOperandTree) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) HashSet(java.util.HashSet)

Example 27 with INaviGroupNode

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

the class CViewContent method deleteNodes.

@Override
public void deleteNodes(final Collection<INaviViewNode> nodes) {
    Preconditions.checkNotNull(nodes, "IE00305: Nodes argument can not be null");
    // Make defensive copy in order to evade the concurrent modification exception
    final Collection<INaviViewNode> nodesCopy = new ArrayList<INaviViewNode>(nodes);
    final List<INaviViewNode> gnodes = graph.getNodes();
    for (final INaviViewNode naviViewNode : nodesCopy) {
        Preconditions.checkNotNull(naviViewNode, "IE00307: Node list contains a null-node");
        Preconditions.checkArgument(gnodes.contains(naviViewNode), "IE00308: Node list contains at least one node that is not part of this view");
    }
    final List<INaviGroupNode> parentsToDelete = new ArrayList<INaviGroupNode>();
    for (final INaviViewNode node : nodesCopy) {
        if (node instanceof INaviGroupNode) {
            if (((INaviGroupNode) node).getNumberOfElements() != 0) {
                deleteGroupNode((INaviGroupNode) node);
            }
            continue;
        }
        removeEdges(node);
        graph.removeNode(node);
        node.removeListener(m_internalNodeListener);
        final INaviGroupNode parent = node.getParentGroup();
        if (parent != null) {
            parent.removeElement(node);
            if (parent.getParentGroup() != null) {
                parent.getParentGroup().addElement(node);
            }
            if (parent.getNumberOfElements() == 0) {
                parentsToDelete.add(parent);
            }
        }
    }
    // We remove group nodes from the list of nodes that are put into the listener notification
    // because deletedNode notifications were already sent for group nodes when they lost their last
    // member.
    final Collection<INaviViewNode> filteredNodes = filterGroupNodes(nodesCopy);
    for (final INaviViewListener listener : listeners) {
        try {
            listener.deletedNodes(view, filteredNodes);
        } catch (final Exception exception) {
            CUtilityFunctions.logException(exception);
        }
    }
    updateGraphType();
}
Also used : ArrayList(java.util.ArrayList) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) InternalTranslationException(com.google.security.zynamics.reil.translators.InternalTranslationException)

Example 28 with INaviGroupNode

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

the class CViewInserter method createGroupNodes.

/**
   * Clones the group nodes of the source view and inserts them into the target view.
   *
   * @param target The target view where the cloned group nodes are inserted.
   * @param sourceNodes The nodes of the source view.
   * @param nodeMap Maps between the source nodes and their cloned counterparts.
   */
private static void createGroupNodes(final INaviView target, final Collection<INaviViewNode> sourceNodes, final Map<INaviViewNode, INaviViewNode> nodeMap) {
    for (final INaviViewNode blockNode : sourceNodes) {
        if (blockNode instanceof INaviGroupNode) {
            final INaviGroupNode gnode = (INaviGroupNode) blockNode;
            final CGroupNode newGroupNode = target.getContent().createGroupNode(getNodes(gnode.getElements(), nodeMap));
            newGroupNode.initializeComment(gnode.getComments());
        }
    }
}
Also used : INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode)

Example 29 with INaviGroupNode

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

the class PostgreSQLNotificationProviderTest method testEditGroupNodeComment.

@Test
public void testEditGroupNodeComment() throws CouldntSaveDataException, CouldntLoadDataException, CPartialLoadException, LoadCancelledException, InterruptedException {
    final CView databaseOneGroupNodeView = databaseOneModuleTwo.getContent().getViewContainer().createView(" GROUP NODE TESTING VIEW ", "");
    CViewInserter.insertView(databaseOneView, databaseOneGroupNodeView);
    final INaviGroupNode databaseOneGroupNode = databaseOneGroupNodeView.getContent().createGroupNode(databaseOneGroupNodeView.getGraph().getNodes());
    databaseOneGroupNodeView.save();
    databaseTwoModuleTwo.close();
    databaseTwoModuleTwo.load();
    databaseTwoView.load();
    final INaviView databaseTwoGroupNodeView = Iterables.getLast(databaseTwoModuleTwo.getContent().getViewContainer().getUserViews());
    INaviGroupNode databaseTwoGroupNode = null;
    assertEquals(databaseOneGroupNodeView.getName(), databaseTwoGroupNodeView.getName());
    databaseTwoGroupNodeView.load();
    for (final INaviViewNode node : databaseTwoGroupNodeView.getContent().getGraph().getNodes()) {
        if (node instanceof INaviGroupNode) {
            databaseTwoGroupNode = (INaviGroupNode) node;
        }
    }
    assertNotNull(databaseTwoGroupNode);
    assertEquals(databaseTwoGroupNode.getId(), databaseOneGroupNode.getId());
    final List<IComment> comments = databaseOneGroupNode.appendComment(" TEST NOTIFICATION PROVIDER TESTS (GROUP NODE COMMENT) BEFORE ");
    synchronized (lock) {
        lock.await(1000, TimeUnit.MILLISECONDS);
    }
    final List<IComment> oneAfter = databaseOneGroupNode.getComments();
    final List<IComment> twoAfter = databaseTwoGroupNode.getComments();
    assertNotNull(oneAfter);
    assertNotNull(twoAfter);
    assertEquals(1, oneAfter.size());
    assertEquals(1, twoAfter.size());
    assertEquals(oneAfter, twoAfter);
    final int oneTwoSize = oneAfter.size();
    final int twoTwoSize = twoAfter.size();
    databaseOneGroupNode.editComment(Iterables.getLast(comments), " TEST NOTIFICATION PROVIDER TESTS (GROUP NODE COMMENT) AFTER ");
    // database one to two over the PostgreSQL back end.
    synchronized (lock) {
        lock.await(1000, TimeUnit.MILLISECONDS);
    }
    final List<IComment> oneThree = databaseOneGroupNode.getComments();
    final List<IComment> twoThree = databaseTwoGroupNode.getComments();
    assertEquals(oneTwoSize, oneThree.size());
    assertEquals(twoTwoSize, twoThree.size());
    assertEquals(oneThree, twoThree);
    assertEquals(" TEST NOTIFICATION PROVIDER TESTS (GROUP NODE COMMENT) AFTER ", Iterables.getLast(oneThree).getComment());
    assertEquals(" TEST NOTIFICATION PROVIDER TESTS (GROUP NODE COMMENT) AFTER ", Iterables.getLast(twoThree).getComment());
}
Also used : CView(com.google.security.zynamics.binnavi.disassembly.views.CView) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) Test(org.junit.Test)

Example 30 with INaviGroupNode

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

the class PostgreSQLNotificationProviderTest method testDeleteGroupNodeComment.

@Test
public void testDeleteGroupNodeComment() throws CouldntSaveDataException, CouldntLoadDataException, LoadCancelledException, CPartialLoadException, InterruptedException, CouldntDeleteException {
    final CView databaseOneGroupNodeView = databaseOneModuleTwo.getContent().getViewContainer().createView(" GROUP NODE TESTING VIEW ", "");
    CViewInserter.insertView(databaseOneView, databaseOneGroupNodeView);
    final INaviGroupNode databaseOneGroupNode = databaseOneGroupNodeView.getContent().createGroupNode(databaseOneGroupNodeView.getGraph().getNodes());
    databaseOneGroupNodeView.save();
    databaseTwoModuleTwo.close();
    databaseTwoModuleTwo.load();
    databaseTwoView.load();
    final INaviView databaseTwoGroupNodeView = Iterables.getLast(databaseTwoModuleTwo.getContent().getViewContainer().getUserViews());
    INaviGroupNode databaseTwoGroupNode = null;
    assertEquals(databaseOneGroupNodeView.getName(), databaseTwoGroupNodeView.getName());
    databaseTwoGroupNodeView.load();
    for (final INaviViewNode node : databaseTwoGroupNodeView.getContent().getGraph().getNodes()) {
        if (node instanceof INaviGroupNode) {
            databaseTwoGroupNode = (INaviGroupNode) node;
        }
    }
    assertNotNull(databaseTwoGroupNode);
    assertEquals(databaseTwoGroupNode.getId(), databaseOneGroupNode.getId());
    final List<IComment> comments = databaseOneGroupNode.appendComment(" TEST NOTIFICATION PROVIDER TESTS (GROUP NODE COMMENT) ");
    synchronized (lock) {
        lock.await(1000, TimeUnit.MILLISECONDS);
    }
    final List<IComment> oneAfter = databaseOneGroupNode.getComments();
    final List<IComment> twoAfter = databaseTwoGroupNode.getComments();
    assertNotNull(oneAfter);
    assertNotNull(twoAfter);
    assertEquals(1, oneAfter.size());
    assertEquals(1, twoAfter.size());
    assertEquals(oneAfter, twoAfter);
    final int oneTwoSize = oneAfter.size();
    final int twoTwoSize = twoAfter.size();
    databaseOneGroupNode.deleteComment(Iterables.getLast(comments));
    // database one to two over the PostgreSQL back end.
    synchronized (lock) {
        lock.await(1000, TimeUnit.MILLISECONDS);
    }
    final List<IComment> oneThree = databaseOneGroupNode.getComments();
    final List<IComment> twoThree = databaseTwoGroupNode.getComments();
    assertEquals(oneTwoSize - 1, oneThree.size());
    assertEquals(twoTwoSize - 1, twoThree.size());
    assertEquals(oneThree, twoThree);
}
Also used : CView(com.google.security.zynamics.binnavi.disassembly.views.CView) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) Test(org.junit.Test)

Aggregations

INaviGroupNode (com.google.security.zynamics.binnavi.disassembly.INaviGroupNode)40 Test (org.junit.Test)23 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)16 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)15 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)11 CComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment)9 IUser (com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser)9 UniqueTestUserGenerator (com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator)8 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)7 ArrayList (java.util.ArrayList)7 CGroupNode (com.google.security.zynamics.binnavi.disassembly.CGroupNode)6 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)5 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)4 INaviFunctionNode (com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode)4 NaviNode (com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode)4 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)3 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)3 GroupNodeCommentNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.GroupNodeCommentNotificationContainer)3 MockTagManager (com.google.security.zynamics.binnavi.Tagging.MockTagManager)3 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)3