Search in sources :

Example 16 with INaviFunctionNode

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

the class PostgreSQLNotificationProviderTest method testEditFunctionNodeCommentSync.

@Test
public void testEditFunctionNodeCommentSync() throws CouldntLoadDataException, CPartialLoadException, LoadCancelledException, CouldntSaveDataException, InterruptedException {
    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) BEFORE ");
    // 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.editLocalFunctionComment(Iterables.getLast(comments), " TEST NOTIFICATION PROVIDER TESTS (LOCAL FUNCTION NODE COMMENT) AFTER ");
    // 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, oneThree.size());
    assertEquals(twoTwoSize, twoThree.size());
    assertEquals(oneThree, twoThree);
    assertEquals(" TEST NOTIFICATION PROVIDER TESTS (LOCAL FUNCTION NODE COMMENT) AFTER ", Iterables.getLast(oneThree).getComment());
    assertEquals(" TEST NOTIFICATION PROVIDER TESTS (LOCAL FUNCTION NODE COMMENT) AFTER ", Iterables.getLast(twoThree).getComment());
}
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)

Example 17 with INaviFunctionNode

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

the class PostgreSQLNotificationParserTest method testFunctionNodeCommentParsingDeleteComment.

@Test
public void testFunctionNodeCommentParsingDeleteComment() {
    new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
    MockPGNotification notification = new MockPGNotification("comment_changes", "bn_function_nodes UPDATE 1 6666 4608 null");
    final CommentNotification result = PostgreSQLCommentNotificationParser.processFunctionNodeCommentNotification(notification, provider);
    assertNotNull(result);
    final FunctionNodeCommentNotificationContainer container = (FunctionNodeCommentNotificationContainer) result;
    final INaviFunctionNode functionNode = container.getNode();
    assertEquals(new CAddress(4608), functionNode.getAddress());
    assertEquals(CommentOperation.DELETE, container.getOperation());
    assertNull(container.getCommentId());
}
Also used : CommentNotification(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) FunctionNodeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.FunctionNodeCommentNotificationContainer) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 18 with INaviFunctionNode

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

the class View method createNode.

// ! Clones an existing node.
/**
   * Creates a new view node by cloning an existing view node.
   *
   * @param node The node to clone.
   *
   * @return The cloned node.
   */
