Search in sources :

Example 41 with INaviViewNode

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

the class PostgreSQLNodeSaver method saveNodes.

/**
   * Saves the nodes to the nodes table. As a side effect, this function also fills index lists that
   * store the indices into the nodes list for all node types. TODO: This method should probably be
   * split into two methods.
   *
   * @param provider Provides the connection to the database.
   * @param newViewId ID of the new view that is being saved.
   * @param nodes The nodes to save.
   * @param functionNodeIndices Index into the nodes list that identifies the function nodes.
   * @param codeNodeIndices Index into the nodes list that identifies the code nodes.
   * @param textNodeIndices Index into the nodes list that identifies the text nodes.
   * @param groupNodeIndices Index into the nodes list that identifies the group nodes.
   * @param groupNodeMap Maps between node IDs and group node objects.
   * @return The ID of the first node saved to the database.
   * @throws SQLException Thrown if saving the nodes failed.
   */
private static int saveNodes(final AbstractSQLProvider provider, final int newViewId, final List<INaviViewNode> nodes, final List<Integer> functionNodeIndices, final List<Integer> codeNodeIndices, final List<Integer> textNodeIndices, final List<Integer> groupNodeIndices, final BiMap<Integer, INaviGroupNode> groupNodeMap) throws SQLException {
    final String query = "INSERT INTO " + CTableNames.NODES_TABLE + "( view_id, parent_id, type, x, y, width, height, color, bordercolor, " + " selected, visible) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    final PreparedStatement preparedStatement = provider.getConnection().getConnection().prepareStatement(query, java.sql.Statement.RETURN_GENERATED_KEYS);
    int counter = 0;
    for (final INaviViewNode node : nodes) {
        String nodeType = null;
        if (node instanceof CCodeNode) {
            nodeType = CODE;
            codeNodeIndices.add(counter);
        } else if (node instanceof CFunctionNode) {
            nodeType = FUNCTION;
            functionNodeIndices.add(counter);
        } else if (node instanceof INaviGroupNode) {
            nodeType = GROUP;
            groupNodeIndices.add(counter);
            groupNodeMap.put(counter, (INaviGroupNode) node);
        } else if (node instanceof CTextNode) {
            nodeType = TEXT;
            textNodeIndices.add(counter);
        }
        counter++;
        preparedStatement.setInt(1, newViewId);
        preparedStatement.setNull(2, Types.INTEGER);
        preparedStatement.setObject(3, nodeType, Types.OTHER);
        preparedStatement.setDouble(4, node.getX());
        preparedStatement.setDouble(5, node.getY());
        preparedStatement.setDouble(6, node.getWidth());
        preparedStatement.setDouble(7, node.getHeight());
        preparedStatement.setInt(8, node.getColor().getRGB());
        preparedStatement.setInt(9, node.getBorderColor().getRGB());
        preparedStatement.setBoolean(10, node.isSelected());
        preparedStatement.setBoolean(11, node.isVisible());
        preparedStatement.addBatch();
    }
    preparedStatement.executeBatch();
    final ResultSet resultSet = preparedStatement.getGeneratedKeys();
    int lastId = 0;
    try {
        while (resultSet.next()) {
            if (resultSet.isFirst()) {
                lastId = resultSet.getInt(1);
                break;
            }
        }
    } finally {
        preparedStatement.close();
        resultSet.close();
    }
    return lastId;
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) ResultSet(java.sql.ResultSet) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) PreparedStatement(java.sql.PreparedStatement) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode)

Example 42 with INaviViewNode

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

the class PostgreSQLNodeSaver method updateNodeIds.

/**
   * Updates the node IDs of the nodes that were saved to the database.
   *
   * @param nodes The nodes whose IDs are updated.
   * @param firstNode The new ID of the first node.
   */
protected static void updateNodeIds(final List<INaviViewNode> nodes, final int firstNode) {
    int newIdCounter = firstNode;
    for (final INaviViewNode node : nodes) {
        node.setId(newIdCounter);
        newIdCounter++;
    }
}
Also used : INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode)

