Search in sources :

Example 36 with INaviEdge

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

the class PostgreSQLNotificationParserTest method testGlobalEdgeCommentParsingDeleteLastComment.

@Test
public void testGlobalEdgeCommentParsingDeleteLastComment() {
    new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
    MockPGNotification notification = new MockPGNotification("comment_changes", "bn_global_edge_comments DELETE 1 1 4608 4614");
    Collection<CommentNotification> result = PostgreSQLCommentNotificationParser.processEdgeGlobalCommentNotification(notification, provider);
    assertEquals(1, result.size());
    final EdgeCommentNotificationContainer container = (EdgeCommentNotificationContainer) Iterables.getFirst(result, null);
    final INaviEdge edge = container.getEdge();
    assertEquals(1111, edge.getId());
    assertEquals(CommentOperation.DELETE, container.getOperation());
    assertNull(container.getCommentId());
    assertEquals(CommentScope.GLOBAL, container.getScope());
}
Also used : EdgeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.EdgeCommentNotificationContainer) CommentNotification(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) Test(org.junit.Test)

Example 37 with INaviEdge

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

the class PostgreSQLNotificationParserTest method testLocalEdgeCommentParsingAppend.

@Test
public void testLocalEdgeCommentParsingAppend() {
    new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
    MockPGNotification notification = new MockPGNotification("comment_changes", "bn_edges UPDATE 4444 3333");
    final CommentNotification result = PostgreSQLCommentNotificationParser.processEdgeLocalCommentNotification(notification, provider);
    assertNotNull(result);
    final EdgeCommentNotificationContainer container = (EdgeCommentNotificationContainer) result;
    final INaviEdge edge = container.getEdge();
    assertEquals(4444, edge.getId());
    assertEquals(CommentOperation.APPEND, container.getOperation());
    assertEquals(new Integer(3333), container.getCommentId());
    assertEquals(CommentScope.LOCAL, container.getScope());
}
Also used : EdgeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.EdgeCommentNotificationContainer) CommentNotification(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) Test(org.junit.Test)

Example 38 with INaviEdge

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

the class PostgreSQLNotificationParserTest method testGlobalEdgeCommentParsingAppendFirstComment.

@Test
public void testGlobalEdgeCommentParsingAppendFirstComment() {
    new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
    MockPGNotification notification = new MockPGNotification("comment_changes", "bn_global_edge_comments INSERT 1 1 4608 4614 3333");
    final Collection<CommentNotification> result = PostgreSQLCommentNotificationParser.processEdgeGlobalCommentNotification(notification, provider);
    assertEquals(1, result.size());
    final EdgeCommentNotificationContainer container = (EdgeCommentNotificationContainer) Iterables.getFirst(result, null);
    final INaviEdge edge = container.getEdge();
    assertEquals(1111, edge.getId());
    assertEquals(CommentOperation.APPEND, container.getOperation());
    assertEquals(new Integer(3333), container.getCommentId());
    assertEquals(CommentScope.GLOBAL, container.getScope());
}
Also used : EdgeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.EdgeCommentNotificationContainer) CommentNotification(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) Test(org.junit.Test)

Example 39 with INaviEdge

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

the class View method convertData.

/**
   * Converts internal view data to API view data.
   */
private void convertData() {
    final IDirectedGraph<INaviViewNode, INaviEdge> graph = naviView.getGraph();
    final List<ViewNode> blocks = new ArrayList<ViewNode>();
    final List<ViewEdge> edges = new ArrayList<ViewEdge>();
    for (final INaviViewNode block : graph.getNodes()) {
        // ESCA-JAVA0177:
        final ViewNode newBlock = convert(block);
        cachedNodes.put(block, newBlock);
        blocks.add(newBlock);
    }
    for (final INaviViewNode block : graph.getNodes()) {
        if (block.getParentGroup() != null) {
            ((GroupNode) cachedNodes.get(block.getParentGroup())).addNode(cachedNodes.get(block));
        }
    }
    for (final INaviEdge edge : graph.getEdges()) {
        final ViewNode source = cachedNodes.get(edge.getSource());
        final ViewNode target = cachedNodes.get(edge.getTarget());
        final ViewEdge viewEdge = new ViewEdge(edge, source, target);
        edges.add(viewEdge);
        cachedEdges.put(edge, viewEdge);
    }
    viewGraph = new ViewGraph(blocks, edges);
}
Also used : ArrayList(java.util.ArrayList) CNaviViewEdge(com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge) IViewEdge(com.google.security.zynamics.zylib.gui.zygraph.edges.IViewEdge) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) IViewNode(com.google.security.zynamics.zylib.gui.zygraph.nodes.IViewNode) CNaviViewNode(com.google.security.zynamics.binnavi.disassembly.CNaviViewNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge)

