Search in sources :

Example 11 with INaviFunctionNode

use of com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode 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 12 with INaviFunctionNode

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

the class CGlobalEdgeCommentSynchronizer method getModules.

/**
   * Returns the modules the nodes of the edge belong to.
   *
   * @param edge The edge to check.
   *
   * @return Source module and target module of the edge.
   *
   * @throws MaybeNullException Thrown if the edge does not have source module or target module.
   */
private static Pair<INaviModule, INaviModule> getModules(final INaviEdge edge) throws MaybeNullException {
    INaviModule srcModule = null;
    INaviModule tarModule = null;
    if (edge.getSource() instanceof INaviCodeNode) {
        srcModule = ((INaviCodeNode) edge.getSource()).getParentFunction().getModule();
    } else if (edge.getSource() instanceof INaviFunctionNode) {
        srcModule = ((INaviFunctionNode) edge.getSource()).getFunction().getModule();
    }
    if (edge.getTarget() instanceof INaviCodeNode) {
        tarModule = ((INaviCodeNode) edge.getTarget()).getParentFunction().getModule();
    } else if (edge.getTarget() instanceof INaviFunctionNode) {
        tarModule = ((INaviFunctionNode) edge.getTarget()).getFunction().getModule();
    }
    return new Pair<INaviModule, INaviModule>(srcModule, tarModule);
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) Pair(com.google.security.zynamics.zylib.general.Pair)

Example 13 with INaviFunctionNode

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

the class CSteppingHelper method getAddress.

/**
   * Determines the start address of a node.
   *
   * @param node Node whose address is determined.
   *
   * @return The start address of the given node or null if the node does not have an address.
   */
private static BreakpointAddress getAddress(final INaviViewNode node) {
    if (node instanceof INaviCodeNode) {
        final INaviCodeNode ccnode = (INaviCodeNode) node;
        final INaviInstruction instruction = Iterables.getFirst(ccnode.getInstructions(), null);
        return new BreakpointAddress(instruction.getModule(), new UnrelocatedAddress(instruction.getAddress()));
    } else if (node instanceof INaviFunctionNode) {
        final INaviFunction function = ((INaviFunctionNode) node).getFunction();
        final INaviModule module = function.getModule();
        return new BreakpointAddress(module, new UnrelocatedAddress(function.getAddress()));
    } else {
        // Node types we can not step to
        return null;
    }
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 14 with INaviFunctionNode

use of com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode 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 15 with INaviFunctionNode

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

the class PostgreSQLNotificationProviderTest method testDeleteFunctionNodeCommentSync.

@Test
public void testDeleteFunctionNodeCommentSync() throws CouldntLoadDataException, CPartialLoadException, LoadCancelledException, CouldntSaveDataException, InterruptedException, CouldntDeleteException {
    databaseOneCallGraph = databaseOneModuleTwo.getContent().getViewContainer().getNativeCallgraphView();
    databaseOneCallGraph.load();
    final INaviFunctionNode databaseOneFunctionNode = (INaviFunctionNode) databaseOneCallGraph.getGraph().getNodes().get(1);
    databaseTwoCallGraph = databaseTwoModuleTwo.getContent().getViewContainer().getNativeCallgraphView();
    databaseTwoCallGraph.load();
    final INaviFunctionNode databaseTwoFunctionNode = (INaviFunctionNode) databaseTwoCallGraph.getGraph().getNodes().get(1);
    final List<IComment> oneBefore = databaseOneFunctionNode.getLocalFunctionComment() == null ? new ArrayList<IComment>() : databaseOneFunctionNode.getLocalFunctionComment();
    final List<IComment> twoBefore = databaseTwoFunctionNode.getLocalFunctionComment() == null ? new ArrayList<IComment>() : databaseTwoFunctionNode.getLocalFunctionComment();
    assertEquals(oneBefore, twoBefore);
    final List<IComment> comments = databaseOneFunctionNode.appendLocalFunctionComment(" TEST NOTIFICATION PROVIDER TESTS (LOCAL FUNCTION NODE COMMENT) ");
    // database one to two over the PostgreSQL back end.
    synchronized (lock) {
        lock.await(1000, TimeUnit.MILLISECONDS);
    }
    final List<IComment> oneAfter = databaseOneFunctionNode.getLocalFunctionComment();
    final List<IComment> twoAfter = databaseTwoFunctionNode.getLocalFunctionComment();
    assertNotNull(oneAfter);
    assertNotNull(twoAfter);
    assertEquals(oneBefore.size() + 1, oneAfter.size());
    assertEquals(twoBefore.size() + 1, twoAfter.size());
    assertEquals(oneAfter, twoAfter);
    final int oneTwoSize = oneAfter.size();
    final int twoTwoSize = twoAfter.size();
    databaseOneFunctionNode.deleteLocalFunctionComment(Iterables.getLast(comments));
    // database one to two over the PostgreSQL back end.
    synchronized (lock) {
        lock.await(1000, TimeUnit.MILLISECONDS);
    }
    final List<IComment> oneThree = databaseOneFunctionNode.getLocalFunctionComment();
    final List<IComment> twoThree = databaseTwoFunctionNode.getLocalFunctionComment();
    assertEquals(oneTwoSize - 1, oneThree.size());
    assertEquals(twoTwoSize - 1, twoThree.size());
    assertEquals(oneThree, twoThree);
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) Test(org.junit.Test)

Aggregations

INaviFunctionNode (com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode)24 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)17 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)9 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)7 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)6 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)6 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)5 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)4 CFunctionNode (com.google.security.zynamics.binnavi.disassembly.CFunctionNode)4 INaviGroupNode (com.google.security.zynamics.binnavi.disassembly.INaviGroupNode)4 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 BreakpointAddress (com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress)3 INaviTextNode (com.google.security.zynamics.binnavi.disassembly.INaviTextNode)3 UnrelocatedAddress (com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress)3 FunctionNodeCommentNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.FunctionNodeCommentNotificationContainer)2 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)2 IAddressNode (com.google.security.zynamics.binnavi.disassembly.IAddressNode)2 NaviNode (com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode)2