Search in sources :

Example 11 with Node

use of y.base.Node in project binnavi by google.

the class View2DTest method setUp.

@Before
public void setUp() throws CouldntLoadDataException, LoadCancelledException, FileReadException {
    ConfigManager.instance().read();
    final MockDatabase database = new MockDatabase();
    final CModule module = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, new MockSqlProvider());
    database.getContent().addModule(module);
    manager.addDatabase(database);
    module.load();
    m_view = module.getContent().getViewContainer().createView("name", "description");
    final ZyGraphViewSettings settings = new ZyGraphViewSettings(new CallGraphSettingsConfigItem());
    settings.getLayoutSettings().setDefaultGraphLayout(LayoutStyle.CIRCULAR);
    final ZyGraph2DView g2dView = new ZyGraph2DView();
    final LinkedHashMap<Node, NaviNode> nodeMap = new LinkedHashMap<Node, NaviNode>();
    final LinkedHashMap<Edge, NaviEdge> edgeMap = new LinkedHashMap<Edge, NaviEdge>();
    final Node node1 = g2dView.getGraph2D().createNode();
    final CTextNode rawNode1 = m_view.getContent().createTextNode(Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, " TEXT NODE ")));
    nodeMap.put(node1, new NaviNode(node1, new ZyNormalNodeRealizer<NaviNode>(new ZyLabelContent(null)), rawNode1));
    final Node node2 = g2dView.getGraph2D().createNode();
    final CTextNode rawNode2 = m_view.getContent().createTextNode(Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, " TEXT COMMENT ")));
    nodeMap.put(node2, new NaviNode(node2, new ZyNormalNodeRealizer<NaviNode>(new ZyLabelContent(null)), rawNode2));
    final Edge edge = g2dView.getGraph2D().createEdge(node1, node2);
    final INaviEdge rawEdge = m_view.getContent().createEdge(rawNode1, rawNode2, com.google.security.zynamics.zylib.gui.zygraph.edges.EdgeType.JUMP_CONDITIONAL_FALSE);
    edgeMap.put(edge, new NaviEdge(nodeMap.get(node1), nodeMap.get(node2), edge, new ZyEdgeRealizer<NaviEdge>(new ZyLabelContent(null), null), rawEdge));
    final ZyGraph graph = new ZyGraph(m_view, nodeMap, edgeMap, settings, g2dView);
    m_view2d = new View2D(database, new CModuleContainer(database, module), graph, pluginInterface);
}
Also used : ZyGraphViewSettings(com.google.security.zynamics.binnavi.ZyGraph.ZyGraphViewSettings) CallGraphSettingsConfigItem(com.google.security.zynamics.binnavi.config.CallGraphSettingsConfigItem) ZyGraph(com.google.security.zynamics.binnavi.yfileswrap.zygraph.ZyGraph) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) Node(y.base.Node) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) CModuleContainer(com.google.security.zynamics.binnavi.disassembly.Modules.CModuleContainer) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) LinkedHashMap(java.util.LinkedHashMap) View2D(com.google.security.zynamics.binnavi.yfileswrap.API.disassembly.View2D) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) ZyEdgeRealizer(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyEdgeRealizer) ZyLabelContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) ZyNormalNodeRealizer(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyNormalNodeRealizer) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) ZyGraph2DView(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.ZyGraph2DView) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) NaviEdge(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge) Edge(y.base.Edge) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) NaviEdge(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) Before(org.junit.Before)

Example 12 with Node

use of y.base.Node in project binnavi by google.

the class CDefaultNodeClickedLeftAction method execute.

