Search in sources :

Example 41 with CComment

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

the class PostgreSQLTextNodeCommentTests method deleteTextNodeComment5.

@Test(expected = CouldntDeleteException.class)
public void deleteTextNodeComment5() throws CouldntDeleteException, CouldntLoadDataException, LoadCancelledException, MaybeNullException, CPartialLoadException, CouldntSaveDataException {
    final INaviTextNode textNode = setupTextNode();
    final List<IComment> comments = textNode.getComments() == null ? new ArrayList<IComment>() : textNode.getComments();
    final IComment lastComment = comments.size() == 0 ? null : Iterables.getLast(comments);
    final String commentString = " TEST DELETE TEXT NODE COMMENT WRONG USER ";
    final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    final int commentId = getProvider().appendTextNodeComment(textNode, commentString, user.getUserId());
    final IComment newComment = new CComment(commentId, user, lastComment, commentString);
    final ArrayList<IComment> storedComments = getProvider().loadCommentById(commentId);
    assertNotNull(storedComments);
    assertEquals(comments.size() + 1, storedComments.size());
    assertEquals(newComment, Iterables.getLast(storedComments));
    final IUser wrongUser = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    getProvider().deleteTextNodeComment(textNode, commentId, wrongUser.getUserId());
}
Also used : CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) INaviTextNode(com.google.security.zynamics.binnavi.disassembly.INaviTextNode) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) UniqueTestUserGenerator(com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 42 with CComment

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

the class PostgreSQLTextNodeCommentTests method deleteTextNodeComment4.

@Test
public void deleteTextNodeComment4() throws CouldntDeleteException, CouldntLoadDataException, LoadCancelledException, MaybeNullException, CPartialLoadException, CouldntSaveDataException {
    final INaviTextNode textNode = setupTextNode();
    final List<IComment> comments = textNode.getComments() == null ? new ArrayList<IComment>() : textNode.getComments();
    final IComment lastComment = comments.size() == 0 ? null : Iterables.getLast(comments);
    final String commentString = " TEST DELETE TEXT NODE COMMENT ";
    final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    final int commentId = getProvider().appendTextNodeComment(textNode, commentString, user.getUserId());
    final IComment newComment = new CComment(commentId, user, lastComment, commentString);
    final ArrayList<IComment> storedComments = getProvider().loadCommentById(commentId);
    assertNotNull(storedComments);
    assertEquals(comments.size() + 1, storedComments.size());
    assertEquals(newComment, Iterables.getLast(storedComments));
    getProvider().deleteTextNodeComment(textNode, commentId, user.getUserId());
    final ArrayList<IComment> commentsAfterDelete = getProvider().loadCommentById(commentId);
    assertNotNull(commentsAfterDelete);
    assertTrue(commentsAfterDelete.isEmpty());
}
Also used : CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) INaviTextNode(com.google.security.zynamics.binnavi.disassembly.INaviTextNode) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) UniqueTestUserGenerator(com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 43 with CComment

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

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

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

the class PostgreSQLInstructionFunctions method createInstructions.

/**
   * Saves an instruction to the database.
   *
   * @param provider The provider used to access the database.
   * @param instructions The instruction to save.
   *
   * @throws SQLException Thrown if the instruction could not be created.
   */
public static void createInstructions(final SQLProvider provider, final Iterable<INaviInstruction> instructions) throws SQLException {
    Preconditions.checkNotNull(provider, "IE01550: Provider argument can not be null");
    Preconditions.checkNotNull(instructions, "IE01554: Instruction argument can not be null");
    final String query = "INSERT INTO " + CTableNames.INSTRUCTIONS_TABLE + "(module_id, address, mnemonic, data, native, architecture, comment_id) " + "VALUES(?, ?, ?, ?, ?, ?, ?)";
    final PreparedStatement insertStatement = provider.getConnection().getConnection().prepareStatement(query);
    final ArrayList<INaviInstruction> instructionsWithUnsavedComments = new ArrayList<INaviInstruction>();
    final List<List<COperandTree>> operands = new ArrayList<List<COperandTree>>();
    for (final INaviInstruction instruction : instructions) {
        final String mnemonic = instruction.getMnemonic();
        final byte[] data = instruction.getData();
        operands.add(instruction.getOperands());
        final INaviModule module = instruction.getModule();
        final IAddress address = instruction.getAddress();
        final int moduleID = module.getConfiguration().getId();
        final List<IComment> comments = instruction.getGlobalComment();
        final Integer commentId = comments == null ? null : comments.size() == 0 ? null : Iterables.getLast(comments).getId();
        if ((comments != null) && (comments.size() != 0) && (commentId == null)) {
            instructionsWithUnsavedComments.add(instruction);
        }
        try {
            insertStatement.setInt(1, moduleID);
            insertStatement.setObject(2, address.toBigInteger(), Types.BIGINT);
            insertStatement.setString(3, mnemonic);
            insertStatement.setBytes(4, data);
            insertStatement.setBoolean(5, false);
            insertStatement.setObject(6, instruction.getArchitecture(), Types.OTHER);
            if (commentId == null) {
                insertStatement.setNull(7, Types.INTEGER);
            } else {
                insertStatement.setInt(7, commentId);
            }
            insertStatement.execute();
        } finally {
            insertStatement.close();
        }
    }
    // unsaved comments.
    for (final INaviInstruction instruction : instructionsWithUnsavedComments) {
        final ArrayList<IComment> instructionComments = new ArrayList<IComment>();
        for (final IComment comment : instruction.getGlobalComment()) {
            try {
                final Integer commentId = PostgreSQLInstructionFunctions.appendGlobalInstructionComment(provider, instruction, comment.getComment(), comment.getUser().getUserId());
                final IComment newComment = new CComment(commentId, comment.getUser(), comment.getParent(), comment.getComment());
                instructionComments.add(newComment);
            } catch (final CouldntSaveDataException exception) {
                CUtilityFunctions.logException(exception);
            }
        }
        instruction.initializeGlobalComment(instructionComments);
    }
    for (final List<COperandTree> operand : operands) {
        int position = 0;
        for (final COperandTree operandTree : operand) {
            createOperandTree(provider, operandTree, position);
            position++;
        }
    }
}
Also used : 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) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) BigInteger(java.math.BigInteger) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) ArrayList(java.util.ArrayList) List(java.util.List) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Aggregations

CComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment)121 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)114 Test (org.junit.Test)104 IUser (com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser)96 UniqueTestUserGenerator (com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator)89 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)89 ArrayList (java.util.ArrayList)13 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)11 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)10 INaviTextNode (com.google.security.zynamics.binnavi.disassembly.INaviTextNode)9 Date (java.util.Date)9 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)8 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)8 INaviGroupNode (com.google.security.zynamics.binnavi.disassembly.INaviGroupNode)8 CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)8 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)7 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)6 CTextNode (com.google.security.zynamics.binnavi.disassembly.CTextNode)6 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)5 CFunction (com.google.security.zynamics.binnavi.disassembly.CFunction)5