Search in sources :

Example 6 with CodeNodeCommentNotificationContainer

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

the class PostgreSQLCommentNotificationParser method processNodeLocalNodeCommentNotification.

/**
   * Parses the {@link PGNotification} notifications from the PostgreSQL database back end for local
   * code node comments by using a regular expression. If the regular expression matches the
   * supplied {@link PGNotification} notification, it is determined if the code node in the
   * notification is currently loaded, and if a {@link CommentNotificationContainer} with the
   * gathered data from the notification is returned.
   *
   * @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 processNodeLocalNodeCommentNotification(final PGNotification notification, final SQLProvider provider) {
    final Matcher matcher = NODE_LOCAL_PATTERN.matcher(notification.getParameter());
    if (!matcher.find()) {
        return null;
    }
    final Integer moduleId = Integer.parseInt(matcher.group(3));
    final Integer nodeId = Integer.parseInt(matcher.group(4));
    final Integer commentId = matcher.group(6).equals("null") ? null : Integer.parseInt(matcher.group(6));
    final INaviModule module = provider.findModule(moduleId);
    if (!module.isLoaded()) {
        return null;
    }
    final INaviCodeNode codeNode = (INaviCodeNode) NodeCache.get(provider).getNodeById(nodeId);
    if (codeNode == null) {
        return null;
    }
    final CommentOperation operation = commentId == null ? CommentOperation.DELETE : CommentOperation.APPEND;
    return new CodeNodeCommentNotificationContainer(codeNode, operation, CommentScope.LOCAL, commentId);
}
Also used : BigInteger(java.math.BigInteger) CommentOperation(com.google.security.zynamics.binnavi.disassembly.CommentManager.CommentOperation) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) Matcher(java.util.regex.Matcher) CodeNodeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.CodeNodeCommentNotificationContainer)

Example 7 with CodeNodeCommentNotificationContainer

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

the class PostgreSQLCommentNotificationParser method processNodeGlobalCommentNotification.

/**
   * Parses the notifications from the database back end for global code node comments by using a
   * regular expression. If the regular expression matches the supplied {@link PGNotification}
   * notification, it is determined if the code node in the notification is currently loaded, and if
   * a {@link CommentNotificationContainer} with the data from the notification is returned.
   *
   * @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> processNodeGlobalCommentNotification(final PGNotification notification, final SQLProvider provider) {
    final Matcher matcher = NODE_GLOBAL_PATTERN.matcher(notification.getParameter());
    if (!matcher.find()) {
        return new ArrayList<>();
    }
    final String databaseOperation = matcher.group(2);
    final int moduleId = Integer.parseInt(matcher.group(3));
    final IAddress nodeAddress = new CAddress(new BigInteger(matcher.group(4)));
    final Integer commentId = matcher.group(6) == null ? null : Integer.parseInt(matcher.group(6));
    final INaviModule notificationModule = provider.findModule(moduleId);
    if ((notificationModule == null) || !notificationModule.isLoaded()) {
        return new ArrayList<>();
    }
    final ImmutableCollection<INaviViewNode> nodes = NodeCache.get(provider).getNodeByAddress(nodeAddress, moduleId);
    if (nodes == null) {
        return new ArrayList<>();
    }
    final CommentOperation operation = databaseOperation.equalsIgnoreCase("DELETE") ? CommentOperation.DELETE : CommentOperation.APPEND;
    Collection<CommentNotification> notifications = new ArrayList<>();
    for (INaviViewNode node : nodes) {
        notifications.add(new CodeNodeCommentNotificationContainer((INaviCodeNode) node, 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) 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) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) BigInteger(java.math.BigInteger) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) CodeNodeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.CodeNodeCommentNotificationContainer)

Aggregations

CodeNodeCommentNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.CodeNodeCommentNotificationContainer)7 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)7 CommentNotification (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification)6 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)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 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)2 BigInteger (java.math.BigInteger)2 Matcher (java.util.regex.Matcher)2 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)1 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)1 ArrayList (java.util.ArrayList)1