Search in sources :

Example 6 with EdgeCommentNotificationContainer

use of com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.EdgeCommentNotificationContainer 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;
}
Also used : CommentNotification(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) BigInteger(java.math.BigInteger) CommentOperation(com.google.security.zynamics.binnavi.disassembly.CommentManager.CommentOperation) EdgeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.EdgeCommentNotificationContainer) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) BigInteger(java.math.BigInteger)

Example 7 with EdgeCommentNotificationContainer

use of com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.EdgeCommentNotificationContainer in project binnavi by google.

the class PostgreSQLCommentNotificationParser method processEdgeLocalCommentNotification.

/**
   * Parses the notifications from the database back end for local edge comments by using a regular
   * expression. If the regular expression matches the supplied {@link PGNotification} notification,
   * it is determined if the edge in question is loaded, and if a
   * {@link CommentNotificationContainer} is build with the data from the notification.
   *
   * @param notification The {@link PGNotification} from the PostgreSQL database server.
   * @param provider The {@link SQLProvider} which is used to communicate with the database.
   */
static CommentNotification processEdgeLocalCommentNotification(final PGNotification notification, final SQLProvider provider) {
    final Matcher matcher = EDGE_LOCAL_PATTERN.matcher(notification.getParameter());
    if (!matcher.find()) {
        return null;
    }
    final Integer edgeId = Integer.parseInt(matcher.group(3));
    final Integer commentId = matcher.group(4).equals("null") ? null : Integer.parseInt(matcher.group(4));
    final INaviEdge edge = EdgeCache.get(provider).getEdgeById(edgeId);
    if (edge == null) {
        return null;
    }
    final CommentOperation operation = commentId == null ? CommentOperation.DELETE : CommentOperation.APPEND;
    return new EdgeCommentNotificationContainer(edge, operation, CommentScope.LOCAL, commentId);
}
Also used : BigInteger(java.math.BigInteger) CommentOperation(com.google.security.zynamics.binnavi.disassembly.CommentManager.CommentOperation) EdgeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.EdgeCommentNotificationContainer) Matcher(java.util.regex.Matcher) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge)

Aggregations

EdgeCommentNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.EdgeCommentNotificationContainer)7 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)7 CommentNotification (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification)6 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)5 Test (org.junit.Test)5 CommentOperation (com.google.security.zynamics.binnavi.disassembly.CommentManager.CommentOperation)2 BigInteger (java.math.BigInteger)2 Matcher (java.util.regex.Matcher)2 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)1 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)1 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)1 ArrayList (java.util.ArrayList)1