Search in sources :

Example 6 with IComment

use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.

the class GroupNodeTest method testSetCollapsed.

@Test
public void testSetCollapsed() {
    final Database database = new Database(new MockDatabase());
    final MockModule mockModule = new MockModule();
    final TagManager nodeTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.NODE_TAG));
    final TagManager viewTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.VIEW_TAG));
    final Module module = new Module(database, mockModule, nodeTagManager, viewTagManager);
    final MockView mockView = new MockView();
    final View view = new View(module, mockView, nodeTagManager, viewTagManager);
    final INaviGroupNode internalGroupNode = new CGroupNode(0, 0, 0, 0, 0, Color.RED, false, false, new HashSet<CTag>(), new ArrayList<IComment>(), false, new MockSqlProvider());
    final GroupNode node = new GroupNode(view, internalGroupNode, viewTagManager);
    final MockGroupNodeListener listener = new MockGroupNodeListener();
    node.addListener(listener);
    node.setCollapsed(true);
    assertEquals("changedState;", listener.events);
    assertTrue(node.isCollapsed());
    node.removeListener(listener);
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) Test(org.junit.Test)

Example 7 with IComment

use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.

the class CGraphDebuggerTest method testToggleBreakpoint3.

@Test
public void testToggleBreakpoint3() {
    final MockModule module = new MockModule();
    module.getConfiguration().setDebugger(m_debugger);
    m_debugger.setAddressTranslator(module, m_fileBase, m_imageBase);
    final DebugTargetSettings target = new ModuleTargetSettings(module);
    final DebuggerProvider debuggerProvider = new DebuggerProvider(target);
    debuggerProvider.addDebugger(m_debugger);
    final CFunction function = new CFunction(module, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, m_provider);
    final ArrayList<IComment> comments = Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Mock Comment"));
    final INaviCodeNode codeNode = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, false, comments, function, new HashSet<CTag>(), new MockSqlProvider());
    codeNode.addInstruction(new CInstruction(true, module, new CAddress(0x123), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", m_provider), null);
    codeNode.addInstruction(new CInstruction(true, module, new CAddress(0x124), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", m_provider), null);
    CGraphDebugger.toggleBreakpoint(debuggerProvider, codeNode, 2);
    assertEquals(1, m_debugger.getBreakpointManager().getNumberOfBreakpoints(BreakpointType.REGULAR));
    assertEquals(0x124, m_debugger.getBreakpointManager().getBreakpoint(BreakpointType.REGULAR, 0).getAddress().getAddress().getAddress().toLong());
    assertEquals(BreakpointStatus.BREAKPOINT_INACTIVE, m_debugger.getBreakpointManager().getBreakpointStatus(BreakpointType.REGULAR, 0));
    CGraphDebugger.toggleBreakpoint(debuggerProvider, codeNode, 2);
    assertEquals(0, m_debugger.getBreakpointManager().getNumberOfBreakpoints(BreakpointType.REGULAR));
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) ArrayList(java.util.ArrayList) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) DebugTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.DebugTargetSettings) ModuleTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) DebuggerProvider(com.google.security.zynamics.binnavi.debug.debugger.DebuggerProvider) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) Test(org.junit.Test)

Example 8 with IComment

use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.

the class PostgreSQLNodeSaver method saveGroupNodes.

/**
 * Saves the group 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 groupNodeIndices Index into the nodes list that identifies the group nodes.
 *
 * @throws SQLException Thrown if saving the group nodes failed.
 */