public ViewNode createNode(final ViewNode node) {
    Preconditions.checkNotNull(node, "Error: Node argument can not be null");
    if (node instanceof CodeNode) {
        final List<INaviInstruction> instructionsList = new ArrayList<INaviInstruction>();
        for (final Instruction instruction : ((CodeNode) node).getInstructions()) {
            Preconditions.checkNotNull(instruction, "Error: Instruction list contains a null-element");
            instructionsList.add(instruction.getNative());
        }
        CCodeNode newNode;
        try {
            newNode = naviView.getContent().createCodeNode(((INaviCodeNode) node.getNative()).getParentFunction(), instructionsList);
        } catch (final MaybeNullException e) {
            newNode = naviView.getContent().createCodeNode(null, instructionsList);
        }
        adjustAttributes(node, newNode);
        return cachedNodes.get(newNode);
    } else if (node instanceof FunctionNode) {
        final CFunctionNode newNode = naviView.getContent().createFunctionNode(((INaviFunctionNode) node.getNative()).getFunction());
        adjustAttributes(node, newNode);
        return cachedNodes.get(newNode);
    } else if (node instanceof TextNode) {
        final CTextNode newNode = naviView.getContent().createTextNode(((TextNode) node).getComments());
        adjustAttributes(node, newNode);
        return cachedNodes.get(newNode);
    } else if (node instanceof GroupNode) {
        throw new IllegalStateException("Group nodes can not be cloned");
    } else {
        throw new IllegalStateException("Error: Unknown node type");
    }
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) ArrayList(java.util.ArrayList) CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) INaviTextNode(com.google.security.zynamics.binnavi.disassembly.INaviTextNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 19 with INaviFunctionNode

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

the class CMenuBuilder method addSelectionMenus.

/**
   * Adds menus related to node selection to a given node context menu.
   *
   * @param menu The node context menu to extend.
   * @param graph The graph the clicked node belongs to.
   * @param node The clicked node.
   */
public static void addSelectionMenus(final JPopupMenu menu, final ZyGraph graph, final NaviNode node) {
    Preconditions.checkNotNull(menu, "IE02144: Menu argument can not be null");
    Preconditions.checkNotNull(graph, "IE02145: Graph argument can not be null");
    Preconditions.checkNotNull(node, "IE02146: Node argument can not be null");
    final JMenu selectionMenu = new JMenu("Selection");
    selectionMenu.add(CActionProxy.proxy(new CActionSelectNodePredecessors(graph, node)));
    selectionMenu.add(CActionProxy.proxy(new CActionSelectNodeSuccessors(graph, node)));
    if (graph.getSelectedNodes().size() > 0) {
        selectionMenu.add(CActionProxy.proxy(new CGroupAction(graph)));
    }
    if (node.getRawNode() instanceof INaviCodeNode) {
        try {
            final INaviFunction parentFunction = ((INaviCodeNode) node.getRawNode()).getParentFunction();
            selectionMenu.add(CActionProxy.proxy(new CActionSelectSameParentFunction(graph, parentFunction)));
        } catch (final MaybeNullException exception) {
        // Obviously we can not select nodes of the same parent function if there
        // is no parent function.
        }
    } else if (node.getRawNode() instanceof INaviFunctionNode) {
        final INaviFunction function = ((INaviFunctionNode) node.getRawNode()).getFunction();
        selectionMenu.add(CActionProxy.proxy(new CActionSelectSameFunctionType(graph, function.getType())));
    }
    menu.add(selectionMenu);
    menu.addSeparator();
}
Also used : CActionSelectNodeSuccessors(com.google.security.zynamics.binnavi.ZyGraph.Menus.Actions.CActionSelectNodeSuccessors) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) CActionSelectSameParentFunction(com.google.security.zynamics.binnavi.ZyGraph.Menus.Actions.CActionSelectSameParentFunction) CGroupAction(com.google.security.zynamics.binnavi.Gui.GraphWindows.Actions.CGroupAction) CActionSelectSameFunctionType(com.google.security.zynamics.binnavi.ZyGraph.Menus.Actions.CActionSelectSameFunctionType) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) JMenu(javax.swing.JMenu) CActionSelectNodePredecessors(com.google.security.zynamics.binnavi.ZyGraph.Menus.Actions.CActionSelectNodePredecessors)

Example 20 with INaviFunctionNode

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

the class CDebuggerPainter method updateSingleNodeDebuggerHighlighting.

/**
   * Updates the debugger highlighting for a single node
   *
   * @param graph The graph in which the node is located
   * @param address The address of the breakpoint
   * @param node The node in which the breakpoint is located.
   */
public static void updateSingleNodeDebuggerHighlighting(final ZyGraph graph, final UnrelocatedAddress address, final NaviNode node) {
    Preconditions.checkNotNull(graph, "IE01192: Graph argument can not be null");
    Preconditions.checkNotNull(address, "IE01216: Address argument can not be null");
    final INaviViewNode rawNode = node.getRawNode();
    if (rawNode instanceof ICodeNode) {
        final INaviCodeNode codeNode = (INaviCodeNode) rawNode;
        updateDebuggerHighlighting(graph, address, node, codeNode);
    } else if (rawNode instanceof INaviFunctionNode) {
        final INaviFunctionNode functionNode = (INaviFunctionNode) rawNode;
        updateDebuggerHighlighting(address, node, functionNode);
    }
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) ICodeNode(com.google.security.zynamics.zylib.gui.zygraph.nodes.ICodeNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode)

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