Search in sources :

Example 21 with IComment

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

the class PostgreSQLNotificationProviderTest method testAppendLocalEdgeCommentSync.

@Test
public void testAppendLocalEdgeCommentSync() throws CouldntSaveDataException, CouldntLoadDataException, InterruptedException {
    final INaviEdge databaseOneEdge = databaseOneView.getContent().getGraph().getEdges().get(3);
    final INaviEdge databaseTwoEdge = databaseTwoView.getContent().getGraph().getEdges().get(3);
    final List<IComment> oneBefore = databaseOneEdge.getLocalComment() == null ? new ArrayList<IComment>() : databaseOneEdge.getLocalComment();
    final List<IComment> twoBefore = databaseTwoEdge.getLocalComment() == null ? new ArrayList<IComment>() : databaseTwoEdge.getLocalComment();
    assertEquals(oneBefore, twoBefore);
    databaseOneEdge.appendLocalComment(" TEST NOTIFICATION PROVIDER TESTS (LOCAL CODE NODE COMMENT) ");
    // database one to two over the PostgreSQL back end.
    synchronized (lock) {
        lock.await(1000, TimeUnit.MILLISECONDS);
    }
    final List<IComment> oneAfter = databaseOneEdge.getLocalComment();
    final List<IComment> twoAfter = databaseTwoEdge.getLocalComment();
    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) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) Test(org.junit.Test)

Example 22 with IComment

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

the class PostgreSQLNotificationProviderTest method testEditGlobalCodeNodeCommentSync.

@Test
public void testEditGlobalCodeNodeCommentSync() throws CouldntSaveDataException, CouldntLoadDataException, InterruptedException {
    final INaviCodeNode databaseOnecodeNode = databaseOneView.getContent().getBasicBlocks().get(1);
    final INaviCodeNode databaseTwocodeNode = databaseTwoView.getContent().getBasicBlocks().get(1);
    final List<IComment> oneBefore = databaseOnecodeNode.getComments().getGlobalCodeNodeComment() == null ? new ArrayList<IComment>() : databaseOnecodeNode.getComments().getGlobalCodeNodeComment();
    final List<IComment> twoBefore = databaseTwocodeNode.getComments().getGlobalCodeNodeComment() == null ? new ArrayList<IComment>() : databaseTwocodeNode.getComments().getGlobalCodeNodeComment();
    assertEquals(oneBefore, twoBefore);
    databaseOnecodeNode.getComments().appendGlobalCodeNodeComment(" TEST NOTIFICATION PROVIDER TESTS (GLOBAL CODE NODE COMMENT) BEFORE ");
    // database one to two over the PostgreSQL back end.
    synchronized (lock) {
        lock.await(1000, TimeUnit.MILLISECONDS);
    }
    final List<IComment> oneAfter = databaseOnecodeNode.getComments().getGlobalCodeNodeComment();
    final List<IComment> twoAfter = databaseTwocodeNode.getComments().getGlobalCodeNodeComment();
    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().editGlobalCodeNodeComment(Iterables.getLast(databaseOnecodeNode.getComments().getGlobalCodeNodeComment()), " TEST NOTIFICATION PROVIDER TESTS (GLOBAL CODE NODE COMMENT) AFTER ");
    // database one to two over the PostgreSQL back end.
    synchronized (lock) {
        lock.await(1000, TimeUnit.MILLISECONDS);
    }
    final List<IComment> oneThree = databaseOnecodeNode.getComments().getGlobalCodeNodeComment();
    final List<IComment> twoThree = databaseTwocodeNode.getComments().getGlobalCodeNodeComment();
    assertEquals(oneTwoSize, oneThree.size());
    assertEquals(twoTwoSize, twoThree.size());
    assertEquals(oneThree, twoThree);
    assertEquals(" TEST NOTIFICATION PROVIDER TESTS (GLOBAL CODE NODE COMMENT) AFTER ", Iterables.getLast(oneThree).getComment());
    assertEquals(" TEST NOTIFICATION PROVIDER TESTS (GLOBAL CODE NODE COMMENT) AFTER ", Iterables.getLast(twoThree).getComment());
}
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 23 with IComment

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

the class CViewInserterTest method test.