Example 43 with INaviViewNode

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

the class PostgreSQLNodeLoader method loadNodes.

/**
   * Loads the view nodes of a view.
   * 
   * @param provider The connection to the database.
   * @param view The view whose nodes are loaded.
   * @param modules All modules that belong to the database.
   * @param nodeTagManager Tag manager responsible for tagging the nodes of the view.
   * 
   * @return The loaded nodes.
   * 
   * @throws SQLException Thrown of loading the nodes failed.
   * @throws CPartialLoadException Thrown if loading the nodes failed because a necessary module was
   *         not loaded.
   * @throws CouldntLoadDataException
   */
public static List<INaviViewNode> loadNodes(final AbstractSQLProvider provider, final INaviView view, final List<INaviModule> modules, final CTagManager nodeTagManager) throws SQLException, CPartialLoadException, CouldntLoadDataException {
    final List<INaviViewNode> nodes = new ArrayList<INaviViewNode>();
    PostgreSQLGroupNodeLoader.load(provider, view, nodes);
    PostgreSQLFunctionNodeLoader.load(provider, view, nodes);
    PostgreSQLCodeNodeLoader.load(provider, view, nodes, modules);
    PostgreSQLTextNodeLoader.load(provider, view, nodes);
    // It is very, very important to return the nodes in the order of their IDs
    // because when a graph is Saved As, the order of the loaded nodes is compared
    // to the order of the nodes before the graph was saved.
    //
    // Furthermore this must happen before group nodes are set up.
    // TODO: sp has said this sometime in the past without any reasoning why
    // therefore this has to be checked and understood otherwise this code is just
    // burning cycles.
    Collections.sort(nodes, new Comparator<INaviViewNode>() {

        @Override
        public int compare(final INaviViewNode lhs, final INaviViewNode rhs) {
            return lhs.getId() - rhs.getId();
        }
    });
    final CConnection connection = provider.getConnection();
    PostgreSQLGroupNodeLoader.setupGroupNodes(connection, view, nodes);
    loadNodeTags(connection, nodes, nodeTagManager);
    return nodes;
}
Also used : CConnection(com.google.security.zynamics.binnavi.Database.CConnection) ArrayList(java.util.ArrayList) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode)

Example 44 with INaviViewNode

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

the class CTagTreeCellRenderer method renderTaggedGraphNodeNode.

/**
   * Renders nodes that represent individual graph nodes.
   *
   * @param node The node to render.
   */
private void renderTaggedGraphNodeNode(final CTaggedGraphNodeNode node) {
    final INaviViewNode rawNode = node.getGraphNode().getRawNode();
    if (rawNode.isTagged() && rawNode.isSelected()) {
        setForeground(COLOR_TAGGED_SELECTED_ALL);
    } else if (rawNode.isTagged() && !rawNode.isVisible()) {
        setForeground(COLOR_TAGGED_INVISIBLE);
    }
    setToolTipText(buildToolTip(node.getGraphNode()));
}
Also used : INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode)

Example 45 with INaviViewNode

use of com.google.security.zynamics.binnavi.disassembly.INaviViewNode 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)

Aggregations

INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)73 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)22 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)21 Test (org.junit.Test)16 INaviGroupNode (com.google.security.zynamics.binnavi.disassembly.INaviGroupNode)14 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)13 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)12 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)12 INaviFunctionNode (com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode)11 ArrayList (java.util.ArrayList)10 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)9 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)9 CNaviViewEdge (com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge)9 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)9 CGroupNode (com.google.security.zynamics.binnavi.disassembly.CGroupNode)8 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)8 NaviNode (com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode)8 INaviTextNode (com.google.security.zynamics.binnavi.disassembly.INaviTextNode)7 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)7 CView (com.google.security.zynamics.binnavi.disassembly.views.CView)7