Search in sources :

Example 91 with CComment

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

the class FunctionTest method testAppendFunctionComment.

@Test
public void testAppendFunctionComment() throws CouldntSaveDataException, com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException, CouldntLoadDataException {
    final MockFunctionListener listener = new MockFunctionListener();
    final Function function = new Function(ModuleFactory.get(), m_internalFunction2);
    function.addListener(listener);
    final CUserManager userManager = CUserManager.get(m_provider);
    final IUser user = userManager.addUser(" SET FUNCTION COMMENT TEST ");
    userManager.setCurrentActiveUser(user);
    final List<IComment> appendedComments = function.appendComment("Hannes");
    assertEquals(appendedComments, function.getComment());
    assertEquals(appendedComments, m_internalFunction2.getGlobalComment());
    assertEquals("appendedComment;", listener.events);
    final ArrayList<IComment> comments = Lists.newArrayList();
    comments.add(new CComment(12345, CommonTestObjects.TEST_USER_1, null, "FOO"));
    m_internalFunction2.initializeGlobalComment(comments);
    assertEquals(comments.get(0), function.getComment().get(0));
    assertEquals(comments.get(0), m_internalFunction2.getGlobalComment().get(0));
    assertEquals("appendedComment;initializedComments;", listener.events);
    function.removeListener(listener);
}
Also used : CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) CUserManager(com.google.security.zynamics.binnavi.Gui.Users.CUserManager) Test(org.junit.Test)

Example 92 with CComment

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

the class InstructionTest method testCommentInitialization.

@Test
public void testCommentInitialization() throws CouldntLoadDataException, LoadCancelledException {
    final SQLProvider provider = new MockSqlProvider();
    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 COperandTreeNode rootNode1 = new COperandTreeNode(1, IOperandTree.NODE_TYPE_REGISTER_ID, "eax", null, new ArrayList<IReference>(), provider, internalModule.getTypeManager(), internalModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode rootNode2 = new COperandTreeNode(1, IOperandTree.NODE_TYPE_REGISTER_ID, "ebx", null, new ArrayList<IReference>(), provider, internalModule.getTypeManager(), internalModule.getContent().getTypeInstanceContainer());
    final COperandTree operand1 = new COperandTree(rootNode1, provider, internalModule.getTypeManager(), internalModule.getContent().getTypeInstanceContainer());
    final COperandTree operand2 = new COperandTree(rootNode2, provider, internalModule.getTypeManager(), internalModule.getContent().getTypeInstanceContainer());
    final List<COperandTree> operands = Lists.newArrayList(operand1, operand2);
    final CInstruction internalInstruction = new CInstruction(false, internalModule, new CAddress(0x123), "mov", operands, new byte[] { 1, 2, 3 }, "x86-32", provider);
    final Instruction instruction = new Instruction(internalInstruction);
    final MockInstructionListener listener = new MockInstructionListener();
    instruction.addListener(listener);
    final ArrayList<IComment> comment = Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Hannes"));
    instruction.initializeComment(comment);
    assertEquals(comment, internalInstruction.getGlobalComment());
    assertEquals(comment, instruction.getComment());
    // TODO (timkornau): check if double messages are what we want here of rather not.
    // assertEquals("InitializedComment;", listener.events);
    instruction.removeListener(listener);
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) DebuggerTemplate(com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) SQLProvider(com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) IReference(com.google.security.zynamics.zylib.disassembly.IReference) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Test(org.junit.Test)

Example 93 with CComment

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

the class ViewTest method testTextNode.

@Test
public void testTextNode() throws PartialLoadException, com.google.security.zynamics.binnavi.API.disassembly.CouldntLoadDataException {
    final MockViewListener listener = new MockViewListener();
    m_view.addListener(listener);
    m_view.load();
    final ArrayList<IComment> comment = Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, " COMMENT VIEW TEST "));
    final TextNode textNode = m_view.createTextNode(comment);
    assertEquals(textNode, m_view.getGraph().getNodes().get(0));
    assertEquals(listener.events, "addedNode;");
    assertEquals(com.google.security.zynamics.binnavi.API.disassembly.GraphType.MixedGraph, m_view.getGraphType());
    assertEquals(" COMMENT VIEW TEST ", textNode.getComments().get(0).getComment());
    m_view.removeListener(listener);
}
Also used : CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) Test(org.junit.Test)