@Override
public void execute(final CNodeClickedLeftState<NodeType, EdgeType> state, final MouseEvent event) {
    CMouseCursorHelper.setDefaultCursor(state.getGraph());
    final AbstractZyGraph<NodeType, EdgeType> graph = state.getGraph();
    final Node n = state.getNode();
    final NodeType node = graph.getNode(n);
    final double x = graph.getEditMode().translateX(event.getX());
    final double y = graph.getEditMode().translateY(event.getY());
    final CStateFactory<NodeType, EdgeType> factory = state.getStateFactory();
    if (ProximityHelper.isProximityNode(state.getGraph().getGraph(), n)) {
        CEditNodeHelper.removeCaret(graph);
        final ZyProximityNode<?> proximityNode = ProximityHelper.getProximityNode(graph.getGraph(), n);
        for (final IZyEditModeListener<NodeType, EdgeType> listener : factory.getListeners()) {
            try {
                listener.proximityBrowserNodeClicked(proximityNode, event, x, y);
            } catch (final Exception exception) {
            // TODO: (timkornau): implement logging here.
            }
        }
    } else if ((node != null) && (node.getRawNode() instanceof IGroupNode)) {
        CEditNodeHelper.removeCaret(graph);
        final GroupNodeRealizer gnr = (GroupNodeRealizer) graph.getGraph().getRealizer(node.getNode());
        final NodeLabel handle = gnr.getStateLabel();
        if (handle.getBox().contains(x, y)) {
            // Clicks on the X in the group node corner
            toggleGroup(node);
        } else if (SwingUtilities.isLeftMouseButton(event)) {
            if ((event.getClickCount() == 2) && event.isControlDown()) {
                // CTRL-LEFT-DOUBLECLICK
                toggleGroup(node);
            } else if (event.getClickCount() == 1) {
                CGraphSelector.selectNode(graph, node, event.isShiftDown());
            }
        }
    } else {
        if (node != null) {
            if (graph.getEditMode().getLabelEventHandler().isActiveLabel(node.getRealizer().getNodeContent())) {
                CEditNodeHelper.setCaretEnd(graph, state.getNode(), event);
            } else {
                if (graph.getEditMode().getLabelEventHandler().isActive()) {
                    CEditNodeHelper.removeCaret(graph);
                }
                final Set<NodeType> selectedNodes = graph.getSelectedNodes();
                if (event.isShiftDown() && (selectedNodes.size() >= 1)) {
                    CGraphSelector.selectPath(graph, new ArrayList<NodeType>(selectedNodes), node);
                } else if (event.isControlDown()) {
                    graph.selectNode(node, !node.isSelected());
                } else {
                    final Collection<NodeType> toUnselect = new ArrayList<NodeType>(graph.getNodes());
                    toUnselect.remove(node);
                    final Collection<NodeType> toSelect = new ArrayList<NodeType>();
                    toSelect.add(node);
                    graph.selectNodes(toSelect, toUnselect);
                }
            }
            for (final IZyEditModeListener<NodeType, EdgeType> listener : factory.getListeners()) {
                // ESCA-JAVA0166: Catch Exception because we are calling a listener function
                try {
                    listener.nodeClicked(node, event, x, y);
                } catch (final Exception exception) {
                // TODO: (timkornau): implement logging here.
                }
            }
        }
    }
}
Also used : GroupNodeRealizer(y.view.hierarchy.GroupNodeRealizer) Set(java.util.Set) IGroupNode(com.google.security.zynamics.zylib.gui.zygraph.nodes.IGroupNode) ZyGraphNode(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.nodes.ZyGraphNode) Node(y.base.Node) IGroupNode(com.google.security.zynamics.zylib.gui.zygraph.nodes.IGroupNode) ZyProximityNode(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.proximity.ZyProximityNode) ArrayList(java.util.ArrayList) IZyEditModeListener(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.IZyEditModeListener) NodeLabel(y.view.NodeLabel)

Example 13 with Node

use of y.base.Node in project binnavi by google.

the class CDefaultNodeClickedRightAction method execute.

@Override
public void execute(final CNodeClickedRightState<NodeType, EdgeType> state, final MouseEvent event) {
    CMouseCursorHelper.setDefaultCursor(state.getGraph());
    final AbstractZyGraph<NodeType, EdgeType> graph = state.getGraph();
    final Node yNode = state.getNode();
    final NodeType node = graph.getNode(yNode);
    final double x = graph.getEditMode().translateX(event.getX());
    final double y = graph.getEditMode().translateY(event.getY());
    if (graph.getEditMode().getLabelEventHandler().isActive() && graph.getEditMode().getLabelEventHandler().hasEmptySelection()) {
        CEditNodeHelper.removeCaret(graph);
    }
    if (node == null) {
        // Proximity node was clicked
        final ZyProximityNode<?> proximityNode = ProximityHelper.getProximityNode(graph.getGraph(), yNode);
        for (final IZyEditModeListener<NodeType, EdgeType> listener : state.getStateFactory().getListeners()) {
            try {
                listener.proximityBrowserNodeClicked(proximityNode, event, x, y);
            } catch (final Exception exception) {
            // TODO: (timkornau): implement logging here.
            }
        }
    } else {
        for (final IZyEditModeListener<NodeType, EdgeType> listener : state.getStateFactory().getListeners()) {
            try {
                listener.nodeClicked(node, event, x, y);
            } catch (final Exception exception) {
            // TODO: (timkornau): implement logging here.
            }
        }
    }
}
Also used : ZyGraphNode(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.nodes.ZyGraphNode) Node(y.base.Node) ZyProximityNode(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.proximity.ZyProximityNode)

