Search in sources :

Example 6 with CNaviViewEdge

use of com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge in project binnavi by google.

the class CUnInlinerTest method testUninlineSingleBlockConnectNeighbors.

@Test
public void testUninlineSingleBlockConnectNeighbors() {
    final List<INaviViewNode> nodes = new FilledList<INaviViewNode>();
    final List<INaviEdge> edges = new FilledList<INaviEdge>();
    final INaviFunction mockFunction = new MockFunction(m_provider);
    final INaviFunction mockFunction2 = new MockFunction(m_provider);
    final MockInstruction mi1 = new MockInstruction(0x123);
    final MockInstruction mi2 = new MockInstruction(0x124);
    final MockInstruction mi3 = new MockInstruction(0x125);
    final CCodeNode parentNode = new CCodeNode(1, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    final CCodeNode upperNode = new CCodeNode(2, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    final CCodeNode inlinedNode = new CCodeNode(3, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction2, new HashSet<CTag>(), m_provider);
    final CCodeNode lowerNode = new CCodeNode(4, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    final CCodeNode childNode1 = new CCodeNode(5, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    final CCodeNode childNode2 = new CCodeNode(6, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    upperNode.addInstruction(mi1, null);
    inlinedNode.addInstruction(mi2, null);
    lowerNode.addInstruction(mi3, null);
    nodes.add(parentNode);
    nodes.add(upperNode);
    nodes.add(inlinedNode);
    nodes.add(lowerNode);
    nodes.add(childNode1);
    nodes.add(childNode2);
    final CNaviViewEdge parentEdge = new CNaviViewEdge(0, parentNode, upperNode, EdgeType.JUMP_UNCONDITIONAL, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    final CNaviViewEdge enteringEdge = new CNaviViewEdge(1, upperNode, inlinedNode, EdgeType.ENTER_INLINED_FUNCTION, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    final CNaviViewEdge leavingEdge = new CNaviViewEdge(2, inlinedNode, lowerNode, EdgeType.LEAVE_INLINED_FUNCTION, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    final CNaviViewEdge childEdge1 = new CNaviViewEdge(3, lowerNode, childNode1, EdgeType.JUMP_CONDITIONAL_FALSE, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    final CNaviViewEdge childEdge2 = new CNaviViewEdge(4, lowerNode, childNode2, EdgeType.JUMP_CONDITIONAL_TRUE, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    edges.add(parentEdge);
    edges.add(enteringEdge);
    edges.add(leavingEdge);
    edges.add(childEdge1);
    edges.add(childEdge2);
    connect(parentNode, upperNode, parentEdge);
    connect(upperNode, inlinedNode, enteringEdge);
    connect(inlinedNode, lowerNode, leavingEdge);
    connect(lowerNode, childNode1, childEdge1);
    connect(lowerNode, childNode2, childEdge2);
    final MockView view = new MockView(nodes, edges, m_provider);
    CUnInliner.unInline(view, inlinedNode);
    assertEquals(4, view.getNodeCount());
    assertEquals(3, view.getEdgeCount());
    assertEquals(EdgeType.JUMP_UNCONDITIONAL, view.getGraph().getEdges().get(0).getType());
    assertEquals(EdgeType.JUMP_CONDITIONAL_FALSE, view.getGraph().getEdges().get(1).getType());
    assertEquals(EdgeType.JUMP_CONDITIONAL_TRUE, view.getGraph().getEdges().get(2).getType());
    final INaviCodeNode cnode = (INaviCodeNode) view.getGraph().getNodes().get(3);
    assertEquals(2, Iterables.size(cnode.getInstructions()));
    assertEquals(mi1.toString(), Iterables.get(cnode.getInstructions(), 0).toString());
    assertEquals(mi3.toString(), Iterables.get(cnode.getInstructions(), 1).toString());
}
Also used : MockFunction(com.google.security.zynamics.binnavi.disassembly.MockFunction) FilledList(com.google.security.zynamics.zylib.types.lists.FilledList) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) CNaviViewEdge(com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) CBend(com.google.security.zynamics.zylib.gui.zygraph.edges.CBend) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Test(org.junit.Test)

Example 7 with CNaviViewEdge

use of com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge 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 8 with CNaviViewEdge

use of com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge in project binnavi by google.

the class ZyGraphTest method testAddedEdgeCheckColor.

@Test
public void testAddedEdgeCheckColor() {
    final Pair<CNaviViewEdge, com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge> p = createEdgeForAddedEdgeTests();
    final CNaviViewEdge edge = p.first();
    final com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge cnn = p.second();
    assertEquals(edge.getColor(), cnn.getRealizerLineColor());
    edge.setColor(Color.GREEN);
    assertEquals(Color.GREEN, edge.getColor());
    assertEquals(edge.getColor(), cnn.getRealizerLineColor());
}
Also used : CNaviViewEdge(com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge) Test(org.junit.Test)

Example 9 with CNaviViewEdge

use of com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge in project binnavi by google.

the class PostgreSQLGlobalEdgeCommentTests method appendGlobalEdgeComment4.

@Test
public void appendGlobalEdgeComment4() throws CouldntLoadDataException, LoadCancelledException, CouldntSaveDataException, CPartialLoadException {
    final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    final List<IComment> storedComments = edge.getGlobalComment() == null ? new ArrayList<IComment>() : edge.getGlobalComment();
    final IComment lastComment = storedComments.isEmpty() ? null : Iterables.getLast(storedComments);
    final String firstCommentString = " PASS GLOBAL EDGE COMMENT WITHOUT PARENT ID ";
    final int firstCommentId = getProvider().appendGlobalEdgeComment(edge, firstCommentString, user.getUserId());
    final IComment firstComment = new CComment(firstCommentId, user, lastComment, firstCommentString);
    final String secondCommentString = " PASS GLOBAL EDGE COMMENT WITH PARENT ID ";
    final int secondCommentId = getProvider().appendGlobalEdgeComment(edge, secondCommentString, user.getUserId());
    final IComment secondComment = new CComment(secondCommentId, user, firstComment, secondCommentString);
    final ArrayList<IComment> commentsFromDatabase = getProvider().loadCommentById(secondCommentId);
    assertNotNull(commentsFromDatabase);
    assertEquals(storedComments.size() + 2, commentsFromDatabase.size());
    assertTrue(commentsFromDatabase.contains(firstComment));
    assertTrue(commentsFromDatabase.contains(secondComment));
    final CNaviViewEdge callgraphEdge = (CNaviViewEdge) loadCallGraphEdge(getKernel32Module());
    getProvider().appendGlobalEdgeComment(callgraphEdge, " PASS GLOBAL CALLGRAPH EDGE COMMENT WITHOUT PARENT ID ", user.getUserId());
}
Also used : CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) CNaviViewEdge(com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge) 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 10 with CNaviViewEdge

use of com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge in project binnavi by google.

the class View method createEdge.

// ! Creates a new edge.
/**
   * Creates an edge in the view.
   *
   * @param source The source node of the edge.
   * @param target The target node of the edge.
   * @param edgeType The edge type of the edge.
   *
   * @return The created edge.
   */
public ViewEdge createEdge(final ViewNode source, final ViewNode target, final EdgeType edgeType) {
    Preconditions.checkNotNull(source, "Error: Source argument can not be null");
    Preconditions.checkNotNull(target, "Error: Target argument can not be null");
    Preconditions.checkNotNull(edgeType, "Error: Edge type argument can not be null");
    final CNaviViewEdge newEdge = naviView.getContent().createEdge(source.getNative(), target.getNative(), edgeType.getNative());
    return cachedEdges.get(newEdge);
}
Also used : CNaviViewEdge(com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge)

Aggregations

CNaviViewEdge (com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge)18 Test (org.junit.Test)11 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)8 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)7 CBend (com.google.security.zynamics.zylib.gui.zygraph.edges.CBend)7 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)6 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)6 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)5 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)5 MockFunction (com.google.security.zynamics.binnavi.disassembly.MockFunction)5 MockInstruction (com.google.security.zynamics.binnavi.disassembly.MockInstruction)5 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)4 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)4 FilledList (com.google.security.zynamics.zylib.types.lists.FilledList)4 CComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment)3 IUser (com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser)3 CTextNode (com.google.security.zynamics.binnavi.disassembly.CTextNode)3 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)3 ArrayList (java.util.ArrayList)3 UniqueTestUserGenerator (com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator)2