@Test
public void test() throws CouldntLoadDataException, CPartialLoadException, LoadCancelledException, FileReadException, CouldntSaveDataException {
    ConfigManager.instance().read();
    final INaviModule mockModule = new MockModule();
    final MockSqlProvider mockProvider = new MockSqlProvider();
    final CUserManager userManager = CUserManager.get(mockProvider);
    final IUser user = userManager.addUser(" VIEW INSERTER USER ");
    userManager.setCurrentActiveUser(user);
    final CModuleViewGenerator generator = new CModuleViewGenerator(mockProvider, mockModule);
    final CView view = generator.generate(1, "", "", ViewType.NonNative, GraphType.MIXED_GRAPH, new Date(), new Date(), 0, 0, new HashSet<CTag>(), new HashSet<CTag>(), false);
    view.load();
    final MockFunction mockFunction = new MockFunction(mockProvider);
    final CFunctionNode fnode1 = view.getContent().createFunctionNode(mockFunction);
    final CFunctionNode fnode2 = view.getContent().createFunctionNode(mockFunction);
    @SuppressWarnings("unused") final CNaviViewEdge edge1 = view.getContent().createEdge(fnode1, fnode2, EdgeType.JUMP_UNCONDITIONAL);
    final MockInstruction instruction1 = new MockInstruction();
    final CCodeNode cnode1 = view.getContent().createCodeNode(mockFunction, Lists.newArrayList(instruction1));
    final CCodeNode cnode2 = view.getContent().createCodeNode(mockFunction, Lists.newArrayList(instruction1));
    @SuppressWarnings("unused") final CNaviViewEdge edge2 = view.getContent().createEdge(cnode1, cnode2, EdgeType.JUMP_UNCONDITIONAL);
    final ArrayList<IComment> comments = Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Foo"));
    final CTextNode tnode1 = view.getContent().createTextNode(comments);
    @SuppressWarnings("unused") final CNaviViewEdge edge3 = view.getContent().createEdge(cnode1, tnode1, EdgeType.JUMP_UNCONDITIONAL);
    final CGroupNode gnode1 = view.getContent().createGroupNode(Lists.newArrayList((INaviViewNode) fnode1, (INaviViewNode) fnode2));
    gnode1.appendComment("TEST GROUP NODE COMMENT 1");
    final CView view2 = generator.generate(2, "", "", ViewType.NonNative, GraphType.MIXED_GRAPH, new Date(), new Date(), 0, 0, new HashSet<CTag>(), new HashSet<CTag>(), false);
    view2.load();
    CViewInserter.insertView(view, view2);
    final List<INaviViewNode> nodes = view2.getGraph().getNodes();
    assertEquals(view2.getNodeCount(), 6);
    assertEquals(mockFunction, ((INaviFunctionNode) nodes.get(0)).getFunction());
    assertEquals(nodes.get(5), ((INaviFunctionNode) nodes.get(0)).getParentGroup());
}
Also used : MockFunction(com.google.security.zynamics.binnavi.disassembly.MockFunction) CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) CModuleViewGenerator(com.google.security.zynamics.binnavi.Database.CModuleViewGenerator) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CUserManager(com.google.security.zynamics.binnavi.Gui.Users.CUserManager) Date(java.util.Date) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) CNaviViewEdge(com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) Test(org.junit.Test)

Example 24 with IComment

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

the class MockView method getFullView.

