Search in sources :

Example 1 with CBend

use of com.google.security.zynamics.zylib.gui.zygraph.edges.CBend in project binnavi by google.

the class CViewContent method createEdge.

@Override
public CNaviViewEdge createEdge(final INaviViewNode source, final INaviViewNode target, final EdgeType edgeType) {
    Preconditions.checkNotNull(source, "IE00290: Source argument can not be null");
    Preconditions.checkNotNull(target, "IE00291: Target argument can not be null");
    Preconditions.checkNotNull(edgeType, "IE00292: Edge type argument can not be null");
    Preconditions.checkArgument(source.inSameDatabase(provider), "IE00187: Source node is not in the same database");
    Preconditions.checkArgument(target.inSameDatabase(provider), "IE00189: Target node is not in the same database");
    final CNaviViewEdge edge = new CNaviViewEdge(-1, source, target, edgeType, 0, 0, 0, 0, Color.BLACK, false, true, null, new ArrayList<CBend>(), provider);
    source.addOutgoingEdge(edge);
    target.addIncomingEdge(edge);
    edge.addListener(m_internalEdgeListener);
    graph.addEdge(edge);
    for (final INaviViewListener listener : listeners) {
        try {
            listener.addedEdge(view, edge);
        } catch (final Exception exception) {
            CUtilityFunctions.logException(exception);
        }
    }
    return edge;
}
Also used : CNaviViewEdge(com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge) CBend(com.google.security.zynamics.zylib.gui.zygraph.edges.CBend) InternalTranslationException(com.google.security.zynamics.reil.translators.InternalTranslationException)

Example 2 with CBend

use of com.google.security.zynamics.zylib.gui.zygraph.edges.CBend in project binnavi by google.

the class CViewInserter method createEdges.

/**
 * Clones the edges of the source view and inserts them into the target view.
 *
 * @param target The target view where the cloned edges are inserted.
 * @param edges The source edges that are cloned.
 * @param nodeMap Maps between the source nodes and their cloned counterparts.
 */
private static void createEdges(final INaviView target, final List<INaviEdge> edges, final Map<INaviViewNode, INaviViewNode> nodeMap) {
    for (final INaviEdge edge : edges) {
        final INaviViewNode sourceNode = nodeMap.get(edge.getSource());
        final INaviViewNode targetNode = nodeMap.get(edge.getTarget());
        final CNaviViewEdge newEdge = target.getContent().createEdge(sourceNode, targetNode, edge.getType());
        newEdge.setColor(edge.getColor());
        newEdge.setX1(edge.getX1());
        newEdge.setY1(edge.getY1());
        newEdge.setX2(edge.getX2());
        newEdge.setY2(edge.getY2());
        for (final CBend bend : edge.getBends()) {
            newEdge.addBend(bend.getX(), bend.getY());
        }
    }
}
Also used : CNaviViewEdge(com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge) CBend(com.google.security.zynamics.zylib.gui.zygraph.edges.CBend) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge)

Example 3 with CBend

use of com.google.security.zynamics.zylib.gui.zygraph.edges.CBend in project binnavi by google.

the class CUnInlinerTest method testUninlineSingleBlock.

@Test
public void testUninlineSingleBlock() {
    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 upperNode = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    final CCodeNode inlinedNode = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction2, new HashSet<CTag>(), m_provider);
    final CCodeNode lowerNode = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    final CTextNode textNode = new CTextNode(0, 0, 0, 0, 0, Color.RED, false, true, new HashSet<CTag>(), null, m_provider);
    upperNode.addInstruction(mi1, null);
    inlinedNode.addInstruction(mi2, null);
    lowerNode.addInstruction(mi3, null);
    nodes.add(upperNode);
    nodes.add(inlinedNode);
    nodes.add(textNode);
    nodes.add(lowerNode);
    final CNaviViewEdge enteringEdge = new CNaviViewEdge(0, 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(0, inlinedNode, lowerNode, EdgeType.LEAVE_INLINED_FUNCTION, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    final CNaviViewEdge textEdge = new CNaviViewEdge(0, textNode, inlinedNode, EdgeType.TEXTNODE_EDGE, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    edges.add(enteringEdge);
    edges.add(leavingEdge);
    edges.add(textEdge);
    connect(upperNode, inlinedNode, enteringEdge);
    connect(inlinedNode, lowerNode, leavingEdge);
    connect(textNode, inlinedNode, textEdge);
    final MockView view = new MockView(nodes, edges, m_provider);
    CUnInliner.unInline(view, inlinedNode);
    assertEquals(1, view.getNodeCount());
    assertEquals(0, view.getEdgeCount());
    final INaviCodeNode cnode = (INaviCodeNode) view.getGraph().getNodes().get(0);
    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) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Test(org.junit.Test)

Example 4 with CBend

use of com.google.security.zynamics.zylib.gui.zygraph.edges.CBend 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 5 with CBend

use of com.google.security.zynamics.zylib.gui.zygraph.edges.CBend 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)

Aggregations

CBend (com.google.security.zynamics.zylib.gui.zygraph.edges.CBend)11 CNaviViewEdge (com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge)7 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)7 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)6 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)5 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)4 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)4 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)4 MockFunction (com.google.security.zynamics.binnavi.disassembly.MockFunction)4 MockInstruction (com.google.security.zynamics.binnavi.disassembly.MockInstruction)4 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)4 FilledList (com.google.security.zynamics.zylib.types.lists.FilledList)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)2 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2 CConnection (com.google.security.zynamics.binnavi.Database.CConnection)1 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)1 CComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment)1