Search in sources :

Example 6 with INaviFunctionNode

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

the class CGraphGrouper method determineNodeText.

/**
   * Determines the text to be displayed in a group node, if the given node is inside a collapsed
   * group node.
   * 
   * @param node The node whose text is determined.
   * 
   * @return The string to be displayed for the given node.
   */
private static String determineNodeText(final NaviNode node) {
    if (node.getRawNode() instanceof INaviCodeNode) {
        final INaviCodeNode cnode = (INaviCodeNode) node.getRawNode();
        return String.format("Basic Block: %s", cnode.getAddress().toHexString());
    } else if (node.getRawNode() instanceof INaviFunctionNode) {
        final INaviFunctionNode fnode = (INaviFunctionNode) node.getRawNode();
        return String.format("Function: %s (%s)", fnode.getFunction().getName(), fnode.getFunction().getAddress().toHexString());
    } else if (node.getRawNode() instanceof INaviTextNode) {
        // Display up to 15 characters of the first line of
        // the comment for comment nodes.
        final INaviTextNode tnode = (INaviTextNode) node.getRawNode();
        final List<IComment> comment = tnode.getComments();
        final String firstLine = (comment.isEmpty()) ? "" : comment.get(1).getComment();
        final int firstLineBreak = Math.min(firstLine.indexOf('\n'), firstLine.indexOf('\r'));
        final int toDisplay = Math.min(Math.min(15, firstLineBreak == -1 ? Integer.MAX_VALUE : firstLineBreak), firstLine.length());
        return String.format("Text: %s", firstLine.substring(0, toDisplay));
    } else if (node.getRawNode() instanceof INaviGroupNode) {
        // Display up to 15 characters of the first line of
        // the comment for group nodes.
        final INaviGroupNode gnode = (INaviGroupNode) node.getRawNode();
        final List<IComment> comment = gnode.getComments();
        final String firstLine = (comment.isEmpty()) ? "" : comment.get(0).getComment();
        final int firstLineBreak = Math.min(firstLine.indexOf('\n'), firstLine.indexOf('\r'));
        final int toDisplay = Math.min(Math.min(15, firstLineBreak == -1 ? Integer.MAX_VALUE : firstLineBreak), firstLine.length());
        return String.format("Group: %s", firstLine.substring(0, toDisplay));
    } else {
        throw new IllegalStateException("IE01150: Unknown node type");
    }
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) INaviTextNode(com.google.security.zynamics.binnavi.disassembly.INaviTextNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) ArrayList(java.util.ArrayList) List(java.util.List) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode)

Example 7 with INaviFunctionNode

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

the class PostgreSQLNodeSaver method saveFunctionNodes.

/**
   * Saves the function nodes to the database.
   *
   * @param provider The connection to the database.
   * @param nodes The nodes to save.
   * @param firstNode The database index of the first node.
   * @param functionNodeIndices Index into the nodes list that identifies the function nodes.
   *
   * @throws SQLException Thrown if saving the function nodes failed.
   */
protected static void saveFunctionNodes(final SQLProvider provider, final List<INaviViewNode> nodes, final int firstNode, final List<Integer> functionNodeIndices) throws SQLException {
    if (functionNodeIndices.isEmpty()) {
        return;
    }
    final String query = "INSERT INTO " + CTableNames.FUNCTION_NODES_TABLE + "(module_id, node_id, function, comment_id) VALUES (?, ?, ?, ?)";
    final ArrayList<INaviFunctionNode> functionNodesWithUnsavedComments = new ArrayList<INaviFunctionNode>();
    final PreparedStatement preparedStatement = provider.getConnection().getConnection().prepareStatement(query);
    try {
        for (final int index : functionNodeIndices) {
            final CFunctionNode node = (CFunctionNode) nodes.get(index);
            final INaviFunction function = node.getFunction();
            final List<IComment> comments = node.getLocalFunctionComment();
            final Integer commentId = comments == null ? null : comments.size() == 0 ? null : Iterables.getLast(comments).getId();
            if ((comments != null) && (comments.size() != 0) && (commentId == null)) {
                functionNodesWithUnsavedComments.add(node);
            }
            preparedStatement.setInt(1, function.getModule().getConfiguration().getId());
            preparedStatement.setInt(2, firstNode + index);
            preparedStatement.setObject(3, function.getAddress().toBigInteger(), Types.BIGINT);
            if (commentId == null) {
                preparedStatement.setNull(4, Types.INTEGER);
            } else {
                preparedStatement.setInt(4, commentId);
            }
            preparedStatement.addBatch();
        }
        preparedStatement.executeBatch();
    } finally {
        preparedStatement.close();
    }
    for (final INaviFunctionNode functionNode : functionNodesWithUnsavedComments) {
        final ArrayList<IComment> functionNodeComments = new ArrayList<IComment>();
        for (final IComment comment : functionNode.getLocalFunctionComment()) {
            try {
                final Integer commentId = provider.appendFunctionNodeComment(functionNode, comment.getComment(), comment.getUser().getUserId());
                final IComment newComment = new CComment(commentId, comment.getUser(), comment.getParent(), comment.getComment());
                functionNodeComments.add(newComment);
            } catch (final CouldntSaveDataException exception) {
                CUtilityFunctions.logException(exception);
            }
        }
        functionNode.initializeLocalFunctionComment(functionNodeComments);
    }
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction)