protected static void saveGroupNodes(final SQLProvider provider, final List<INaviViewNode> nodes, final int firstNode, final List<Integer> groupNodeIndices) throws SQLException {
    Preconditions.checkNotNull(provider, "IE02525: connection argument can not be null");
    Preconditions.checkNotNull(nodes, "IE02526: nodes argument can not be null");
    Preconditions.checkNotNull(groupNodeIndices, "Error: groupNodeIndices argument can not be null");
    if (!groupNodeIndices.isEmpty()) {
        final String query = "INSERT INTO " + CTableNames.GROUP_NODES_TABLE + "(node_id, collapsed, comment_id) VALUES (?, ?, ?)";
        final PreparedStatement preparedStatement = provider.getConnection().getConnection().prepareStatement(query);
        final List<INaviGroupNode> groupNodesWithUnsavedComments = new ArrayList<INaviGroupNode>();
        try {
            for (final Integer index : groupNodeIndices) {
                final INaviGroupNode node = (INaviGroupNode) nodes.get(index);
                preparedStatement.setInt(1, firstNode + index);
                preparedStatement.setBoolean(2, node.isCollapsed());
                final List<IComment> comment = node.getComments();
                final Integer commentId = comment == null ? null : comment.size() == 0 ? null : Iterables.getLast(comment).getId();
                if ((comment != null) && (comment.size() != 0) && (commentId == null)) {
                    groupNodesWithUnsavedComments.add(node);
                }
                if (commentId == null) {
                    preparedStatement.setNull(3, Types.INTEGER);
                } else {
                    preparedStatement.setInt(3, commentId);
                }
                preparedStatement.addBatch();
            }
            preparedStatement.executeBatch();
        } finally {
            preparedStatement.close();
        }
        // TODO (timkornau): this can work better.
        for (final INaviGroupNode groupNode : groupNodesWithUnsavedComments) {
            final ArrayList<IComment> groupNodeComments = new ArrayList<IComment>();
            for (final IComment comment : groupNode.getComments()) {
                try {
                    final Integer commentId = provider.appendGroupNodeComment(groupNode, comment.getComment(), comment.getUser().getUserId());
                    final IComment newComment = new CComment(commentId, comment.getUser(), comment.getParent(), comment.getComment());
                    groupNodeComments.add(newComment);
                } catch (final CouldntSaveDataException exception) {
                    CUtilityFunctions.logException(exception);
                }
            }
            groupNode.initializeComment(groupNodeComments);
        }
    }
}
Also used : CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) 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) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode)

Example 9 with IComment

use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.

the class PostgreSQLNodeSaver method saveCodeNodes.

/**
 * Saves the code 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 codeNodeIndices Index into the nodes list that identifies the code nodes.
 *
 * @throws SQLException Thrown if saving the code node instructions failed.
 */
