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());
}
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);
}
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);
}
}
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++;
}
}
}
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();
}
}
Aggregations