Search in sources :

Example 51 with IComment

use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment 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 52 with IComment

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

the class TypeInstanceTableDatamodel method generateFormattedComment.

private static FormattedCharacterBuffer generateFormattedComment(final List<IComment> comments) {
    // Calculate the number of rows that will be needed.
    int numberOfRows = 0;
    for (final IComment comment : comments) {
        final CommentContainer commentContainer = new CommentContainer(comment);
        final List<String> commentFragments = commentContainer.getCommentingString();
        numberOfRows += commentFragments.size();
    }
    // Generate and fill the buffer.
    FormattedCharacterBuffer result = new FormattedCharacterBuffer(numberOfRows + 1, columns[COMMENTS_INDEX].getWidth());
    int lineIndex = 0;
    int columnIndex = 0;
    for (final IComment comment : comments) {
        final CommentContainer commentContainer = new CommentContainer(comment);
        final List<String> commentFragments = commentContainer.getCommentingString();
        for (final String commentFragment : commentFragments) {
            for (int i = 0; i < commentFragment.length(); i++) {
                result.setAt(lineIndex, columnIndex, commentFragment.charAt(i), STANDARD_FONT, Color.BLACK, Color.WHITE);
                columnIndex++;
            }
            columnIndex = 0;
            lineIndex++;
        }
    }
    return result;
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) CommentContainer(com.google.security.zynamics.binnavi.ZyGraph.Builders.CommentContainer) FormattedCharacterBuffer(com.google.security.zynamics.zylib.gui.CodeDisplay.FormattedCharacterBuffer)

Example 53 with IComment

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

the class ViewEdgeTest method setUp.

@Before
public void setUp() throws CouldntLoadDataException, LoadCancelledException {
    final MockSqlProvider provider = new MockSqlProvider();
    final Database database = new Database(new MockDatabase());
    final CModule internalModule = new CModule(123, "Name", "Comment", new Date(), new Date(), "12345678123456781234567812345678", "1234567812345678123456781234567812345678", 55, 66, new CAddress(0x555), new CAddress(0x666), new DebuggerTemplate(1, "Mock Debugger", "localhaus", 88, provider), null, Integer.MAX_VALUE, false, provider);
    internalModule.load();
    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, internalModule, nodeTagManager, viewTagManager);
    internalModule.getContent().getViewContainer().createView("", "");
    // new View(module, mockView, nodeTagManager,
    final View view = module.getViews().get(2);
    // viewTagManager);
    final ArrayList<IComment> comment = Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, " COMMENT "));
    m_source = view.createTextNode(comment);
    m_target = view.createTextNode(comment);
    // m_internalEdge = new CNaviEdge(1, internalNode, internalNode,
    // com.google.security.zynamics.zylib.gui.zygraph.edges.EdgeType.JUMP_UNCONDITIONAL, 0, 0, 0, 0,
    // Color.MAGENTA,
    // false, true, "", new FilledList<CBend>(), new MockSqlProvider());
    // new
    m_edge = view.createEdge(m_source, m_target, EdgeType.JumpUnconditional);
// ViewEdge(m_internalEdge,
// m_source,
// m_target);
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) DebuggerTemplate(com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) 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) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Before(org.junit.Before)

Example 54 with IComment

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

the class PostgreSQLNotificationProviderTest method testDeleteLocalInstructionCommentSync.