Example 94 with CComment

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

the class ViewTest method testGraph.

@Test
public void testGraph() {
    final List<INaviViewNode> nodes = new ArrayList<INaviViewNode>();
    final List<INaviEdge> edges = new ArrayList<INaviEdge>();
    final MutableDirectedGraph<INaviViewNode, INaviEdge> graph = new MutableDirectedGraph<INaviViewNode, INaviEdge>(nodes, edges);
    final int viewId = new BigInteger(31, new SecureRandom()).intValue();
    final INaviView internalView = new CView(viewId, internalModule, "My View", "My View Description", com.google.security.zynamics.zylib.disassembly.ViewType.NonNative, m_creationDate, m_modificationDate, graph, new HashSet<CTag>(), false, m_provider);
    final INaviFunction internalFunction = internalModule.getContent().getFunctionContainer().getFunctions().get(0);
    final CCodeNode codeNode = internalView.getContent().createCodeNode(internalFunction, Lists.newArrayList(new MockInstruction()));
    final CFunctionNode functionNode = internalView.getContent().createFunctionNode(internalFunction);
    @SuppressWarnings("unused") final CTextNode textNode = internalView.getContent().createTextNode(Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Foo")));
    @SuppressWarnings("unused") final CGroupNode groupNode = internalView.getContent().createGroupNode(internalView.getGraph().getNodes());
    internalView.getContent().createEdge(codeNode, functionNode, com.google.security.zynamics.zylib.gui.zygraph.edges.EdgeType.JUMP_UNCONDITIONAL);
    final TagManager tagManager = new TagManager(new MockTagManager(TagType.NODE_TAG));
    final MockViewListener listener = new MockViewListener();
    final View view = new View(module, internalView, tagManager, m_viewTagManager);
    view.addListener(listener);
    assertEquals(4, view.getGraph().getNodes().size());
    assertEquals(1, view.getGraph().getEdges().size());
    internalView.getContent().deleteNodes(internalView.getContent().getGraph().getNodes());
    assertEquals("deletedEdge;deletedNode;deletedNode;deletedNode;", listener.events);
}
Also used : ArrayList(java.util.ArrayList) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) SecureRandom(java.security.SecureRandom) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) BigInteger(java.math.BigInteger) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) MutableDirectedGraph(com.google.security.zynamics.zylib.types.graphs.MutableDirectedGraph) Test(org.junit.Test)

Example 95 with CComment

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

the class ViewTest method testCreateNode.

@Test
public void testCreateNode() throws PartialLoadException, com.google.security.zynamics.binnavi.API.disassembly.CouldntLoadDataException {
    final MockViewListener listener = new MockViewListener();
    final Function function = module.getFunctions().get(0);
    final List<Instruction> instructions = Lists.newArrayList(new Instruction(new MockInstruction()));
    m_view.load();
    final CodeNode codeNode = m_view.createCodeNode(function, instructions);
    final FunctionNode functionNode = m_view.createFunctionNode(function);
    final ArrayList<IComment> comment = Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, " COMMENT VIEW TEST "));
    final TextNode textNode = m_view.createTextNode(comment);
    assertEquals(3, m_view.getNodeCount());
    m_view.addListener(listener);
    @SuppressWarnings("unused") final CodeNode clonedCodeNode = (CodeNode) m_view.createNode(codeNode);
    @SuppressWarnings("unused") final FunctionNode clonedFunctionNode = (FunctionNode) m_view.createNode(functionNode);
    @SuppressWarnings("unused") final TextNode clonedTextNode = (TextNode) m_view.createNode(textNode);
    m_view.removeListener(listener);
}
Also used : INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) Test(org.junit.Test)

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