Search in sources :

Example 1 with EdgeCursor

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

the class YHelpers method openFolder.

/**
 * Opens a folder node.
 *
 * @param graph The graph the folder node belongs to.
 * @param folderNode The folder node to be opened.
 */
public static void openFolder(final Graph2D graph, final Node folderNode) {
    Preconditions.checkNotNull(graph, "Error: Graph argument can not be null");
    Preconditions.checkNotNull(folderNode, "Error: Folder node argument can not be null");
    final HierarchyManager hierarchy = graph.getHierarchyManager();
    final double w = graph.getWidth(folderNode);
    final double h = graph.getHeight(folderNode);
    final NodeList folderNodes = new NodeList();
    folderNodes.add(folderNode);
    graph.firePreEvent();
    for (final NodeCursor nc = folderNodes.nodes(); nc.ok(); nc.next()) {
        // get original location of folder node
        final Graph2D innerGraph = (Graph2D) hierarchy.getInnerGraph(nc.node());
        final YPoint folderP = graph.getLocation(nc.node());
        final NodeList innerNodes = new NodeList(innerGraph.nodes());
        hierarchy.openFolder(nc.node());
        // get new location of group node
        final Rectangle2D.Double gBox = graph.getRealizer(nc.node()).getBoundingBox();
        // move grouped nodes to former location of folder node
        LayoutTool.moveSubgraph(graph, innerNodes.nodes(), folderP.x - gBox.x, folderP.y - gBox.y);
    }
    graph.firePostEvent();
    graph.unselectAll();
    for (final NodeCursor nc = folderNodes.nodes(); nc.ok(); nc.next()) {
        graph.setSelected(nc.node(), true);
    }
    // to the node
    if ((w != graph.getWidth(folderNode)) || (h != graph.getHeight(folderNode))) {
        for (final EdgeCursor ec = folderNode.outEdges(); ec.ok(); ec.next()) {
            graph.setSourcePointRel(ec.edge(), YPoint.ORIGIN);
        }
        for (final EdgeCursor ec = folderNode.inEdges(); ec.ok(); ec.next()) {
            graph.setTargetPointRel(ec.edge(), YPoint.ORIGIN);
        }
    }
    graph.updateViews();
}
Also used : HierarchyManager(y.view.hierarchy.HierarchyManager) EdgeCursor(y.base.EdgeCursor) NodeList(y.base.NodeList) Rectangle2D(java.awt.geom.Rectangle2D) NodeCursor(y.base.NodeCursor) YPoint(y.geom.YPoint) Graph2D(y.view.Graph2D)

Example 2 with EdgeCursor

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

the class TypeDependenceGraph method willCreateCycle.

/**
 * Tests if adding a member of type memberType to containingType would create a cyclic type
 * declaration.
 *
 * @param containingType The base type that contains memberType.
 * @param memberType The base type of a member contained in containingType.
 * @return Returns whether adding memberType to containingType would create a cyclic type
 *         declaration.
 */
public boolean willCreateCycle(final BaseType containingType, final BaseType memberType) {
    Preconditions.checkNotNull(containingType, "Error: Containing type can not be null.");
    Preconditions.checkNotNull(memberType, "Error: Member type can not be null.");
    if (containingType == memberType) {
        return true;
    }
    // 0) The pre-condition is that the existing graph is cycle free.
    // 1) Contained types is the set of types that are explicitly and implicitly contained within
    // the structure this member belongs to.
    // 2) The intersection of this set and all types that are contained by parentType must be empty.
    // TODO(jannewger): instead of creating a copy, the implementation for determining dependent
    // types should be parameterizable whether to include the contained type or not.
    final Set<BaseType> containedTypes = Sets.newHashSet(determineDependentTypes(containingType));
    containedTypes.remove(containingType);
    final Node startNode = containedRelationMap.get(memberType);
    final Queue<Edge> edgesToVisit = new LinkedList<Edge>();
    for (final EdgeCursor ec = startNode.inEdges(); ec.ok(); ec.next()) {
        edgesToVisit.add((Edge) ec.current());
    }
    final Set<Node> visitednodes = new HashSet<Node>();
    while (!edgesToVisit.isEmpty()) {
        final Edge currentEdge = edgesToVisit.poll();
        final Node nextNode = currentEdge.source();
        final BaseType baseType = containedRelationMap.inverse().get(nextNode);
        if (containedTypes.contains(baseType)) {
            return true;
        }
        if (!visitednodes.contains(nextNode)) {
            for (final EdgeCursor ec = nextNode.inEdges(); ec.ok(); ec.next()) {
                edgesToVisit.add((Edge) ec.current());
            }
        }
        visitednodes.add(nextNode);
    }
    return false;
}
Also used : EdgeCursor(y.base.EdgeCursor) BaseType(com.google.security.zynamics.binnavi.disassembly.types.BaseType) Node(y.base.Node) Edge(y.base.Edge) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 3 with EdgeCursor

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

the class CReilInstructionGraph method getIncomingEdgesForAddress.

/**
 * Convenience method to obtain the edge in the ReilInstructionGraph that corresponds to ENTERING
 * a particular native instruction
 *
 * @param nativeInstructionAddress The address of the native instruction
 *
 * @return The edge corresponding to entering the native instruction
 */
