Search in sources :

Example 66 with INaviViewNode

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

the class CRegisterTrackingHelper method getInstructionMap.

/**
   * Creates an address -> instruction mapping for all instructions in a graph.
   *
   * @param view The input graph.
   * @return The created mapping.
   */
public static Map<IAddress, INaviInstruction> getInstructionMap(final INaviView view) {
    final Map<IAddress, INaviInstruction> instructionMap = new HashMap<IAddress, INaviInstruction>();
    final List<INaviViewNode> nodes = view.getGraph().getNodes();
    for (final INaviViewNode node : nodes) {
        if (node instanceof INaviCodeNode) {
            final INaviCodeNode cnode = (INaviCodeNode) node;
            for (final INaviInstruction instruction : cnode.getInstructions()) {
                instructionMap.put(instruction.getAddress(), instruction);
            }
        }
    }
    return instructionMap;
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) HashMap(java.util.HashMap) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 67 with INaviViewNode

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

the class CViewPruner method getSources.

/**
   * Collects edge information about outgoing 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> getSources(final INaviEdge edge, final Map<INaviViewNode, INaviViewNode> nodeMap, final Set<INaviEdge> visited) {
    final INaviViewNode source = edge.getSource();
    visited.add(edge);
    final Set<EdgeResult> sources = new HashSet<EdgeResult>();
    if (nodeMap.containsKey(source)) {
        sources.add(new EdgeResult(nodeMap.get(source), edge.getType()));
    } else {
        for (final INaviEdge incomingEdge : source.getIncomingEdges()) {
            if (!visited.contains(incomingEdge)) {
                sources.addAll(getSources(incomingEdge, nodeMap, visited));
            }
        }
    }
    return sources;
}
Also used : INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) HashSet(java.util.HashSet)

Example 68 with INaviViewNode

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

the class CNodeClickHandler method nodeClicked.

/**
   * Handles clicks on nodes.
   *
   * @param node The clicked node.
   * @param event The click event.
   * @param x The x-coordinate of the click.
   * @param y The y-coordinate of the click.
   * @param extensions List of objects that extend code node context menus.
   */
public void nodeClicked(final NaviNode node, final MouseEvent event, final double x, final double y, final List<ICodeNodeExtension> extensions) {
    if (event.getButton() == MouseEvent.BUTTON3) {
        handleRightClick(node, event, x, y, extensions);
    } else if ((event.getButton() == MouseEvent.BUTTON1) && (event.getClickCount() == 2) && event.isControlDown()) {
        final INaviViewNode rawNode = node.getRawNode();
        if (rawNode instanceof INaviFunctionNode) {
            final INaviFunction function = ((INaviFunctionNode) rawNode).getFunction();
            CGraphOpener.showFunction(m_model.getParent(), m_model.getViewContainer(), function);
        } else if (rawNode instanceof INaviCodeNode) {
            final INaviCodeNode cnode = (INaviCodeNode) rawNode;
            final int row = node.positionToRow(y - node.getY());
            final INaviInstruction instruction = CCodeNodeHelpers.lineToInstruction(cnode, row);
            if (instruction == null) {
                return;
            }
            final Set<IAddress> references = new HashSet<IAddress>();
            for (final INaviOperandTree operand : instruction.getOperands()) {
                collectReferences(operand.getRootNode(), references);
            }
            final List<INaviFunction> functions = m_model.getViewContainer().getFunctions();
            for (final INaviFunction function : functions) {
                for (final IAddress address : references) {
                    if (function.getAddress().equals(address)) {
                        CGraphOpener.showFunction(m_model.getParent(), m_model.getViewContainer(), function);
                    }
                }
            }
        }
    } else if (!m_model.getGraph().getEditMode().getLabelEventHandler().isActive() && (event.getButton() == MouseEvent.BUTTON1) && (event.getClickCount() == 2)) {
        if ((node.getRawNode() instanceof INaviGroupNode) && event.isShiftDown()) {
            final INaviGroupNode gnode = (INaviGroupNode) node.getRawNode();
            gnode.setCollapsed(!gnode.isCollapsed());
        } else {
            CGraphZoomer.zoomNode(m_model.getGraph(), node);
        }
    }
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) INaviOperandTree(com.google.security.zynamics.binnavi.disassembly.INaviOperandTree) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) HashSet(java.util.HashSet)

Example 69 with INaviViewNode

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

the class CViewContent method deleteNodes.

@Override
public void deleteNodes(final Collection<INaviViewNode> nodes) {
    Preconditions.checkNotNull(nodes, "IE00305: Nodes argument can not be null");
    // Make defensive copy in order to evade the concurrent modification exception
    final Collection<INaviViewNode> nodesCopy = new ArrayList<INaviViewNode>(nodes);
    final List<INaviViewNode> gnodes = graph.getNodes();
    for (final INaviViewNode naviViewNode : nodesCopy) {
        Preconditions.checkNotNull(naviViewNode, "IE00307: Node list contains a null-node");
        Preconditions.checkArgument(gnodes.contains(naviViewNode), "IE00308: Node list contains at least one node that is not part of this view");
    }
    final List<INaviGroupNode> parentsToDelete = new ArrayList<INaviGroupNode>();
    for (final INaviViewNode node : nodesCopy) {
        if (node instanceof INaviGroupNode) {
            if (((INaviGroupNode) node).getNumberOfElements() != 0) {
                deleteGroupNode((INaviGroupNode) node);
            }
            continue;
        }
        removeEdges(node);
        graph.removeNode(node);
        node.removeListener(m_internalNodeListener);
        final INaviGroupNode parent = node.getParentGroup();
        if (parent != null) {
            parent.removeElement(node);
            if (parent.getParentGroup() != null) {
                parent.getParentGroup().addElement(node);
            }
            if (parent.getNumberOfElements() == 0) {
                parentsToDelete.add(parent);
            }
        }
    }
    // We remove group nodes from the list of nodes that are put into the listener notification
    // because deletedNode notifications were already sent for group nodes when they lost their last
    // member.
    final Collection<INaviViewNode> filteredNodes = filterGroupNodes(nodesCopy);
    for (final INaviViewListener listener : listeners) {
        try {
            listener.deletedNodes(view, filteredNodes);
        } catch (final Exception exception) {
            CUtilityFunctions.logException(exception);
        }
    }
    updateGraphType();
}
Also used : ArrayList(java.util.ArrayList) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) InternalTranslationException(com.google.security.zynamics.reil.translators.InternalTranslationException)

Example 70 with INaviViewNode

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

the class CUnInliner method removeTextNodes.

/**
   * Removes text nodes from the deleted nodes.
   *
   * @param view The view from which the nodes are deleted.
   * @param nodes The nodes whose attached text nodes are removed from.
   */
private static void removeTextNodes(final INaviView view, final ImmutableList<INaviViewNode> nodes) {
    final Set<INaviViewNode> toDelete = new HashSet<INaviViewNode>();
    for (final INaviViewNode node : nodes) {
        for (final INaviViewNode parent : node.getParents()) {
            if (parent instanceof INaviTextNode) {
                toDelete.add(parent);
            }
        }
    }
    view.getContent().deleteNodes(toDelete);
}
Also used : INaviTextNode(com.google.security.zynamics.binnavi.disassembly.INaviTextNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) HashSet(java.util.HashSet)

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