Search in sources :

Example 1 with INaviGroupNode

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

the class CViewContent method removeEdges.

/**
 * Returns all incoming and outgoing edges of a node from the view.
 *
 * @param node The view whose edges are removed.
 */
private void removeEdges(final INaviViewNode node) {
    if (node instanceof INaviGroupNode) {
        // Group nodes can not have real edges attached to them
        return;
    }
    final Set<INaviEdge> toDelete = new HashSet<INaviEdge>();
    for (final INaviEdge incomingEdge : node.getIncomingEdges()) {
        incomingEdge.getSource().removeChild(node);
        incomingEdge.getSource().removeOutgoingEdge(incomingEdge);
        toDelete.add(incomingEdge);
    }
    for (final INaviEdge outgoingEdge : node.getOutgoingEdges()) {
        outgoingEdge.getTarget().removeParent(node);
        outgoingEdge.getTarget().removeIncomingEdge(outgoingEdge);
        toDelete.add(outgoingEdge);
    }
    for (final INaviEdge edge : toDelete) {
        deleteEdge(edge);
    }
}
Also used : INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) HashSet(java.util.HashSet)

Example 2 with INaviGroupNode

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

the class CViewInserter method createNodes.

/**
 * Clones a node of the source view and inserts it into the target view.
 *
 * @param target The target view where the cloned view is inserted.
 * @param sourceNode The source node that is cloned and inserted into the target view.
 * @param nodeMap Maps nodes of the source view to their cloned counterparts.
 */
private static void createNodes(final INaviView target, final INaviViewNode sourceNode, final Map<INaviViewNode, INaviViewNode> nodeMap) {
    final INaviViewNode newNode = CNodeTypeSwitcher.switchNode(sourceNode, new INodeTypeCallback<INaviViewNode>() {

        @Override
        public INaviViewNode handle(final INaviCodeNode node) {
            return insertCodeNode(target, node);
        }

        @Override
        public INaviViewNode handle(final INaviFunctionNode node) {
            return insertFunctionNode(target, node);
        }

        @Override
        public INaviViewNode handle(final INaviGroupNode node) {
            // Skip now, create later
            return null;
        }

        @Override
        public INaviViewNode handle(final INaviTextNode node) {
            return insertTextNode(target, node);
        }
    });
    if (newNode != null) {
        newNode.setBorderColor(sourceNode.getBorderColor());
        newNode.setColor(sourceNode.getColor());
        newNode.setHeight(sourceNode.getHeight());
        newNode.setSelected(sourceNode.isSelected());
        newNode.setVisible(sourceNode.isVisible());
        newNode.setWidth(sourceNode.getWidth());
        newNode.setX(sourceNode.getX());
        newNode.setY(sourceNode.getY());
        nodeMap.put(sourceNode, newNode);
    }
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) INaviTextNode(com.google.security.zynamics.binnavi.disassembly.INaviTextNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode)

Example 3 with INaviGroupNode

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

the class CGraphGrouper method determineNodeText.

/**
 * Determines the text to be displayed in a group node, if the given node is inside a collapsed
 * group node.
 *
 * @param node The node whose text is determined.
 *
 * @return The string to be displayed for the given node.
 */
private static String determineNodeText(final NaviNode node) {
    if (node.getRawNode() instanceof INaviCodeNode) {
        final INaviCodeNode cnode = (INaviCodeNode) node.getRawNode();
        return String.format("Basic Block: %s", cnode.getAddress().toHexString());
    } else if (node.getRawNode() instanceof INaviFunctionNode) {
        final INaviFunctionNode fnode = (INaviFunctionNode) node.getRawNode();
        return String.format("Function: %s (%s)", fnode.getFunction().getName(), fnode.getFunction().getAddress().toHexString());
    } else if (node.getRawNode() instanceof INaviTextNode) {
        // Display up to 15 characters of the first line of
        // the comment for comment nodes.
        final INaviTextNode tnode = (INaviTextNode) node.getRawNode();
        final List<IComment> comment = tnode.getComments();
        final String firstLine = (comment.isEmpty()) ? "" : comment.get(1).getComment();
        final int firstLineBreak = Math.min(firstLine.indexOf('\n'), firstLine.indexOf('\r'));
        final int toDisplay = Math.min(Math.min(15, firstLineBreak == -1 ? Integer.MAX_VALUE : firstLineBreak), firstLine.length());
        return String.format("Text: %s", firstLine.substring(0, toDisplay));
    } else if (node.getRawNode() instanceof INaviGroupNode) {
        // Display up to 15 characters of the first line of
        // the comment for group nodes.
        final INaviGroupNode gnode = (INaviGroupNode) node.getRawNode();
        final List<IComment> comment = gnode.getComments();
        final String firstLine = (comment.isEmpty()) ? "" : comment.get(0).getComment();
        final int firstLineBreak = Math.min(firstLine.indexOf('\n'), firstLine.indexOf('\r'));
        final int toDisplay = Math.min(Math.min(15, firstLineBreak == -1 ? Integer.MAX_VALUE : firstLineBreak), firstLine.length());
        return String.format("Group: %s", firstLine.substring(0, toDisplay));
    } else {
        throw new IllegalStateException("IE01150: Unknown node type");
    }
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) INaviTextNode(com.google.security.zynamics.binnavi.disassembly.INaviTextNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) ArrayList(java.util.ArrayList) List(java.util.List) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode)

Example 4 with INaviGroupNode

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

the class CGraphGrouper method getCommonParent.

/**
 * Finds the common parent group of a list of nodes.
 *
 * @param nodes The list of nodes whose parent group is determined.
 *
 * @return The common parent group of the nodes or null if there is no such group.
 */
private static INaviGroupNode getCommonParent(final List<NaviNode> nodes) {
    INaviGroupNode parent = null;
    boolean first = true;
    for (final NaviNode node : nodes) {
        if (first) {
            parent = node.getRawNode().getParentGroup();
            first = false;
        } else {
            if (parent != node.getRawNode().getParentGroup()) {
                return null;
            }
        }
    }
    return parent;
}
Also used : NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode)

Example 5 with INaviGroupNode

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

the class GroupNodeTest method testSetCollapsed.

@Test
public void testSetCollapsed() {
    final Database database = new Database(new MockDatabase());
    final MockModule mockModule = new MockModule();
    final TagManager nodeTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.NODE_TAG));
    final TagManager viewTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.VIEW_TAG));
    final Module module = new Module(database, mockModule, nodeTagManager, viewTagManager);
    final MockView mockView = new MockView();
    final View view = new View(module, mockView, nodeTagManager, viewTagManager);
    final INaviGroupNode internalGroupNode = new CGroupNode(0, 0, 0, 0, 0, Color.RED, false, false, new HashSet<CTag>(), new ArrayList<IComment>(), false, new MockSqlProvider());
    final GroupNode node = new GroupNode(view, internalGroupNode, viewTagManager);
    final MockGroupNodeListener listener = new MockGroupNodeListener();
    node.addListener(listener);
    node.setCollapsed(true);
    assertEquals("changedState;", listener.events);
    assertTrue(node.isCollapsed());
    node.removeListener(listener);
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) 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