public Iterable<IInstructionGraphEdge> getIncomingEdgesForAddress(final IAddress nativeInstructionAddress) {
    final ArrayList<IInstructionGraphEdge> result = new ArrayList<IInstructionGraphEdge>();
    final EdgeCursor edgeCursor = m_internalGraph.edges();
    while (edgeCursor.ok()) {
        final Edge currentEdge = (Edge) edgeCursor.current();
        final long targetAddress = m_nodesMap.get(currentEdge.target()).getReilInstruction().getAddress().toLong();
        if ((targetAddress >> 8) == nativeInstructionAddress.toLong()) {
            result.add(m_edgesMap.get(currentEdge));
        }
        edgeCursor.next();
    }
    return result;
}
Also used : IInstructionGraphEdge(com.google.security.zynamics.reil.algorithms.mono2.common.instructiongraph.interfaces.IInstructionGraphEdge) EdgeCursor(y.base.EdgeCursor) ArrayList(java.util.ArrayList) IInstructionGraphEdge(com.google.security.zynamics.reil.algorithms.mono2.common.instructiongraph.interfaces.IInstructionGraphEdge) Edge(y.base.Edge) ReilEdge(com.google.security.zynamics.reil.ReilEdge) ReilInstructionGraphEdge(com.google.security.zynamics.reil.algorithms.mono2.common.instructiongraph.ReilInstructionGraphEdge)

Example 4 with EdgeCursor

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

the class CReilInstructionGraph method getOutgoingEdgesForAddress.

/**
 * Convenience method to obtain the edge in the ReilInstructionGraph that corresponds to LEAVING a
 * particular native instruction
 *
 * @param nativeInstructionAddress The address of the native instruction
 *
 * @return The edge corresponding to entering the native instruction
 */
public Iterable<IInstructionGraphEdge> getOutgoingEdgesForAddress(final IAddress nativeInstructionAddress) {
    final ArrayList<IInstructionGraphEdge> result = new ArrayList<IInstructionGraphEdge>();
    final EdgeCursor edgeCursor = m_internalGraph.edges();
    while (edgeCursor.ok()) {
        final Edge edge = (Edge) edgeCursor.current();
        final long sourceAddress = m_nodesMap.get(edge.source()).getReilInstruction().getAddress().toLong();
        final long targetAddress = m_nodesMap.get(edge.target()).getReilInstruction().getAddress().toLong();
        if (((targetAddress & 0xFF) == 0) && ((sourceAddress >> 8) == nativeInstructionAddress.toLong())) {
            result.add(m_edgesMap.get(edge));
        }
        edgeCursor.next();
    }
    return result;
}
Also used : IInstructionGraphEdge(com.google.security.zynamics.reil.algorithms.mono2.common.instructiongraph.interfaces.IInstructionGraphEdge) EdgeCursor(y.base.EdgeCursor) ArrayList(java.util.ArrayList) IInstructionGraphEdge(com.google.security.zynamics.reil.algorithms.mono2.common.instructiongraph.interfaces.IInstructionGraphEdge) Edge(y.base.Edge) ReilEdge(com.google.security.zynamics.reil.ReilEdge) ReilInstructionGraphEdge(com.google.security.zynamics.reil.algorithms.mono2.common.instructiongraph.ReilInstructionGraphEdge)

Example 5 with EdgeCursor

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

the class YHelpers method closeGroup.

/**
 * Closes a group node.
 *
 * @param graph The graph the group node belongs to.
 * @param groupNode The group node to be closed.
 */
public static void closeGroup(final Graph2D graph, final Node groupNode) {
    Preconditions.checkNotNull(graph, "Error: Graph argument can not be null");
    Preconditions.checkNotNull(groupNode, "Error: Group node argument can not be null");
    final HierarchyManager hierarchy = graph.getHierarchyManager();
    final double w = graph.getWidth(groupNode);
    final double h = graph.getHeight(groupNode);
    final NodeList groupNodes = new NodeList();
    groupNodes.add(groupNode);
    graph.firePreEvent();
    for (final NodeCursor nc = groupNodes.nodes(); nc.ok(); nc.next()) {
        hierarchy.closeGroup(nc.node());
    }
    graph.firePostEvent();
    // to the node
    if ((w != graph.getWidth(groupNode)) || (h != graph.getHeight(groupNode))) {
        for (final EdgeCursor ec = groupNode.outEdges(); ec.ok(); ec.next()) {
            graph.setSourcePointRel(ec.edge(), YPoint.ORIGIN);
        }
        for (final EdgeCursor ec = groupNode.inEdges(); ec.ok(); ec.next()) {
            graph.setTargetPointRel(ec.edge(), YPoint.ORIGIN);
        }
    }
    graph.updateViews();
}
Also used : HierarchyManager(y.view.hierarchy.HierarchyManager) EdgeCursor(y.base.EdgeCursor) NodeList(y.base.NodeList) NodeCursor(y.base.NodeCursor)

Aggregations

EdgeCursor (y.base.EdgeCursor)8 Edge (y.base.Edge)6 NodeCursor (y.base.NodeCursor)3 NodeList (y.base.NodeList)3 ReilEdge (com.google.security.zynamics.reil.ReilEdge)2 ReilInstructionGraphEdge (com.google.security.zynamics.reil.algorithms.mono2.common.instructiongraph.ReilInstructionGraphEdge)2 IInstructionGraphEdge (com.google.security.zynamics.reil.algorithms.mono2.common.instructiongraph.interfaces.IInstructionGraphEdge)2 ArrayList (java.util.ArrayList)2 Node (y.base.Node)2 Graph2D (y.view.Graph2D)2 HierarchyManager (y.view.hierarchy.HierarchyManager)2 BaseType (com.google.security.zynamics.binnavi.disassembly.types.BaseType)1 ZyGraphNode (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.nodes.ZyGraphNode)1 ZyProximityNode (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.proximity.ZyProximityNode)1 Rectangle2D (java.awt.geom.Rectangle2D)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 YPoint (y.geom.YPoint)1 Bend (y.view.Bend)1 BendCursor (y.view.BendCursor)1