public static INaviView getFullView(final SQLProvider sql, final ViewType type, final Integer viewId) {
    final Integer realViewId = viewId == null ? new BigInteger(31, new SecureRandom()).intValue() : viewId;
    final MockFunction function = new MockFunction(4608);
    final List<INaviViewNode> nodes = new ArrayList<INaviViewNode>();
    final List<INaviEdge> edges = new ArrayList<INaviEdge>();
    nodes.add(new CCodeNode(1111, 0, 0, 0, 0, Color.RED, Color.RED, false, true, Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "GC I")), function, new LinkedHashSet<CTag>(), sql));
    nodes.add(new CCodeNode(2222, 0, 0, 0, 0, Color.RED, Color.RED, false, true, Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "GC II")), function, new LinkedHashSet<CTag>(), sql));
    nodes.add(new CCodeNode(3333, 0, 0, 0, 0, Color.RED, Color.RED, false, true, Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "GC III")), function, new LinkedHashSet<CTag>(), sql));
    nodes.add(new CCodeNode(4444, 0, 0, 0, 0, Color.RED, Color.RED, false, true, Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "GC IV")), function, new LinkedHashSet<CTag>(), sql));
    nodes.add(new CCodeNode(5555, 0, 0, 0, 0, Color.RED, Color.RED, false, true, Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "GC V")), function, new LinkedHashSet<CTag>(), sql));
    nodes.add(new CFunctionNode(6666, new MockFunction(sql, 4608), 0, 0, 0, 0, Color.GREEN, false, true, null, new HashSet<CTag>(), sql));
    nodes.add(new CTextNode(7777, 0, 0, 0, 0, Color.YELLOW, false, true, new LinkedHashSet<CTag>(), null, sql));
    nodes.add(new CGroupNode(8888, 0, 0, 0, 0, Color.BLACK, false, true, new LinkedHashSet<CTag>(), null, false, sql));
    ((INaviCodeNode) nodes.get(0)).addInstruction(MockCreator.createInstructionWithOperand(function.getAddress().toBigInteger().add(BigInteger.valueOf(0)), function.getModule(), sql), null);
    ((INaviCodeNode) nodes.get(0)).addInstruction(MockCreator.createInstructionWithOperand(function.getAddress().toBigInteger().add(BigInteger.valueOf(1)), function.getModule(), sql), null);
    ((INaviCodeNode) nodes.get(0)).addInstruction(MockCreator.createInstructionWithOperand(function.getAddress().toBigInteger().add(BigInteger.valueOf(2)), function.getModule(), sql), null);
    ((INaviCodeNode) nodes.get(1)).addInstruction(MockCreator.createInstructionWithOperand(function.getAddress().toBigInteger().add(BigInteger.valueOf(3)), function.getModule(), sql), null);
    ((INaviCodeNode) nodes.get(1)).addInstruction(MockCreator.createInstructionWithOperand(function.getAddress().toBigInteger().add(BigInteger.valueOf(4)), function.getModule(), sql), null);
    ((INaviCodeNode) nodes.get(1)).addInstruction(MockCreator.createInstructionWithOperand(function.getAddress().toBigInteger().add(BigInteger.valueOf(5)), function.getModule(), sql), null);
    ((INaviCodeNode) nodes.get(2)).addInstruction(MockCreator.createInstructionWithOperand(function.getAddress().toBigInteger().add(BigInteger.valueOf(6)), function.getModule(), sql), null);
    ((INaviCodeNode) nodes.get(2)).addInstruction(MockCreator.createInstructionWithOperand(function.getAddress().toBigInteger().add(BigInteger.valueOf(7)), function.getModule(), sql), null);
    ((INaviCodeNode) nodes.get(2)).addInstruction(MockCreator.createInstructionWithOperand(function.getAddress().toBigInteger().add(BigInteger.valueOf(8)), function.getModule(), sql), null);
    ((INaviCodeNode) nodes.get(3)).addInstruction(MockCreator.createInstructionWithOperand(function.getAddress().toBigInteger().add(BigInteger.valueOf(9)), function.getModule(), sql), null);
    ((INaviCodeNode) nodes.get(3)).addInstruction(MockCreator.createInstructionWithOperand(function.getAddress().toBigInteger().add(BigInteger.valueOf(10)), function.getModule(), sql), null);
    ((INaviCodeNode) nodes.get(3)).addInstruction(MockCreator.createInstructionWithOperand(function.getAddress().toBigInteger().add(BigInteger.valueOf(11)), function.getModule(), sql), null);
    ((INaviCodeNode) nodes.get(4)).addInstruction(MockCreator.createInstructionWithOperand(function.getAddress().toBigInteger().add(BigInteger.valueOf(12)), function.getModule(), sql), null);
    ((INaviCodeNode) nodes.get(4)).addInstruction(MockCreator.createInstructionWithOperand(function.getAddress().toBigInteger().add(BigInteger.valueOf(13)), function.getModule(), sql), null);
    ((INaviCodeNode) nodes.get(4)).addInstruction(MockCreator.createInstructionWithOperand(function.getAddress().toBigInteger().add(BigInteger.valueOf(14)), function.getModule(), sql), null);
    final CNaviViewEdge edge1 = new CNaviViewEdge(1111, nodes.get(0), nodes.get(2), EdgeType.JUMP_UNCONDITIONAL, 0, 0, 0, 0, Color.BLACK, false, false, null, new FilledList<CBend>(), sql);
    final CNaviViewEdge edge2 = new CNaviViewEdge(2222, nodes.get(1), nodes.get(2), EdgeType.JUMP_UNCONDITIONAL, 0, 0, 0, 0, Color.BLACK, false, false, null, new FilledList<CBend>(), sql);
    final CNaviViewEdge edge3 = new CNaviViewEdge(3333, nodes.get(2), nodes.get(3), EdgeType.JUMP_UNCONDITIONAL, 0, 0, 0, 0, Color.BLACK, false, false, null, new FilledList<CBend>(), sql);
    final CNaviViewEdge edge4 = new CNaviViewEdge(4444, nodes.get(2), nodes.get(4), EdgeType.JUMP_UNCONDITIONAL, 0, 0, 0, 0, Color.BLACK, false, false, null, new FilledList<CBend>(), sql);
    edges.add(edge1);
    edges.add(edge2);
    edges.add(edge3);
    edges.add(edge4);
    nodes.get(0).addOutgoingEdge(edge1);
    nodes.get(2).addIncomingEdge(edge1);
    nodes.get(1).addOutgoingEdge(edge2);
    nodes.get(2).addIncomingEdge(edge2);
    nodes.get(2).addOutgoingEdge(edge3);
    nodes.get(3).addIncomingEdge(edge3);
    nodes.get(2).addOutgoingEdge(edge4);
    nodes.get(4).addIncomingEdge(edge4);
    assert nodes.get(2).getParents().size() == 2;
    NodeCache.get(sql).addNodes(nodes);
    EdgeCache.get(sql).addEdges(edges);
    for (final INaviViewNode node : nodes) {
        if (node instanceof INaviCodeNode) {
            InstructionCache.get(sql).addInstructions(((INaviCodeNode) node).getInstructions());
        }
    }
    return new MockView(new MutableDirectedGraph<INaviViewNode, INaviEdge>(nodes, edges), sql, type, realViewId);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) ArrayList(java.util.ArrayList) SecureRandom(java.security.SecureRandom) BigInteger(java.math.BigInteger) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) CBend(com.google.security.zynamics.zylib.gui.zygraph.edges.CBend) BigInteger(java.math.BigInteger) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 25 with IComment

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