Example 8 with INaviFunctionNode

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

the class InternalNodeCallBack method zoomToAddress.

/**
   * Zooms to the first occurrence of an address in a graph.
   *
   * @param graph The graph where the zoom operation takes place.
   * @param address The address to zoom to.
   */
public static void zoomToAddress(final ZyGraph graph, final IAddress address) {
    graph.iterate(new INodeCallback<NaviNode>() {

        @Override
        public IterationMode next(final NaviNode node) {
            if (node.getRawNode() instanceof INaviCodeNode) {
                final INaviCodeNode codeNode = (INaviCodeNode) node.getRawNode();
                for (final INaviInstruction instruction : codeNode.getInstructions()) {
                    if (instruction.getAddress().equals(address)) {
                        uncollapseParents(codeNode);
                        graph.showNode(node, true);
                        ZoomFunctions.zoomToNode(graph, node);
                        return IterationMode.STOP;
                    }
                }
            } else if (node.getRawNode() instanceof INaviFunctionNode) {
                final INaviFunctionNode functionNode = (INaviFunctionNode) node.getRawNode();
                if (functionNode.getFunction().getAddress().equals(address)) {
                    uncollapseParents(functionNode);
                    graph.showNode(node, true);
                    ZoomFunctions.zoomToNode(graph, node);
                    return IterationMode.STOP;
                }
            }
            return IterationMode.CONTINUE;
        }
    });
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) IterationMode(com.google.security.zynamics.zylib.types.common.IterationMode) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 9 with INaviFunctionNode

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

the class CDebuggerPainter method updateDebuggerHighlighting.

/**
   * Updates the program counter highlighting in a whole graph.
   *
   * @param graph The graph where the highlighting is updated.
   * @param address The address of the program counter to be highlighted.
   * @param module The module in which the address is located.
   */
public static void updateDebuggerHighlighting(final ZyGraph graph, final UnrelocatedAddress address, final INaviModule module) {
    Preconditions.checkNotNull(graph, "IE02187: Graph argument can not be null");
    Preconditions.checkNotNull(address, "IE02188: Address argument can not be null");
    graph.iterate(new INodeCallback<NaviNode>() {

        @Override
        public IterationMode next(final NaviNode node) {
            final INaviViewNode rawNode = node.getRawNode();
            if (rawNode instanceof ICodeNode) {
                final INaviCodeNode codeNode = (INaviCodeNode) rawNode;
                try {
                    if (module.equals(codeNode.getParentFunction().getModule())) {
                        updateDebuggerHighlighting(graph, address, node, codeNode);
                    }
                } catch (final MaybeNullException exception) {
                    CUtilityFunctions.logException(exception);
                }
            } else if (rawNode instanceof INaviFunctionNode) {
                final INaviFunctionNode functionNode = (INaviFunctionNode) rawNode;
                if (module.equals(functionNode.getFunction().getModule())) {
                    updateDebuggerHighlighting(address, node, functionNode);
                }
            }
            return IterationMode.CONTINUE;
        }
    });
    ZyZoomHelpers.zoomToAddress(graph, address.getAddress(), module, false);
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) ICodeNode(com.google.security.zynamics.zylib.gui.zygraph.nodes.ICodeNode) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) IterationMode(com.google.security.zynamics.zylib.types.common.IterationMode)

Example 10 with INaviFunctionNode

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

the class PostgreSQLNotificationProviderTest method testAppendFunctionNodeCommentSync.

@Test
public void testAppendFunctionNodeCommentSync() 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);
    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);
}
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