Search in sources :

Example 71 with IComment

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

the class GenericCommentsTableModel method editComment.

private IComment editComment(IComment comment, String newComment) {
    IComment newlySetComment = null;
    try {
        if (newComment.isEmpty()) {
            commentAccessor.deleteComment(comment);
        } else {
            newlySetComment = commentAccessor.editComment(comment, newComment);
        }
    } catch (CouldntSaveDataException | CouldntDeleteException e) {
        CUtilityFunctions.logException(e);
    }
    resetCachedComments();
    return newlySetComment;
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)

Example 72 with IComment

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

the class GenericCommentsTableModel method keyPressedOrTyped.

@Override
public /**
   * Please read the comment in the base class regarding this method - it is somewhat counter-
   * intuitive for people used to the Swing keyboard handling model.
   */
void keyPressedOrTyped(CodeDisplayCoordinate coordinate, KeyEvent event) {
    int commentRow = coordinate.getRow();
    IComment comment = null;
    if (commentRow < cachedComments.size()) {
        comment = cachedComments.get(commentRow);
    }
    if (!isEditable(coordinate)) {
        return;
    }
    switch(event.getKeyCode()) {
        // VK_UNDEFINED implies that this was a KEY_TYPED event.
        case KeyEvent.VK_UNDEFINED:
            if (commentRow >= cachedComments.size()) {
                // Create a new comment.
                try {
                    commentAccessor.appendComment(String.format("%c", event.getKeyChar()));
                    coordinate.setFieldIndex(1);
                } catch (CouldntSaveDataException | CouldntLoadDataException e) {
                    CUtilityFunctions.logException(e);
                }
                resetCachedComments();
                // the handling code below.
                break;
            }
            switch(event.getKeyChar()) {
                case KeyEvent.VK_ENTER:
                    comment = handleRegularKeyInComment(comment, coordinate, event);
                    coordinate.setLine(coordinate.getLine() < (comment.getNumberOfCommentLines() - 1) ? coordinate.getLine() + 1 : comment.getNumberOfCommentLines() - 1);
                    coordinate.setFieldIndex(0);
                    break;
                case KeyEvent.VK_BACK_SPACE:
                    comment = handleBackspaceKeyInComment(comment, coordinate);
                    break;
                case KeyEvent.VK_DELETE:
                    comment = handleDeleteKeyInComment(comment, coordinate);
                    break;
                default:
                    comment = handleRegularKeyInComment(comment, coordinate, event);
                    coordinate.setFieldIndex(coordinate.getFieldIndex() + 1);
                    break;
            }
            break;
        case KeyEvent.VK_HOME:
            coordinate.setFieldIndex(0);
            break;
        case KeyEvent.VK_END:
            coordinate.setFieldIndex(columns[coordinate.getColumn()].getWidth());
            break;
        default:
            throw new IllegalArgumentException();
    }
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)

Example 73 with IComment

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

the class InstructionCommentsDataModel method getCommentUserCharacterBuffer.

private FormattedCharacterBuffer getCommentUserCharacterBuffer(int rowIndex, int columnIndex, int lineIndex) {
    // Return the user string associated with the comment.
    ArrayList<IComment> comments = internalData.get(rowIndex).second();
    int currentLineIndex = 0;
    String username = "";
    for (IComment comment : comments) {
        if ((currentLineIndex + comment.getNumberOfCommentLines() > lineIndex) && (currentLineIndex == lineIndex)) {
            // Found the right comment.
            String temp = comment.getUser().getUserName();
            if (temp != null) {
                username = temp;
            }
            break;
        }
        currentLineIndex += comment.getNumberOfCommentLines();
    }
    username = CodeDisplay.padRight(username, getColumnWidthInCharacters(columnIndex));
    return new FormattedCharacterBuffer(username, STANDARD_FONT, columns[USER_INDEX].getDefaultFontColor(), columns[USER_INDEX].getDefaultBackgroundColor());
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) FormattedCharacterBuffer(com.google.security.zynamics.zylib.gui.CodeDisplay.FormattedCharacterBuffer)

Example 74 with IComment

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

the class LocalInstructionCommentAccessor method getAllComments.

@Override
public ArrayList<Pair<INaviInstruction, IComment>> getAllComments() {
    final ArrayList<Pair<INaviInstruction, IComment>> values = new ArrayList<>();
    final CCodeNodeComments currentComments = m_codeNode.getComments();
    for (final INaviInstruction instruction : m_codeNode.getInstructions()) {
        final List<IComment> comments = currentComments.getLocalInstructionComment(instruction);
        if ((comments == null) || comments.isEmpty()) {
            values.add(new Pair<INaviInstruction, IComment>(instruction, new EmptyComment()));
            continue;
        } else {
            for (final IComment comment : comments) {
                values.add(new Pair<INaviInstruction, IComment>(instruction, comment));
            }
            values.add(new Pair<INaviInstruction, IComment>(instruction, new EmptyComment()));
        }
    }
    return values;
}
Also used : EmptyComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.EmptyComment) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) CCodeNodeComments(com.google.security.zynamics.binnavi.disassembly.CCodeNodeComments) ArrayList(java.util.ArrayList) Pair(com.google.security.zynamics.zylib.general.Pair) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 75 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)

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