@Test
public void testDeleteLocalInstructionCommentSync() throws CouldntSaveDataException, CouldntLoadDataException, InterruptedException, CouldntDeleteException {
    final INaviCodeNode databaseOnecodeNode = databaseOneView.getContent().getBasicBlocks().get(3);
    final INaviCodeNode databaseTwocodeNode = databaseTwoView.getContent().getBasicBlocks().get(3);
    final List<IComment> oneBefore = databaseOnecodeNode.getComments().getLocalInstructionComment(databaseOnecodeNode.getLastInstruction()) == null ? new ArrayList<IComment>() : databaseOnecodeNode.getComments().getLocalInstructionComment(databaseOnecodeNode.getLastInstruction());
    final List<IComment> twoBefore = databaseTwocodeNode.getComments().getLocalInstructionComment(databaseTwocodeNode.getLastInstruction()) == null ? new ArrayList<IComment>() : databaseTwocodeNode.getComments().getLocalInstructionComment(databaseTwocodeNode.getLastInstruction());
    assertEquals(oneBefore, twoBefore);
    final List<IComment> comments = databaseOnecodeNode.getComments().appendLocalInstructionComment(databaseOnecodeNode.getLastInstruction(), " TEST NOTIFICATION PROVIDER TESTS (GLOBAL INSTRUCTION COMMENT)");
    // database one to two over the PostgreSQL back end.
    synchronized (lock) {
        lock.await(1000, TimeUnit.MILLISECONDS);
    }
    final List<IComment> oneAfter = databaseOnecodeNode.getComments().getLocalInstructionComment(databaseOnecodeNode.getLastInstruction());
    final List<IComment> twoAfter = databaseTwocodeNode.getComments().getLocalInstructionComment(databaseTwocodeNode.getLastInstruction());
    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();
    databaseOnecodeNode.getComments().deleteLocalInstructionComment(databaseOnecodeNode.getLastInstruction(), Iterables.getLast(comments));
    // database one to two over the PostgreSQL back end.
    synchronized (lock) {
        lock.await(1000, TimeUnit.MILLISECONDS);
    }
    final List<IComment> oneThree = databaseOnecodeNode.getComments().getLocalInstructionComment(databaseOnecodeNode.getLastInstruction());
    final List<IComment> twoThree = databaseTwocodeNode.getComments().getLocalInstructionComment(databaseTwocodeNode.getLastInstruction());
    assertEquals(oneTwoSize - 1, oneThree.size());
    assertEquals(twoTwoSize - 1, twoThree.size());
    assertEquals(oneThree, twoThree);
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) Test(org.junit.Test)

Example 55 with IComment

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

the class PostgreSQLNotificationProviderTest method testAppendGlobalInstructionCommentSync.

@Test
public void testAppendGlobalInstructionCommentSync() throws CouldntSaveDataException, CouldntLoadDataException, InterruptedException {
    final INaviCodeNode databaseOnecodeNode = databaseOneView.getContent().getBasicBlocks().get(3);
    final INaviCodeNode databaseTwocodeNode = databaseTwoView.getContent().getBasicBlocks().get(3);
    final List<IComment> oneBefore = Iterables.getFirst(databaseOnecodeNode.getInstructions(), null).getGlobalComment() == null ? new ArrayList<IComment>() : Iterables.getFirst(databaseOnecodeNode.getInstructions(), null).getGlobalComment();
    final List<IComment> twoBefore = Iterables.getFirst(databaseTwocodeNode.getInstructions(), null).getGlobalComment() == null ? new ArrayList<IComment>() : Iterables.getFirst(databaseTwocodeNode.getInstructions(), null).getGlobalComment();
    assertEquals(oneBefore, twoBefore);
    Iterables.getFirst(databaseOnecodeNode.getInstructions(), null).appendGlobalComment(" TEST NOTIFICATION PROVIDER TESTS (GLOBAL INSTRUCTION COMMENT)");
    // database one to two over the PostgreSQL back end.
    synchronized (lock) {
        lock.await(1000, TimeUnit.MILLISECONDS);
    }
    final List<IComment> oneAfter = Iterables.getFirst(databaseOnecodeNode.getInstructions(), null).getGlobalComment();
    final List<IComment> twoAfter = Iterables.getFirst(databaseTwocodeNode.getInstructions(), null).getGlobalComment();
    assertNotNull(oneAfter);
    assertNotNull(twoAfter);
    assertEquals(oneBefore.size() + 1, oneAfter.size());
    assertEquals(twoBefore.size() + 1, twoAfter.size());
    assertEquals(oneAfter, twoAfter);
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) 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