use of com.google.security.zynamics.binnavi.disassembly.INaviEdge 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.INaviEdge in project binnavi by google.
the class CViewPruner method convertEdges.
/**
* Converts edges of the original view to the pruned view.
*
* @param view The original view.
* @param prunedView The pruned view.
* @param nodeMap A mapping between nodes of the original view and nodes of the pruned view.
*/
private static void convertEdges(final INaviView view, final INaviView prunedView, final Map<INaviViewNode, INaviViewNode> nodeMap) {
final Set<Pair<INaviViewNode, INaviViewNode>> createdEdges = new HashSet<Pair<INaviViewNode, INaviViewNode>>();
for (final INaviEdge edge : view.getGraph().getEdges()) {
final Set<EdgeResult> sources = getSources(edge, nodeMap, new HashSet<INaviEdge>());
final Set<EdgeResult> targets = getTargets(edge, nodeMap, new HashSet<INaviEdge>());
for (final EdgeResult source : sources) {
for (final EdgeResult target : targets) {
final Pair<INaviViewNode, INaviViewNode> edgePair = new Pair<INaviViewNode, INaviViewNode>(source.m_node, target.m_node);
if (createdEdges.contains(edgePair)) {
continue;
}
prunedView.getContent().createEdge(source.m_node, target.m_node, source.m_type);
createdEdges.add(edgePair);
}
}
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviEdge in project binnavi by google.
the class CViewPruner method getTargets.
/**
* Collects edge information about incoming edges.
*
* @param edge The edge whose information is collected.
* @param nodeMap Maps between nodes of the old view and nodes of the new view.
* @param visited Already visited edges.
*
* @return The collected edge information.
*/
private static Set<EdgeResult> getTargets(final INaviEdge edge, final Map<INaviViewNode, INaviViewNode> nodeMap, final Set<INaviEdge> visited) {
final INaviViewNode target = edge.getTarget();
visited.add(edge);
final Set<EdgeResult> targets = new HashSet<EdgeResult>();
if (nodeMap.containsKey(target)) {
targets.add(new EdgeResult(nodeMap.get(target), edge.getType()));
} else {
for (final INaviEdge outgoingEdge : target.getOutgoingEdges()) {
if (!visited.contains(outgoingEdge)) {
targets.addAll(getTargets(outgoingEdge, nodeMap, visited));
}
}
}
return targets;
}
use of com.google.security.zynamics.binnavi.disassembly.INaviEdge in project binnavi by google.
the class CGlobalEdgeCommentSynchronizer method updateOpenViews.
/**
* Pushes a new global edge comment to all open views.
*
* @param edge The edge that has the new comment.
* @param comments The new comment of the code node.
*
* @throws CouldntSaveDataException Thrown if updating the edge comments failed.
*/
public static void updateOpenViews(final INaviEdge edge, final ArrayList<IComment> comments) throws CouldntSaveDataException {
try {
final Pair<INaviModule, INaviModule> modules = getModules(edge);
if (modules.first() != modules.second()) {
// TODO: Handle this
return;
}
if ((modules.first() != null) && (modules.second() != null) && modules.first().isLoaded()) {
final List<INaviEdge> edgelist = new ArrayList<INaviEdge>();
final Quad<Integer, IAddress, Integer, IAddress> refEdgeData = getEdgeData(edge);
for (final INaviView view : modules.first().getContent().getViewContainer().getViews()) {
edgelist.addAll(collectEdges(view, refEdgeData));
}
for (final INaviEdge updateEdge : edgelist) {
updateEdge.initializeGlobalComment(comments);
}
}
} catch (final MaybeNullException exception) {
// Trying to update global comments of code nodes without global comments.
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviEdge in project binnavi by google.
the class PostgreSQLCommentNotificationParser method processEdgeGlobalCommentNotification.
/**
* Parses the notifications from the database back end for global edge comments by using a regular
* expression. If the regular expression matches the supplied notification it tries to figure out
* if the edge which was commented is loaded in BinNavi at this point in time. If the edge is
* loaded determine the operation which was performed by the database and then return a
* {@link CommentNotificationContainer} with the gathered results.
*
* @param notification The {@link PGNotification} from the PostgreSQL database server.
* @param provider The {@link SQLProvider} which is used to communicate with the database.
*/
static Collection<CommentNotification> processEdgeGlobalCommentNotification(final PGNotification notification, final SQLProvider provider) {
final Matcher matcher = EDGE_GLOBAL_PATTERN.matcher(notification.getParameter());
if (!matcher.find()) {
return new ArrayList<>();
}
final String databaseOperation = matcher.group(2);
final Integer notificationSourceModuleId = Integer.parseInt(matcher.group(3));
final Integer notificationDestinationModuleId = Integer.parseInt(matcher.group(4));
final IAddress notificationEdgeSourceAddress = new CAddress(new BigInteger(matcher.group(5)));
final IAddress notificationEdgeDestinationAddress = new CAddress(new BigInteger(matcher.group(6)));
final Integer commentId = matcher.group(8) == null ? null : Integer.parseInt(matcher.group(8));
final INaviModule notificationSourceModule = provider.findModule(notificationSourceModuleId);
if ((notificationSourceModule == null) || !notificationSourceModule.isLoaded()) {
return new ArrayList<>();
}
final INaviModule notificationDestinationModule = provider.findModule(notificationDestinationModuleId);
if ((notificationDestinationModule == null) || !notificationDestinationModule.isLoaded()) {
return new ArrayList<>();
}
final CommentOperation operation = databaseOperation.equalsIgnoreCase("DELETE") ? CommentOperation.DELETE : CommentOperation.APPEND;
Collection<CommentNotification> notifications = new ArrayList<>();
final ImmutableCollection<INaviEdge> edges = EdgeCache.get(provider).getEdgeBySourceAndTarget(notificationEdgeSourceAddress, notificationSourceModuleId, notificationEdgeDestinationAddress, notificationDestinationModuleId);
for (INaviEdge edge : edges) {
notifications.add(new EdgeCommentNotificationContainer(edge, operation, CommentScope.GLOBAL, commentId));
}
return notifications;
}
Aggregations