Example 14 with Node

use of y.base.Node in project binnavi by google.

the class CGraphSelector method selectPath.

/**
   * Function which handles the selection of nodes in a path finding scenario. The function performs
   * four BFS runs: BFS 1 searches for all successors of the start nodes. BFS 2 searches for all
   * predecessors of the end nodes. BFS 2 searches for all predecessors of the start nodes. BFS 4
   * searches for all successors of the end nodes.
   * 
   * These four BFS runs are used in two sets: Set 1 is intersect of nodes reached through (BFS 1,
   * BFS 2). Set 2 is intersect of nodes reached through (BFS 3, BFS 4).
   * 
   * Therefore Set 1 represents all nodes on paths if the set of start nodes contains parents of the
   * newly selected node and Set 2 represents all nodes on paths if the set of start nodes contains
   * child nodes of the newly selected node.
   * 
   * 
   * @param graph The graph in which the selection takes place.
   * @param alreadySelectedNodes The List of nodes already selected.
   * @param newlySelectedNode The node which is newly selected.
   */
@SuppressWarnings("unchecked")
public static <NodeType extends ZyGraphNode<?>> void selectPath(final AbstractZyGraph<NodeType, ?> graph, final ArrayList<NodeType> alreadySelectedNodes, final NodeType newlySelectedNode) {
    final Function<NodeType, Node> function = new Function<NodeType, Node>() {

        @Override
        public Node apply(final NodeType input) {
            return input.getNode();
        }
    };
    final Collection<Node> foo = Collections2.transform(alreadySelectedNodes, function);
    final NodeList startNodes = new NodeList(foo.iterator());
    final NodeList endNodes = new NodeList(newlySelectedNode.getNode());
    final Set<Node> startSuccSet = new HashSet<Node>();
    final NodeList[] nodeListsStartSucc = Bfs.getLayers(graph.getGraph(), startNodes, Bfs.DIRECTION_SUCCESSOR, graph.getGraph().createNodeMap(), 0);
    for (final NodeList nodeList : nodeListsStartSucc) {
        startSuccSet.addAll(nodeList);
    }
    final Set<Node> endPredSet = new HashSet<Node>();
    final NodeList[] nodeListsEndPred = Bfs.getLayers(graph.getGraph(), endNodes, Bfs.DIRECTION_PREDECESSOR, graph.getGraph().createNodeMap(), 0);
    for (final NodeList nodeList : nodeListsEndPred) {
        endPredSet.addAll(nodeList);
    }
    final SetView<Node> startBeforeEndSetView = Sets.intersection(startSuccSet, endPredSet);
    if (!startBeforeEndSetView.isEmpty()) {
        for (final Node node : startBeforeEndSetView) {
            graph.getGraph().setSelected(node, true);
        }
    }
    final Set<Node> startPredSet = new HashSet<Node>();
    final NodeList[] nodeListsStartPred = Bfs.getLayers(graph.getGraph(), startNodes, Bfs.DIRECTION_PREDECESSOR, graph.getGraph().createNodeMap(), 0);
    for (final NodeList nodeList : nodeListsStartPred) {
        startPredSet.addAll(nodeList);
    }
    final Set<Node> endSuccSet = new HashSet<Node>();
    final NodeList[] nodeListsEndSucc = Bfs.getLayers(graph.getGraph(), endNodes, Bfs.DIRECTION_SUCCESSOR, graph.getGraph().createNodeMap(), 0);
    for (final NodeList nodeList : nodeListsEndSucc) {
        endSuccSet.addAll(nodeList);
    }
    final SetView<Node> endBeforeStartSetView = Sets.intersection(startPredSet, endSuccSet);
    if (!endBeforeStartSetView.isEmpty()) {
        for (final Node node : endBeforeStartSetView) {
            graph.getGraph().setSelected(node, true);
        }
    }
}
Also used : Function(com.google.common.base.Function) ZyGraphNode(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.nodes.ZyGraphNode) Node(y.base.Node) NodeList(y.base.NodeList) HashSet(java.util.HashSet)

Example 15 with Node

use of y.base.Node in project binnavi by google.

