use of com.google.security.zynamics.binnavi.disassembly.INaviViewNode in project binnavi by google.
the class PostgreSQLNodeSaver method saveParentGroups.
/**
* Stores parent groups for all nodes that have an assigned parent group.
*
* @param connection Provides the connection to the database.
* @param nodes All nodes that were saved.
* @param firstNode The database index of the first node.
* @param groupNodeMap Maps between node IDs and parent group node objects.
*
* @throws SQLException Thrown if the parent groups could not be assigned.
*/
protected static void saveParentGroups(final CConnection connection, final List<INaviViewNode> nodes, final int firstNode, final BiMap<Integer, INaviGroupNode> groupNodeMap) throws SQLException {
int counter = 0;
for (final INaviViewNode node : nodes) {
if (node.getParentGroup() != null) {
final int parentId = firstNode + groupNodeMap.inverse().get(node.getParentGroup());
final int childId = firstNode + counter;
connection.executeUpdate(String.format("UPDATE " + CTableNames.NODES_TABLE + " set parent_id = %d WHERE id = %d", parentId, childId), true);
}
counter++;
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviViewNode in project binnavi by google.
the class PostgreSQLNodeSaver method saveTags.
/**
*
* TODO (timkornau): this code here has serious issues and is in no way anything that we want to
* keep.
*
* Saves the node tags to the database.
*
* @param connection The connection to the database.
* @param nodes The nodes to save.
* @param firstNode Database index of the first node.
*
* @throws SQLException Thrown if saving the tags failed.
*/
protected static void saveTags(final CConnection connection, final List<INaviViewNode> nodes, final int firstNode) throws SQLException {
int counter = firstNode;
final String deleteStatement = "DELETE FROM " + CTableNames.TAGGED_NODES_TABLE + " WHERE node_id IN (%s)";
final String insertStatement = "INSERT INTO " + CTableNames.TAGGED_NODES_TABLE + " VALUES %s ";
boolean isFirst = true;
final StringBuilder range = new StringBuilder();
for (int i = 0; i < nodes.size(); i++) {
if (isFirst) {
range.append(counter);
isFirst = false;
continue;
}
range.append(", ");
range.append(counter);
++counter;
}
if (range.length() != 0) {
connection.executeUpdate(String.format(deleteStatement, range.toString()), true);
}
counter = firstNode;
final StringBuilder insert = new StringBuilder();
isFirst = true;
for (final INaviViewNode node : nodes) {
final Iterator<CTag> it = node.getTagsIterator();
while (it.hasNext()) {
final CTag tag = it.next();
insert.append(isFirst ? "" : ",");
insert.append('(');
insert.append(counter);
insert.append(", ");
insert.append(tag.getId());
insert.append(')');
isFirst = false;
}
++counter;
}
if (insert.length() != 0) {
connection.executeUpdate(String.format(insertStatement, insert.toString()), true);
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviViewNode in project binnavi by google.
the class CDebuggerPainter method updateDebuggerHighlighting.
/**
* Updates the program counter highlighting in a whole graph.
*
* @param graph The graph where the highlighting is updated.
* @param address The address of the program counter to be highlighted.
* @param module The module in which the address is located.
*/
public static void updateDebuggerHighlighting(final ZyGraph graph, final UnrelocatedAddress address, final INaviModule module) {
Preconditions.checkNotNull(graph, "IE02187: Graph argument can not be null");
Preconditions.checkNotNull(address, "IE02188: Address argument can not be null");
graph.iterate(new INodeCallback<NaviNode>() {
@Override
public IterationMode next(final NaviNode node) {
final INaviViewNode rawNode = node.getRawNode();
if (rawNode instanceof ICodeNode) {
final INaviCodeNode codeNode = (INaviCodeNode) rawNode;
try {
if (module.equals(codeNode.getParentFunction().getModule())) {
updateDebuggerHighlighting(graph, address, node, codeNode);
}
} catch (final MaybeNullException exception) {
CUtilityFunctions.logException(exception);
}
} else if (rawNode instanceof INaviFunctionNode) {
final INaviFunctionNode functionNode = (INaviFunctionNode) rawNode;
if (module.equals(functionNode.getFunction().getModule())) {
updateDebuggerHighlighting(address, node, functionNode);
}
}
return IterationMode.CONTINUE;
}
});
ZyZoomHelpers.zoomToAddress(graph, address.getAddress(), module, false);
}
use of com.google.security.zynamics.binnavi.disassembly.INaviViewNode in project binnavi by google.
the class PostgreSQLViewCreator method createView.
/**
* Inserts a new view in the database by copying an existing view.
*
* @param provider The connection to the database.
* @param containerId The ID of the container where the view is created.
* @param view The view to be copied.
* @param name The name of the new view.
* @param description The description of the new view.
* @param containerTable Name of the view container table.
* @param viewContainerTable Name of the view container views table.
* @param generator Generates the view.
* @return The created view.
* @throws CouldntSaveDataException Thrown if the view could not be created.
*/
private static CView createView(final AbstractSQLProvider provider, final int containerId, final INaviView view, final String name, final String description, final String containerTable, final String viewContainerTable, final ViewGenerator generator) throws CouldntSaveDataException {
final CConnection connection = provider.getConnection();
try {
PostgreSQLHelpers.beginTransaction(connection);
final int viewId = insertView(connection, name, description);
// Mark the view as a module view
connection.executeUpdate("INSERT INTO " + viewContainerTable + " VALUES(" + containerId + ", " + viewId + ")", true);
final List<INaviViewNode> nodes = view.getGraph().getNodes();
final List<INaviEdge> edges = view.getGraph().getEdges();
// Store all nodes
PostgreSQLNodeSaver.writeNodes(provider, viewId, nodes);
// Store all edges
PostgreSQLEdgeSaver.writeEdges(provider, edges);
PostgreSQLHelpers.endTransaction(connection);
final String query = "SELECT creation_date, modification_date FROM " + CTableNames.VIEWS_TABLE + " WHERE id = " + viewId;
final ResultSet resultSet = connection.executeQuery(query, true);
try {
while (resultSet.next()) {
final Timestamp creationDate = resultSet.getTimestamp("creation_date");
final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
PostgreSQLHelpers.updateModificationDate(connection, containerTable, containerId);
return generator.generate(viewId, name, description, ViewType.NonNative, view.getGraphType(), creationDate, modificationDate, view.getNodeCount(), view.getEdgeCount(), new HashSet<CTag>(), new HashSet<CTag>(), false);
}
throw new CouldntSaveDataException("Error: Couldnt't load the created view");
} finally {
resultSet.close();
}
} catch (final SQLException exception) {
CUtilityFunctions.logException(exception);
try {
PostgreSQLHelpers.rollback(connection);
} catch (final SQLException e) {
CUtilityFunctions.logException(e);
}
throw new CouldntSaveDataException(exception);
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviViewNode in project binnavi by google.
the class View method createGroupNode.
// ! Creates a new group node.
/**
* Creates a new group node in the view.
*
* @param text Text that is shown when the group node is collapsed.
* @param elements Nodes that belong to the group node.
*
* @return The created group node.
*/
public GroupNode createGroupNode(final String text, final List<ViewNode> elements) {
Preconditions.checkNotNull(text, "Error: Text argument can not be null");
Preconditions.checkNotNull(elements, "Error: Elements argument can not be null");
final List<INaviViewNode> nodes = new ArrayList<INaviViewNode>();
for (final ViewNode element : elements) {
Preconditions.checkNotNull(element, "Error: Elements list contains a null-element");
nodes.add(element.getNative());
}
final CGroupNode newGroupNode = naviView.getContent().createGroupNode(nodes);
return (GroupNode) cachedNodes.get(newGroupNode);
}
Aggregations