the class PostgreSQLEdgeLoader method loadGlobalEdgeComments.

/**
 * Loads the edge comments of a view.
 *
 * @param provider The provider used to access the database.
 * @param viewId ID of the view whose edges are loaded.
 *
 * @return A map of <Edge ID, Edge Comment>.
 *
 * @throws CouldntLoadDataException
 */
private static Map<Integer, ArrayList<IComment>> loadGlobalEdgeComments(final SQLProvider provider, final int viewId) throws CouldntLoadDataException {
    // TODO (timkornau): this query needs to go into the database and needs to use the get all
    // comment ancestors
    // to build the complete
    // comment structure for each edge comment.
    final String query = "SELECT e.id, gc.comment_id FROM " + CTableNames.GLOBAL_EDGE_COMMENTS_TABLE + " AS gc " + " join " + CTableNames.INSTRUCTIONS_TABLE + " AS src_inst on gc.src_address = src_inst.address " + "AND gc.src_module_id = src_inst.module_id " + " join " + CTableNames.INSTRUCTIONS_TABLE + " AS dst_inst on gc.dst_address = dst_inst.address " + "AND gc.dst_module_id = dst_inst.module_id " + " join " + CTableNames.CODENODE_INSTRUCTIONS_TABLE + " AS src_nodes on src_nodes.address = gc.src_address AND src_nodes.position = 0 " + "AND src_nodes.module_id = gc.src_module_id " + " join " + CTableNames.CODENODE_INSTRUCTIONS_TABLE + " AS dst_nodes on dst_nodes.address = gc.dst_address AND dst_nodes.position = 0 " + "AND dst_nodes.module_id = gc.dst_module_id " + " join " + CTableNames.EDGES_TABLE + " AS e ON e.source_node_id = src_nodes.node_id AND e.target_node_id = dst_nodes.node_id " + " join " + CTableNames.NODES_TABLE + " AS src_n ON e.source_node_id = src_n.id " + " join " + CTableNames.NODES_TABLE + " AS dst_n ON e.target_node_id = dst_n.id " + " WHERE src_n.view_id = " + viewId + " AND dst_n.view_id = " + viewId;
    final HashMap<Integer, Integer> commentIdsToEdgeIds = new HashMap<Integer, Integer>();
    final HashMap<Integer, ArrayList<IComment>> edgeIdsToCommentArray = new HashMap<Integer, ArrayList<IComment>>();
    try {
        final ResultSet resultSet = provider.getConnection().executeQuery(query, true);
        try {
            while (resultSet.next()) {
                final int edgeId = resultSet.getInt("id");
                final int commentId = resultSet.getInt("comment_id");
                commentIdsToEdgeIds.put(commentId, edgeId);
            }
        } finally {
            resultSet.close();
        }
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException(exception);
    }
    if (!commentIdsToEdgeIds.isEmpty()) {
        final HashMap<Integer, ArrayList<IComment>> commentIdsToComments = PostgreSQLCommentFunctions.loadMultipleCommentsById(provider, commentIdsToEdgeIds.keySet());
        for (final Entry<Integer, ArrayList<IComment>> commentIdToComment : commentIdsToComments.entrySet()) {
            edgeIdsToCommentArray.put(commentIdsToEdgeIds.get(commentIdToComment.getKey()), commentIdToComment.getValue());
        }
    }
    return edgeIdsToCommentArray;
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet)

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