Example 40 with INaviEdge

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

the class CNodeFunctions method splitAfter.

/**
   * Splits a node.
   * 
   * @param view View the node belongs to.
   * @param originalNode Node to split.
   * @param instruction Instruction after which the node is split.
   */
public static void splitAfter(final INaviView view, final INaviCodeNode originalNode, final INaviInstruction instruction) {
    final Iterable<INaviInstruction> oldInstructions = originalNode.getInstructions();
    if (instruction == Iterables.getLast(oldInstructions)) {
        return;
    }
    // Step I: Find out what instructions belong to the new upper block and what
    // instructions belong to the new lower block.
    final List<INaviInstruction> upperInstructions = new ArrayList<INaviInstruction>();
    final List<INaviInstruction> lowerInstructions = new ArrayList<INaviInstruction>();
    List<INaviInstruction> currentInstructions = upperInstructions;
    for (final INaviInstruction oldInstruction : oldInstructions) {
        currentInstructions.add(oldInstruction);
        if (oldInstruction == instruction) {
            currentInstructions = lowerInstructions;
        }
    }
    // Step II: Create the two new code nodes.
    INaviFunction parentFunction = null;
    try {
        parentFunction = originalNode.getParentFunction();
    } catch (final MaybeNullException e) {
    // No parent function
    }
    final INaviCodeNode newNode1 = view.getContent().createCodeNode(parentFunction, upperInstructions);
    final INaviCodeNode newNode2 = view.getContent().createCodeNode(parentFunction, lowerInstructions);
    newNode1.setColor(originalNode.getColor());
    newNode1.setBorderColor(originalNode.getBorderColor());
    newNode2.setColor(originalNode.getColor());
    // Step III: Transfer node comments and instruction comments from the old node
    // to the new nodes.
    transferLocalCodeNodeComments(originalNode, newNode1, newNode2);
    // Step IV: Connect the two new nodes.
    view.getContent().createEdge(newNode1, newNode2, EdgeType.JUMP_UNCONDITIONAL);
    for (final INaviEdge incomingEdge : originalNode.getIncomingEdges()) {
        view.getContent().createEdge(incomingEdge.getSource(), newNode1, incomingEdge.getType());
    }
    for (final INaviEdge outgoingEdge : originalNode.getOutgoingEdges()) {
        view.getContent().createEdge(newNode2, outgoingEdge.getTarget(), outgoingEdge.getType());
    }
    // Step VI: Get rid of the old node.
    view.getContent().deleteNode(originalNode);
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) ArrayList(java.util.ArrayList) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Aggregations

INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)47 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)21 Test (org.junit.Test)17 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)9 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)9 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)8 EdgeCommentNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.EdgeCommentNotificationContainer)7 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)7 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)7 CNaviViewEdge (com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge)7 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)7 CBend (com.google.security.zynamics.zylib.gui.zygraph.edges.CBend)7 CommentNotification (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification)6 MockInstruction (com.google.security.zynamics.binnavi.disassembly.MockInstruction)6 SQLException (java.sql.SQLException)6 ArrayList (java.util.ArrayList)6 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)5 MockFunction (com.google.security.zynamics.binnavi.disassembly.MockFunction)5 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)5 FilledList (com.google.security.zynamics.zylib.types.lists.FilledList)5