Search in sources :

Example 6 with INaviViewNode

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

the class ZyGraphTest method testDeleteNode.

@Test
public void testDeleteNode() {
    assertEquals(7, m_graph.visibleNodeCount());
    assertEquals(89, NodeFunctions.getInvisibleNodes(m_graph).size());
    assertEquals(96, m_graph.getRawView().getNodeCount());
    final List<NaviNode> nodes = GraphHelpers.getNodes(m_graph);
    final INaviViewNode oldChild = m_view.getGraph().getNodes().get(1);
    assertEquals(1, searchNode(nodes, oldChild).getParents().size());
    m_view.getContent().deleteNode(m_view.getGraph().getNodes().get(0));
    assertEquals(6, m_graph.visibleNodeCount());
    assertEquals(89, NodeFunctions.getInvisibleNodes(m_graph).size());
    assertEquals(95, m_graph.getRawView().getNodeCount());
    assertEquals(0, searchNode(nodes, oldChild).getParents().size());
    m_view.getContent().deleteNodes(Lists.newArrayList(m_view.getGraph().getNodes().get(0), m_view.getGraph().getNodes().get(1)));
    assertEquals(4, m_graph.visibleNodeCount());
    assertEquals(89, NodeFunctions.getInvisibleNodes(m_graph).size());
    assertEquals(93, m_graph.getRawView().getNodeCount());
}
Also used : NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) Test(org.junit.Test)

Example 7 with INaviViewNode

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

the class PostgreSQLEdgeLoader method loadEdges.

/**
   * Loads the edges of a view.
   *
   *  The view and all nodes from the node list must be stored in the database connected to by the
   * provider argument.
   *
   * @param provider The SQL provider that provides the database connection.
   * @param view The view from where the edges are loaded.
   * @param nodes The nodes of the view which must be loaded before.
   *
   * @return The edges of the view.
   *
   * @throws CouldntLoadDataException
   */
public static List<INaviEdge> loadEdges(final AbstractSQLProvider provider, final INaviView view, final Collection<INaviViewNode> nodes) throws CouldntLoadDataException {
    final Map<Integer, INaviViewNode> nodeLookup = new HashMap<Integer, INaviViewNode>();
    final List<Integer> nodeIdList = new ArrayList<Integer>();
    for (final INaviViewNode viewNode : nodes) {
        nodeLookup.put(viewNode.getId(), viewNode);
        nodeIdList.add(viewNode.getId());
    }
    final Map<Integer, ArrayList<IComment>> edgeToGlobalCommentMap = loadGlobalEdgeComments(provider, view.getConfiguration().getId());
    return loadEdges(provider, view, nodeLookup, edgeToGlobalCommentMap);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode)

Example 8 with INaviViewNode

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

the class PostgreSQLEdgeLoader method initializeGlobalComment.

/**
   * Initializes the global comment for an edge.
   *
   * @param edge The edge whose global comment is initialized.
   * @param globalComments The global comment to set.
   */
private static void initializeGlobalComment(final CNaviViewEdge edge, final ArrayList<IComment> globalComments, final SQLProvider provider) {
    final INaviViewNode source = edge.getSource();
    final INaviViewNode target = edge.getTarget();
    if ((source instanceof INaviCodeNode) && (target instanceof IAddressNode)) {
        CommentManager.get(provider).initializeGlobalEdgeComment(edge, globalComments);
    } else if ((source instanceof INaviFunctionNode) && (target instanceof IAddressNode)) {
        CommentManager.get(provider).initializeGlobalEdgeComment(edge, globalComments);
    }
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) IAddressNode(com.google.security.zynamics.binnavi.disassembly.IAddressNode)

Example 9 with INaviViewNode

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

the class PostgreSQLGroupNodeLoader method setupGroupNodes.

/**
   * Sets up the elements of the group nodes of a view.
   * 
   * @param connection The connection to the database.
   * @param view The view whose group nodes are set up.
   * @param nodes The nodes of the view.
   * 
   * @throws SQLException Thrown if setting up the group nodes fails.
   */
public static void setupGroupNodes(final CConnection connection, final INaviView view, final List<INaviViewNode> nodes) throws SQLException {
    final String query = "SELECT id, parent_id FROM " + CTableNames.NODES_TABLE + " WHERE view_id = " + view.getConfiguration().getId() + " ORDER BY id";
    int counter = 0;
    int firstId = -1;
    try (ResultSet resultSet = connection.executeQuery(query, true)) {
        while (resultSet.next()) {
            if (firstId == -1) {
                firstId = resultSet.getInt("id");
            }
            final int parentId = resultSet.getInt("parent_id");
            if (!resultSet.wasNull()) {
                final INaviViewNode node = nodes.get(counter);
                final INaviViewNode parent = nodes.get(parentId - firstId);
                ((CGroupNode) parent).addElement(node);
            }
            counter++;
        }
    }
}
Also used : ResultSet(java.sql.ResultSet) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode)

Example 10 with INaviViewNode

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

the class PostgreSQLNodeLoader method loadNodeTags.

/**
   * Loads the node tags of a list of nodes.
   * 
   * @param connection The connection to the database.
   * @param nodes The nodes whose tags are loaded.
   * @param nodeTagManager Manages all node tags of the database.
   * 
   * @throws SQLException Thrown if loading the node tags failed.
   */
private static void loadNodeTags(final CConnection connection, final List<INaviViewNode> nodes, final CTagManager nodeTagManager) throws SQLException {
    final HashMap<Integer, INaviViewNode> idNodeMap = new HashMap<Integer, INaviViewNode>();
    final HashMap<Integer, CTag> idTagMap = new HashMap<Integer, CTag>();
    final StringBuffer range = new StringBuffer();
    boolean isFirst = true;
    for (final INaviViewNode node : nodes) {
        range.append(isFirst ? "" : ",");
        range.append(node.getId());
        isFirst = false;
        idNodeMap.put(node.getId(), node);
    }
    if (isFirst) {
        return;
    }
    final String query = String.format("SELECT node_id, tag_id FROM %s WHERE node_id IN (%s)", CTableNames.TAGGED_NODES_TABLE, range.toString());
    final ResultSet resultSet = connection.executeQuery(query, true);
    try {
        final Set<Integer> tagIds = new HashSet<Integer>();
        while (resultSet.next()) {
            tagIds.add(resultSet.getInt("tag_id"));
        }
        final Collection<CTag> tags = CTagHelpers.findTags(nodeTagManager.getRootTag(), tagIds);
        for (final CTag tag : tags) {
            idTagMap.put(tag.getId(), tag);
        }
        resultSet.beforeFirst();
        while (resultSet.next()) {
            final INaviViewNode node = idNodeMap.get(resultSet.getInt("node_id"));
            final CTag tag = idTagMap.get(resultSet.getInt("tag_id"));
            ((CNaviViewNode) node).tagNodeSilent(tag);
        }
    } finally {
        resultSet.close();
    }
}
Also used : HashMap(java.util.HashMap) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CNaviViewNode(com.google.security.zynamics.binnavi.disassembly.CNaviViewNode) ResultSet(java.sql.ResultSet) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) HashSet(java.util.HashSet)

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