protected static void saveCodeNodes(final SQLProvider provider, final List<INaviViewNode> nodes, final int firstNode, final List<Integer> codeNodeIndices) throws SQLException {
    if (!codeNodeIndices.isEmpty()) {
        final List<Pair<INaviCodeNode, INaviInstruction>> instructionsWithUnsavedLocalComments = PostgreSQLNodeSaver.saveCodeNodeInstructions(provider, nodes, firstNode, codeNodeIndices);
        final String query = "INSERT INTO " + CTableNames.CODE_NODES_TABLE + "(module_id, node_id, parent_function, comment_id) VALUES (?, ?, ?, ?)";
        final ArrayList<INaviCodeNode> codeNodesWithUnsavedComments = new ArrayList<INaviCodeNode>();
        final PreparedStatement preparedStatement = provider.getConnection().getConnection().prepareStatement(query);
        try {
            for (final int index : codeNodeIndices) {
                final INaviCodeNode codeNode = (INaviCodeNode) nodes.get(index);
                codeNode.setId(firstNode + index);
                INaviFunction function = null;
                try {
                    function = codeNode.getParentFunction();
                } catch (final MaybeNullException e) {
                }
                final int moduleId = Iterables.getLast(codeNode.getInstructions()).getModule().getConfiguration().getId();
                final List<IComment> comment = codeNode.getComments().getLocalCodeNodeComment();
                final Integer commentId = comment == null ? null : comment.size() == 0 ? null : Iterables.getLast(comment).getId();
                if ((comment != null) && (comment.size() != 0) && (commentId == null)) {
                    codeNodesWithUnsavedComments.add(codeNode);
                }
                preparedStatement.setInt(1, moduleId);
                preparedStatement.setInt(2, firstNode + index);
                if (function == null) {
                    preparedStatement.setNull(3, Types.BIGINT);
                } else {
                    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();
        }
        // implementation.
        for (final INaviCodeNode codeNode : codeNodesWithUnsavedComments) {
            final ArrayList<IComment> codeNodecomments = new ArrayList<IComment>();
            for (final IComment comment : codeNode.getComments().getLocalCodeNodeComment()) {
                try {
                    final Integer commentId = PostgreSQLNodeFunctions.appendLocalCodeNodeComment(provider, codeNode, comment.getComment(), comment.getUser().getUserId());
                    final IComment newComment = new CComment(commentId, comment.getUser(), comment.getParent(), comment.getComment());
                    codeNodecomments.add(newComment);
                } catch (final CouldntSaveDataException exception) {
                    CUtilityFunctions.logException(exception);
                }
            }
            codeNode.getComments().initializeLocalCodeNodeComment(codeNodecomments);
        }
        // implementation.
        for (final Pair<INaviCodeNode, INaviInstruction> pair : instructionsWithUnsavedLocalComments) {
            final ArrayList<IComment> localInstructionComments = new ArrayList<IComment>();
            for (final IComment comment : pair.first().getComments().getLocalInstructionComment(pair.second())) {
                try {
                    final int commentId = PostgreSQLInstructionFunctions.appendLocalInstructionComment(provider, pair.first(), pair.second(), comment.getComment(), comment.getUser().getUserId());
                    final IComment newComment = new CComment(commentId, comment.getUser(), comment.getParent(), comment.getComment());
                    localInstructionComments.add(newComment);
                } catch (final CouldntSaveDataException exception) {
                    CUtilityFunctions.logException(exception);
                }
            }
            pair.first().getComments().initializeLocalInstructionComment(pair.second(), localInstructionComments);
        }
    }
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) 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) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Pair(com.google.security.zynamics.zylib.general.Pair) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 10 with IComment

use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.

the class PostgreSQLNodeSaver method saveCodeNodeInstructions.

/**
 * Saves the mapping between code nodes and their instructions to the database.
 *
 * @param provider The provider used to access the database.
 * @param nodes The nodes to save.
 * @param firstNode The database index of the first node.
 * @param codeNodeIndices Index into the nodes list that identifies the code nodes.
 *
 * @throws SQLException Thrown if saving the code node instructions failed.
 */
protected static ArrayList<Pair<INaviCodeNode, INaviInstruction>> saveCodeNodeInstructions(final SQLProvider provider, final List<INaviViewNode> nodes, final int firstNode, final List<Integer> codeNodeIndices) throws SQLException {
    if (!nodes.isEmpty()) {
        final Set<INaviInstruction> unsavedInstructions = new HashSet<INaviInstruction>();
        for (final int index : codeNodeIndices) {
            final CCodeNode node = (CCodeNode) nodes.get(index);
            final Iterable<INaviInstruction> instructions = node.getInstructions();
            for (final INaviInstruction instruction : instructions) {
                if (!(instruction.isStored())) {
                    unsavedInstructions.add(instruction);
                }
            }
        }
        PostgreSQLInstructionFunctions.createInstructions(provider, unsavedInstructions);
        final String query = "INSERT INTO " + CTableNames.CODENODE_INSTRUCTIONS_TABLE + " (module_id, node_id, position, address, comment_id) VALUES (?, ?, ?, ?, ?)";
        final PreparedStatement preparedStatement = provider.getConnection().getConnection().prepareStatement(query);
        final ArrayList<Pair<INaviCodeNode, INaviInstruction>> instructionsWithUnsavedLocalComments = new ArrayList<Pair<INaviCodeNode, INaviInstruction>>();
        try {
            for (final Integer index : codeNodeIndices) {
                final INaviCodeNode codeNode = (INaviCodeNode) nodes.get(index);
                int position = 0;
                for (final INaviInstruction instruction : codeNode.getInstructions()) {
                    final List<IComment> comments = codeNode.getComments().getLocalInstructionComment(instruction);
                    final Integer commentId = comments == null ? null : comments.size() == 0 ? null : Iterables.getLast(comments).getId();
                    if ((comments != null) && (comments.size() != 0) && (commentId == null)) {
                        instructionsWithUnsavedLocalComments.add(new Pair<INaviCodeNode, INaviInstruction>(codeNode, instruction));
                    }
                    final int moduleId = instruction.getModule().getConfiguration().getId();
                    preparedStatement.setInt(1, moduleId);
                    preparedStatement.setInt(2, firstNode + index);
                    preparedStatement.setInt(3, position);
                    preparedStatement.setObject(4, instruction.getAddress().toBigInteger(), Types.BIGINT);
                    if (commentId == null) {
                        preparedStatement.setNull(5, Types.INTEGER);
                    } else {
                        preparedStatement.setInt(5, commentId);
                    }
                    position++;
                    preparedStatement.addBatch();
                }
            }
            preparedStatement.executeBatch();
        } finally {
            preparedStatement.close();
        }
        return instructionsWithUnsavedLocalComments;
    }
    return null;
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) HashSet(java.util.HashSet) Pair(com.google.security.zynamics.zylib.general.Pair)

Aggregations

IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)167 Test (org.junit.Test)129 CComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment)114 IUser (com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser)97 UniqueTestUserGenerator (com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator)89 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)89 ArrayList (java.util.ArrayList)20 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)18 INaviGroupNode (com.google.security.zynamics.binnavi.disassembly.INaviGroupNode)16 INaviTextNode (com.google.security.zynamics.binnavi.disassembly.INaviTextNode)13 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)12 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)11 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)10 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)10 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)9 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)9 PreparedStatement (java.sql.PreparedStatement)8 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)7 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)7 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)7