the class CNodeEditState method mousePressed.

@Override
public IMouseStateChange mousePressed(final MouseEvent event, final AbstractZyGraph<?, ?> graph) {
    final double x = graph.getEditMode().translateX(event.getX());
    final double y = graph.getEditMode().translateY(event.getY());
    final HitInfo hitInfo = graph.getGraph().getHitInfo(x, y);
    if (hitInfo.hasHitNodes()) {
        final Node n = hitInfo.getHitNode();
        if (SwingUtilities.isLeftMouseButton(event) && !event.isAltDown()) {
            if (n == m_node) {
                if (!m_isDragging) {
                    // Change caret
                    CEditNodeHelper.setCaretStart(graph, n, event);
                } else {
                    m_isDragging = false;
                }
                return new CStateChange(this, false);
            } else {
                m_factory.createNodeEditExitState(m_node, event);
                return new CStateChange(m_factory.createNodePressedLeftState(n, event), true);
            }
        } else if (SwingUtilities.isRightMouseButton(event)) {
            if (n == m_node) {
                return new CStateChange(this, false);
            } else {
                m_factory.createNodeEditExitState(m_node, event);
                return new CStateChange(m_factory.createNodePressedRightState(n, event), true);
            }
        } else if (SwingUtilities.isMiddleMouseButton(event) || (event.isAltDown() && SwingUtilities.isLeftMouseButton(event))) {
            if (n == m_node) {
                if (!m_isDragging) {
                    // Change caret
                    CEditNodeHelper.setCaretStart(graph, n, event);
                } else {
                    m_isDragging = false;
                }
                return new CStateChange(this, false);
            } else {
                m_factory.createNodeEditExitState(m_node, event);
                return new CStateChange(m_factory.createNodePressedMiddleState(n, event), true);
            }
        } else {
            return new CStateChange(this, false);
        }
    } else if (hitInfo.hasHitNodeLabels()) {
        throw new IllegalStateException();
    } else if (hitInfo.hasHitEdges()) {
        m_factory.createNodeEditExitState(m_node, event);
        return new CStateChange(m_factory.createEdgePressedLeftState(hitInfo.getHitEdge(), event), true);
    } else if (hitInfo.hasHitEdgeLabels()) {
        m_factory.createNodeEditExitState(m_node, event);
        return new CStateChange(m_factory.createEdgePressedLeftState(hitInfo.getHitEdgeLabel().getEdge(), event), true);
    } else if (hitInfo.hasHitBends()) {
        m_factory.createNodeEditExitState(m_node, event);
        return new CStateChange(m_factory.createBendPressedLeftState(hitInfo.getHitBend(), event), true);
    } else if (hitInfo.hasHitPorts()) {
        m_factory.createNodeEditExitState(m_node, event);
        return new CStateChange(m_factory.createDefaultState(), true);
    } else {
        // User left-pressed the background.
        m_factory.createNodeEditExitState(m_node, event);
        return new CStateChange(m_factory.createBackgroundPressedLeftState(event), true);
    }
}
Also used : HitInfo(y.view.HitInfo) ZyGraphNode(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.nodes.ZyGraphNode) Node(y.base.Node) CStateChange(com.google.security.zynamics.zylib.gui.zygraph.editmode.CStateChange)

Aggregations

Node (y.base.Node)28 ZyGraphNode (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.nodes.ZyGraphNode)9 NaviNode (com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode)8 Edge (y.base.Edge)7 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)5 IViewNode (com.google.security.zynamics.zylib.gui.zygraph.nodes.IViewNode)4 ZyLabelContent (com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent)4 NaviEdge (com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge)3 ZyGraph (com.google.security.zynamics.binnavi.yfileswrap.zygraph.ZyGraph)3 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)3 CStateChange (com.google.security.zynamics.zylib.gui.zygraph.editmode.CStateChange)3 ZyGraph2DView (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.ZyGraph2DView)3 ZyProximityNode (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.proximity.ZyProximityNode)3 HashSet (java.util.HashSet)3 LinkedHashMap (java.util.LinkedHashMap)3 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)2 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)2 ZyGraphViewSettings (com.google.security.zynamics.binnavi.ZyGraph.ZyGraphViewSettings)2 CallGraphSettingsConfigItem (com.google.security.zynamics.binnavi.config.CallGraphSettingsConfigItem)2 CTextNode (com.google.security.zynamics.binnavi.disassembly.CTextNode)2