Search in sources :

Example 26 with INaviEdge

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

the class PostgreSQLEdgeSaver method writeEdges.

/**
   * Writes the edges of a view to the database.
   * 
   * @param provider The SQL provider that provides the connection.
   * @param edges The edges to write to the database.
   * 
   * @throws SQLException Thrown if the edges could not be saved.
   */
public static void writeEdges(final SQLProvider provider, final List<INaviEdge> edges) throws SQLException {
    Preconditions.checkNotNull(provider, "IE02253: Provider argument can not be null");
    Preconditions.checkNotNull(edges, "IE02254: Edges argument can not be null");
    for (final INaviEdge edge : edges) {
        Preconditions.checkArgument(edge.inSameDatabase(provider), "IE02255: Edge list contains an edge that is not part of this database");
    }
    if (edges.isEmpty()) {
        return;
    }
    final CConnection connection = provider.getConnection();
    fillEdgesTable(connection, edges);
    fillEdgepathsTable(connection, edges);
}
Also used : CConnection(com.google.security.zynamics.binnavi.Database.CConnection) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge)

Example 27 with INaviEdge

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

the class PostgreSQLEdgeSaver method fillEdgepathsTable.

/**
   * Writes the data from the edge objects to the edge paths table.
   * 
   * @param connection Connection to a database.
   * @param edges The edges to write.
   * 
   * @throws SQLException Thrown if storing the edge paths failed.
   */
protected static void fillEdgepathsTable(final CConnection connection, final List<INaviEdge> edges) throws SQLException {
    final String query = "INSERT INTO " + CTableNames.EDGE_PATHS_TABLE + "(edge_id, position, x, y) VALUES (?, ?, ?, ?)";
    final PreparedStatement preparedStatement = connection.getConnection().prepareStatement(query);
    try {
        for (final INaviEdge edge : edges) {
            for (final CBend bend : edge.getBends()) {
                preparedStatement.setInt(1, edge.getId());
                preparedStatement.setInt(2, edge.getBends().indexOf(bend));
                preparedStatement.setDouble(3, bend.getX());
                preparedStatement.setDouble(4, bend.getY());
                preparedStatement.addBatch();
            }
        }
        preparedStatement.executeBatch();
    } catch (final SQLException exception) {
        CUtilityFunctions.logException(exception);
        CUtilityFunctions.logException(exception.getNextException());
    } finally {
        preparedStatement.close();
    }
}
Also used : CBend(com.google.security.zynamics.zylib.gui.zygraph.edges.CBend) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge)

Example 28 with INaviEdge

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

the class CNodeDeleter method connectParentsWithChildren.

/**
   * Creates edges to connect the parents of a node with its children.
   *
   * @param view The view where the edges are created.
   * @param node The node at the center of edge creation.
   */
private static void connectParentsWithChildren(final INaviView view, final INaviViewNode node) {
    final List<INaviEdge> incomingEdges = node.getIncomingEdges();
    final List<? extends INaviViewNode> children = node.getChildren();
    for (final INaviEdge incomingEdge : incomingEdges) {
        if (incomingEdge.getSource() == node) {
            continue;
        }
        for (final INaviViewNode child : children) {
            if (child == node) {
                continue;
            }
            // Avoid duplicate edges
            if (!hasEdge(incomingEdge.getSource(), child, incomingEdge.getType())) {
                view.getContent().createEdge(incomingEdge.getSource(), child, incomingEdge.getType());
            }
        }
    }
}
Also used : INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge)

Example 29 with INaviEdge

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

the class CUnInlinerTest method testOneBlock.

@Test
public void testOneBlock() {
    final List<INaviViewNode> nodes = new FilledList<INaviViewNode>();
    final List<INaviEdge> edges = new FilledList<INaviEdge>();
    final INaviFunction mockFunction = new MockFunction();
    final CCodeNode node = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    nodes.add(node);
    final MockView view = new MockView(nodes, edges, m_provider);
    CUnInliner.unInline(view, node);
}
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) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Test(org.junit.Test)

Example 30 with INaviEdge

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

the class CUnInlinerTest method testUninlineSingleBlockNested.

@Test
public void testUninlineSingleBlockNested() {
    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 childNode = new CCodeNode(5, 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(childNode);
    final CNaviViewEdge parentEdge = new CNaviViewEdge(0, parentNode, upperNode, EdgeType.ENTER_INLINED_FUNCTION, 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, childNode, EdgeType.LEAVE_INLINED_FUNCTION, 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);
    connect(parentNode, upperNode, parentEdge);
    connect(upperNode, inlinedNode, enteringEdge);
    connect(inlinedNode, lowerNode, leavingEdge);
    connect(lowerNode, childNode, childEdge1);
    final MockView view = new MockView(nodes, edges, m_provider);
    CUnInliner.unInline(view, inlinedNode);
    assertEquals(3, view.getNodeCount());
    assertEquals(2, view.getEdgeCount());
    assertEquals(EdgeType.ENTER_INLINED_FUNCTION, view.getGraph().getEdges().get(0).getType());
    assertEquals(EdgeType.LEAVE_INLINED_FUNCTION, view.getGraph().getEdges().get(1).getType());
    final INaviCodeNode cnode = (INaviCodeNode) view.getGraph().getNodes().get(2);
    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)

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