use of com.google.security.zynamics.binnavi.disassembly.INaviViewNode in project binnavi by google.
the class ZyGraphBuilder method convert.
/**
* Converts a view to a Graph2D object.
*
* @param nodes Nodes to convert.
* @param edges Edges to convert.
* @param graphSettings Graph settings used to build the graph.
* @param adjustColors True, to initialize the colors of the nodes. False, otherwise.
*
* @return The created Graph2D object.
* @throws LoadCancelledException Thrown if loading the graph was cancelled.
*/
public Graph2D convert(final Collection<INaviViewNode> nodes, final Collection<INaviEdge> edges, final ZyGraphViewSettings graphSettings, final boolean adjustColors) throws LoadCancelledException {
Preconditions.checkNotNull(nodes, "IE00905: View can not be null");
Preconditions.checkNotNull(edges, "IE00906: Edges argument can not be null");
if (!m_loadReporter.report(GraphBuilderEvents.Started)) {
throw new LoadCancelledException();
}
m_loadReporter.start();
final Graph2D graph2D = new Graph2D();
final HierarchyManager hierarchyManager = new HierarchyManager(graph2D);
graph2D.setHierarchyManager(hierarchyManager);
hierarchyManager.addHierarchyListener(new GroupNodeRealizer.StateChangeListener());
checkCancellation(GraphBuilderEvents.InitializedGraph);
// Keep track of all connections between view nodes and yfiles nodes
final HashMap<INaviViewNode, Node> rawNodeToNodeMap = new HashMap<INaviViewNode, Node>();
// To convert the view into a Graph2D object, it is necessary to convert every node
// and every edge from the view into the corresponding yfiles objects.
convertNodes(nodes, graph2D, rawNodeToNodeMap, graphSettings);
checkCancellation(GraphBuilderEvents.ConvertedNodes);
convertEdges(edges, graph2D, rawNodeToNodeMap, adjustColors);
checkCancellation(GraphBuilderEvents.ConvertedEdges);
setupGroupNodes(nodes, graph2D, rawNodeToNodeMap);
checkCancellation(GraphBuilderEvents.CreatedGroupNodes);
checkCancellation(GraphBuilderEvents.Finished);
return graph2D;
}
use of com.google.security.zynamics.binnavi.disassembly.INaviViewNode in project binnavi by google.
the class CViewGraphSynchronizer method updateParentNode.
/**
* Updates the parent group node of a node.
*
* @param node The node whose parent group node is updated.
* @param groupNode The new parent group node.
*/
private void updateParentNode(final INaviViewNode node, final INaviGroupNode groupNode) {
final Node mappedNaviNode = m_mappings.getYNode(node);
final Node mappedGroupNode = groupNode == null ? null : m_mappings.getYNode(groupNode);
if (mappedNaviNode != null) {
// We need this null-check here because a group node can lose all
// of its members to another group node while the group node itself
// is also added to the new group. Since empty group nodes are
// automatically removed, the original group node can already be
// removed from the graph before the changedParentGroup event is sent.
m_graph.getGraph().getHierarchyManager().setParentNode(mappedNaviNode, mappedGroupNode);
m_graph.updateViews();
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviViewNode in project binnavi by google.
the class ZyGraph method saveAs.
/**
* Creates a copy of the current native view and transfers the copied native view into the graph
* object. That means that the graph object changes its underlying raw view when this function is
* called.
*
* @param container The view container where the view is copied to.
* @param name The new name of the raw view.
* @param description The new description of the raw view.
*
* @return The new raw view.
*
* @throws CouldntSaveDataException Thrown if the view could not be saved.
*/
public INaviView saveAs(final IViewContainer container, final String name, final String description) throws CouldntSaveDataException {
Preconditions.checkNotNull(container, "IE00871: Container argument can not be null");
Preconditions.checkNotNull(name, "IE00872: Name argument can not be null");
Preconditions.checkNotNull(description, "IE00899: Description argument can not be null");
final INaviView oldView = m_rawView;
final INaviView newView = container.createView(name, description);
CViewInserter.insertView(oldView, newView);
final List<INaviViewNode> oldNodes = oldView.getGraph().getNodes();
final List<INaviViewNode> newNodes = newView.getGraph().getNodes();
for (int i = 0; i < oldNodes.size(); i++) {
final INaviViewNode newNode = newNodes.get(i);
final NaviNode oldNode = getMappings().getNode(oldNodes.get(i));
getMappings().setNode(newNode, oldNode);
oldNode.setRawNode(newNode);
for (final INaviGraphListener listener : m_listeners) {
try {
listener.changedModel(this, oldNode);
} catch (final Exception exception) {
CUtilityFunctions.logException(exception);
}
}
}
final List<INaviEdge> oldEdges = oldView.getGraph().getEdges();
final List<INaviEdge> newEdges = newView.getGraph().getEdges();
for (int i = 0; i < oldEdges.size(); i++) {
final INaviEdge newEdge = newEdges.get(i);
final NaviEdge oldEdge = getMappings().getEdge(oldEdges.get(i));
assert oldEdge != null;
getMappings().setEdge(newEdge, oldEdge);
final ZyEdgeRealizer<NaviEdge> realizer = oldEdge.getRealizer();
realizer.setUpdater(new CEdgeUpdater(newEdge));
oldEdge.setRawEdge(newEdge);
}
removeListeners();
newView.save();
CSettingsFunctions.saveSettings(newView, getView(), m_settings);
m_rawView = newView;
initializeListeners();
m_synchronizer.reset();
for (final INaviGraphListener listener : m_listeners) {
// ESCA-JAVA0166: Catch Exception here because we are calling a listener function.
try {
listener.changedView(oldView, newView);
} catch (final Exception exception) {
CUtilityFunctions.logException(exception);
}
}
oldView.close();
return m_rawView;
}
use of com.google.security.zynamics.binnavi.disassembly.INaviViewNode in project binnavi by google.
the class CViewContent method createGroupNode.
@Override
public CGroupNode createGroupNode(final Collection<INaviViewNode> nodes) {
Preconditions.checkNotNull(nodes, "IE00297: Nodes argument can not be null");
Preconditions.checkArgument(!nodes.isEmpty(), "IE00298: Nodes list can not be empty");
final CGroupNode groupNode = new CGroupNode(-1, 0, 0, 0, 0, TEXTNODE_COLOR, false, true, new HashSet<CTag>(), null, false, provider);
for (final INaviViewNode node : nodes) {
Preconditions.checkNotNull(node, "IE00299: Nodes list contains a null-argument");
groupNode.addElement(node);
}
addNode(groupNode);
// Do not bother to update the graph type because group nodes have no effect on graph types.
groupNode.addListener(m_internalNodeListener);
groupNode.addGroupListener(m_internalNodeListener);
return groupNode;
}
use of com.google.security.zynamics.binnavi.disassembly.INaviViewNode in project binnavi by google.
the class PostgreSQLViewLoader method loadView.
/**
* Loads the graph of a view from the database.
*
* @param provider The SQL provider that provides the connection.
* @param view The view to load.
* @param list A list of all modules that are part of the database.
* @param nodeTagManager Node tag manager of the database.
*
* @return The graph of the view.
*
* @throws CouldntLoadDataException Thrown if the graph of view could not be loaded.
* @throws CPartialLoadException Thrown if the graph could not be loaded because not all required
* modules are loaded.
*/
public static MutableDirectedGraph<INaviViewNode, INaviEdge> loadView(final AbstractSQLProvider provider, final INaviView view, final List<INaviModule> list, final CTagManager nodeTagManager) throws CouldntLoadDataException, CPartialLoadException {
checkArguments(provider, view, list, nodeTagManager);
try {
final List<INaviViewNode> nodes = PostgreSQLNodeLoader.loadNodes(provider, view, list, nodeTagManager);
NodeCache.get(provider).addNodes(nodes);
final List<INaviEdge> edges = PostgreSQLEdgeLoader.loadEdges(provider, view, nodes);
EdgeCache.get(provider).addEdges(edges);
return new MutableDirectedGraph<INaviViewNode, INaviEdge>(nodes, edges);
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
}
Aggregations