Search in sources :

Example 1 with CEdgeUpdater

use of com.google.security.zynamics.binnavi.ZyGraph.Updaters.CEdgeUpdater in project binnavi by google.

the class ZyEdgeBuilder method convertEdge.

/**
   * Creates a graph node from a raw edge.
   *
   * @param edge The raw edge that provides the underlying data.
   * @param sourceNode Source node of the edge.
   * @param targetNode Target node of the edge.
   * @param graph2D The graph object where the edge is created.
   * @param adjustColors Flag that indicates whether the initial color of all edges should be
   *        recalculated according to their type.
   *
   * @return The created YNode/NaviNode pair.
   */
public static Pair<Edge, NaviEdge> convertEdge(final INaviEdge edge, final NaviNode sourceNode, final NaviNode targetNode, final Graph2D graph2D, final boolean adjustColors) {
    // Build the edge label if necessary
    final ZyLabelContent content = ZyEdgeBuilder.buildContent(edge);
    // Create the edge realizer of the new edge
    final ZyEdgeRealizer<NaviEdge> realizer = new ZyEdgeRealizer<NaviEdge>(content, new CEdgeUpdater(edge));
    // Create the edge
    final Edge g2dEdge = graph2D.createEdge(sourceNode.getNode(), targetNode.getNode(), realizer);
    if (adjustColors) {
        EdgeInitializer.adjustColor(edge);
    }
    EdgeInitializer.initializeEdgeType(edge, realizer);
    graph2D.getRealizer(g2dEdge).setLineColor(edge.getColor());
    // Associate user data with the edge
    final NaviEdge zyEdge = new NaviEdge(sourceNode, targetNode, g2dEdge, realizer, edge);
    NaviNode.link(sourceNode, targetNode);
    final ZyEdgeData<NaviEdge> data = new ZyEdgeData<NaviEdge>(zyEdge);
    realizer.setUserData(data);
    return new Pair<Edge, NaviEdge>(g2dEdge, zyEdge);
}
Also used : ZyEdgeRealizer(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyEdgeRealizer) ZyLabelContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent) CEdgeUpdater(com.google.security.zynamics.binnavi.ZyGraph.Updaters.CEdgeUpdater) ZyEdgeData(com.google.security.zynamics.zylib.gui.zygraph.edges.ZyEdgeData) 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) Pair(com.google.security.zynamics.zylib.general.Pair)

Example 2 with CEdgeUpdater

use of com.google.security.zynamics.binnavi.ZyGraph.Updaters.CEdgeUpdater in project binnavi by google.

the class ZyGraph method saveAs.

/**
   * Creates a copy of the current native view and transfers the copied native view into the graph
   * object. That means that the graph object changes its underlying raw view when this function is
   * called.
   *
   * @param container The view container where the view is copied to.
   * @param name The new name of the raw view.
   * @param description The new description of the raw view.
   *
   * @return The new raw view.
   *
   * @throws CouldntSaveDataException Thrown if the view could not be saved.
   */
public INaviView saveAs(final IViewContainer container, final String name, final String description) throws CouldntSaveDataException {
    Preconditions.checkNotNull(container, "IE00871: Container argument can not be null");
    Preconditions.checkNotNull(name, "IE00872: Name argument can not be null");
    Preconditions.checkNotNull(description, "IE00899: Description argument can not be null");
    final INaviView oldView = m_rawView;
    final INaviView newView = container.createView(name, description);
    CViewInserter.insertView(oldView, newView);
    final List<INaviViewNode> oldNodes = oldView.getGraph().getNodes();
    final List<INaviViewNode> newNodes = newView.getGraph().getNodes();
    for (int i = 0; i < oldNodes.size(); i++) {
        final INaviViewNode newNode = newNodes.get(i);
        final NaviNode oldNode = getMappings().getNode(oldNodes.get(i));
        getMappings().setNode(newNode, oldNode);
        oldNode.setRawNode(newNode);
        for (final INaviGraphListener listener : m_listeners) {
            try {
                listener.changedModel(this, oldNode);
            } catch (final Exception exception) {
                CUtilityFunctions.logException(exception);
            }
        }
    }
    final List<INaviEdge> oldEdges = oldView.getGraph().getEdges();
    final List<INaviEdge> newEdges = newView.getGraph().getEdges();
    for (int i = 0; i < oldEdges.size(); i++) {
        final INaviEdge newEdge = newEdges.get(i);
        final NaviEdge oldEdge = getMappings().getEdge(oldEdges.get(i));
        assert oldEdge != null;
        getMappings().setEdge(newEdge, oldEdge);
        final ZyEdgeRealizer<NaviEdge> realizer = oldEdge.getRealizer();
        realizer.setUpdater(new CEdgeUpdater(newEdge));
        oldEdge.setRawEdge(newEdge);
    }
    removeListeners();
    newView.save();
    CSettingsFunctions.saveSettings(newView, getView(), m_settings);
    m_rawView = newView;
    initializeListeners();
    m_synchronizer.reset();
    for (final INaviGraphListener listener : m_listeners) {
        // ESCA-JAVA0166: Catch Exception here because we are calling a listener function.
        try {
            listener.changedView(oldView, newView);
        } catch (final Exception exception) {
            CUtilityFunctions.logException(exception);
        }
    }
    oldView.close();
    return m_rawView;
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) CEdgeUpdater(com.google.security.zynamics.binnavi.ZyGraph.Updaters.CEdgeUpdater) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviGraphListener(com.google.security.zynamics.binnavi.ZyGraph.INaviGraphListener) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge)

Aggregations

CEdgeUpdater (com.google.security.zynamics.binnavi.ZyGraph.Updaters.CEdgeUpdater)2 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)2 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)1 INaviGraphListener (com.google.security.zynamics.binnavi.ZyGraph.INaviGraphListener)1 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)1 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)1 NaviEdge (com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge)1 Pair (com.google.security.zynamics.zylib.general.Pair)1 ZyEdgeData (com.google.security.zynamics.zylib.gui.zygraph.edges.ZyEdgeData)1 ZyLabelContent (com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent)1 ZyEdgeRealizer (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyEdgeRealizer)1 Edge (y.base.Edge)1