Search in sources :

Example 31 with INaviViewNode

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

the class CViewPruner method convertEdges.

/**
   * Converts edges of the original view to the pruned view.
   *
   * @param view The original view.
   * @param prunedView The pruned view.
   * @param nodeMap A mapping between nodes of the original view and nodes of the pruned view.
   */
private static void convertEdges(final INaviView view, final INaviView prunedView, final Map<INaviViewNode, INaviViewNode> nodeMap) {
    final Set<Pair<INaviViewNode, INaviViewNode>> createdEdges = new HashSet<Pair<INaviViewNode, INaviViewNode>>();
    for (final INaviEdge edge : view.getGraph().getEdges()) {
        final Set<EdgeResult> sources = getSources(edge, nodeMap, new HashSet<INaviEdge>());
        final Set<EdgeResult> targets = getTargets(edge, nodeMap, new HashSet<INaviEdge>());
        for (final EdgeResult source : sources) {
            for (final EdgeResult target : targets) {
                final Pair<INaviViewNode, INaviViewNode> edgePair = new Pair<INaviViewNode, INaviViewNode>(source.m_node, target.m_node);
                if (createdEdges.contains(edgePair)) {
                    continue;
                }
                prunedView.getContent().createEdge(source.m_node, target.m_node, source.m_type);
                createdEdges.add(edgePair);
            }
        }
    }
}
Also used : INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) HashSet(java.util.HashSet) Pair(com.google.security.zynamics.zylib.general.Pair)

Example 32 with INaviViewNode

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

the class CViewPruner method getTargets.

/**
   * Collects edge information about incoming edges.
   *
   * @param edge The edge whose information is collected.
   * @param nodeMap Maps between nodes of the old view and nodes of the new view.
   * @param visited Already visited edges.
   *
   * @return The collected edge information.
   */
private static Set<EdgeResult> getTargets(final INaviEdge edge, final Map<INaviViewNode, INaviViewNode> nodeMap, final Set<INaviEdge> visited) {
    final INaviViewNode target = edge.getTarget();
    visited.add(edge);
    final Set<EdgeResult> targets = new HashSet<EdgeResult>();
    if (nodeMap.containsKey(target)) {
        targets.add(new EdgeResult(nodeMap.get(target), edge.getType()));
    } else {
        for (final INaviEdge outgoingEdge : target.getOutgoingEdges()) {
            if (!visited.contains(outgoingEdge)) {
                targets.addAll(getTargets(outgoingEdge, nodeMap, visited));
            }
        }
    }
    return targets;
}
Also used : INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) HashSet(java.util.HashSet)

Example 33 with INaviViewNode

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

the class CViewPruner method convertNodes.

/**
   * Converts the nodes from the original view to the pruned view.
   *
   * @param view The original view.
   * @param prunedView The pruned view.
   * @param keptInstructions Instructions to add to the new view.
   *
   * @return A mapping between nodes of the original view and nodes of the pruned view.
   */
private static Map<INaviViewNode, INaviViewNode> convertNodes(final INaviView view, final INaviView prunedView, final List<INaviInstruction> keptInstructions) {
    final Map<INaviViewNode, INaviViewNode> nodeMap = new HashMap<INaviViewNode, INaviViewNode>();
    for (final INaviViewNode node : view.getGraph().getNodes()) {
        if (node instanceof INaviCodeNode) {
            final INaviCodeNode cnode = (INaviCodeNode) node;
            final ArrayList<INaviInstruction> newInstructions = Lists.newArrayList(cnode.getInstructions());
            newInstructions.retainAll(keptInstructions);
            if (!newInstructions.isEmpty()) {
                CCodeNode newNode;
                try {
                    newNode = prunedView.getContent().createCodeNode(cnode.getParentFunction(), newInstructions);
                } catch (final MaybeNullException e) {
                    newNode = prunedView.getContent().createCodeNode(null, newInstructions);
                }
                newNode.setBorderColor(node.getBorderColor());
                newNode.setColor(node.getColor());
                nodeMap.put(node, newNode);
            }
        } else if (node instanceof INaviFunctionNode) {
            final INaviFunction function = ((INaviFunctionNode) node).getFunction();
            final CFunctionNode newNode = prunedView.getContent().createFunctionNode(function);
            nodeMap.put(node, newNode);
        }
    }
    return nodeMap;
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) HashMap(java.util.HashMap) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 34 with INaviViewNode

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

the class CViewPruner method prune.

/**
   * Creates a new view from the results of an operand tracking operation.
   *
   * @param container Container where the new view is created.
   * @param view Input view that provides the data.
   * @param keptInstructions Instructions to add to the new view.
   *
   * @return The new view.
   */
public static INaviView prune(final IViewContainer container, final INaviView view, final List<INaviInstruction> keptInstructions) {
    final INaviView prunedView = container.createView("Pruned View", "");
    final Map<INaviViewNode, INaviViewNode> nodeMap = convertNodes(view, prunedView, keptInstructions);
    convertEdges(view, prunedView, nodeMap);
    return prunedView;
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode)

Example 35 with INaviViewNode

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

the class CCrossReferencesPanel method visit.

@Override
public void visit(final CGraphModel model, final IGraphPanelExtender extender) {
    m_parent = model.getParent();
    m_viewContainer = model.getViewContainer();
    for (final INaviViewNode node : model.getGraph().getRawView().getGraph().getNodes()) {
        processNewNode(node);
    }
    m_tableModel.setCrossReferences(m_crossReferences);
    extender.addTab("Calling Functions", this);
    model.getGraph().getRawView().addListener(m_internalListener);
}
Also used : INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode)

Aggregations

INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)73 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)22 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)21 Test (org.junit.Test)16 INaviGroupNode (com.google.security.zynamics.binnavi.disassembly.INaviGroupNode)14 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)13 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)12 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)12 INaviFunctionNode (com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode)11 ArrayList (java.util.ArrayList)10 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)9 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)9 CNaviViewEdge (com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge)9 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)9 CGroupNode (com.google.security.zynamics.binnavi.disassembly.CGroupNode)8 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)8 NaviNode (com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode)8 INaviTextNode (com.google.security.zynamics.binnavi.disassembly.INaviTextNode)7 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)7 CView (com.google.security.zynamics.binnavi.disassembly.views.CView)7