Search in sources :

Example 6 with CommentOperation

use of com.google.security.zynamics.binnavi.disassembly.CommentManager.CommentOperation in project binnavi by google.

the class PostgreSQLCommentNotificationParser method processTypeInstanceCommentNotification.

/**
   * Parses the {@link PGNotification notifications} from the PostgreSQL database back end for
   * {@link TypeInstance type instance} comments by using a regular expression.
   *
   * @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 processTypeInstanceCommentNotification(final PGNotification notification, final SQLProvider provider) {
    final Matcher matcher = TYPE_INSTANCE_PATTERN.matcher(notification.getParameter());
    if (!matcher.find()) {
        return null;
    }
    final Integer moduleId = Integer.parseInt(matcher.group(3));
    final Integer typeInstanceId = Integer.parseInt(matcher.group(4));
    final Integer commentId = matcher.group(5).equals("null") ? null : Integer.parseInt(matcher.group(5));
    final INaviModule module = provider.findModule(moduleId);
    if (module == null || !module.isLoaded()) {
        return null;
    }
    final TypeInstance instance = module.getContent().getTypeInstanceContainer().getTypeInstanceById(typeInstanceId);
    if (instance == null) {
        return null;
    }
    final CommentOperation operation = commentId == null ? CommentOperation.DELETE : CommentOperation.APPEND;
    return new TypeInstanceCommentNotificationContainer(instance, operation, commentId);
}
Also used : BigInteger(java.math.BigInteger) CommentOperation(com.google.security.zynamics.binnavi.disassembly.CommentManager.CommentOperation) TypeInstanceCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TypeInstanceCommentNotificationContainer) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) Matcher(java.util.regex.Matcher) TypeInstance(com.google.security.zynamics.binnavi.disassembly.types.TypeInstance)

Example 7 with CommentOperation

use of com.google.security.zynamics.binnavi.disassembly.CommentManager.CommentOperation in project binnavi by google.

the class PostgreSQLCommentNotificationParser method processInstructionGlobalCommentNotification.

/**
   * Parses the notifications from the database back end for global instruction comments by using a
   * regular expression. If the regular expression matched the supplied {@link PGNotification}
   * notification, it is determined if the {@link INaviInstruction} instruction in the notification
   * is currently loaded, and if a {@link CommentNotificationContainer} with the gathered data 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 processInstructionGlobalCommentNotification(final PGNotification notification, final SQLProvider provider) {
    final Matcher matcher = INSTRUCTION_GLOBAL_PATTERN.matcher(notification.getParameter());
    if (!matcher.find()) {
        return null;
    }
    final Integer moduleId = Integer.parseInt(matcher.group(3));
    final IAddress address = new CAddress(new BigInteger(matcher.group(4)));
    final Integer commentId = matcher.group(7) == null ? null : Integer.parseInt(matcher.group(7));
    final INaviModule module = provider.findModule(moduleId);
    if ((module == null) || !module.isLoaded()) {
        return null;
    }
    final INaviInstruction instruction = InstructionCache.get(provider).getInstructionByAddress(address, moduleId);
    if (instruction == null) {
        return null;
    }
    final CommentOperation operation = commentId == null ? CommentOperation.DELETE : CommentOperation.APPEND;
    return new InstructionCommentNotificationContainer(instruction, null, operation, CommentScope.GLOBAL, commentId);
}
Also used : BigInteger(java.math.BigInteger) CommentOperation(com.google.security.zynamics.binnavi.disassembly.CommentManager.CommentOperation) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) Matcher(java.util.regex.Matcher) BigInteger(java.math.BigInteger) InstructionCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.InstructionCommentNotificationContainer) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 8 with CommentOperation

use of com.google.security.zynamics.binnavi.disassembly.CommentManager.CommentOperation 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)

Example 9 with CommentOperation

use of com.google.security.zynamics.binnavi.disassembly.CommentManager.CommentOperation in project binnavi by google.

the class PostgreSQLCommentNotificationParser method processNodeLocalInstructionCommentNotification.

/**
   * Parses the {@link PGNotification} notifications from the database back end for local
   * instruction comments by using a regular expression. If the regular expression matches the
   * supplied {@link PGNotification} notification, it is determined if the instruction 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 CommentNotification processNodeLocalInstructionCommentNotification(final PGNotification notification, final SQLProvider provider) {
    final Matcher instructionMatcher = INSTRUCTION_LOCAL_PATTERN.matcher(notification.getParameter());
    final boolean instructionMatchFound = instructionMatcher.find();
    if (!instructionMatchFound) {
        return null;
    }
    final Integer moduleId = Integer.parseInt(instructionMatcher.group(3));
    final Integer nodeId = Integer.parseInt(instructionMatcher.group(4));
    final BigInteger notificationInstructionAddress = new BigInteger(instructionMatcher.group(6));
    final Integer commentId = instructionMatcher.group(7).equals("null") ? null : Integer.parseInt(instructionMatcher.group(7));
    final INaviModule module = provider.findModule(moduleId);
    if ((module == null) || !module.isLoaded()) {
        return null;
    }
    final IAddress address = new CAddress(notificationInstructionAddress);
    final INaviInstruction instruction = InstructionCache.get(provider).getInstructionByAddress(address, module.getConfiguration().getId());
    if (instruction == null) {
        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 InstructionCommentNotificationContainer(instruction, 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) BigInteger(java.math.BigInteger) InstructionCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.InstructionCommentNotificationContainer) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 10 with CommentOperation

use of com.google.security.zynamics.binnavi.disassembly.CommentManager.CommentOperation in project binnavi by google.

the class PostgreSQLCommentNotificationParser method processCommentNotification.

/**
   * Parses a {@link PGNotification} notification from the database back end for comment table
   * changes. These changes can not directly be mapped to any of the commentable objects as the
   * relation to which commentable object they belong is not in the notification message. This
   * notification is generated for the following situations for any commentable object:
   *
   * <pre>
   *
   *Delete a comment:
   *
   *[1] Comment 1    [1] Comment 1
   *[2] Comment 2 ->
   *[3] Comment 3    [3] Comment 3
   *
   *Edit a comment:
   *
   *[1] Comment 1    [1] Comment 1
   *[2] Comment 2 -> [2] Edited Comment 2
   *[3] Comment 3    [3] Comment 3
   *
   *</pre>
   *
   * @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 processCommentNotification(final PGNotification notification, final SQLProvider provider) {
    final Matcher matcher = COMMENTS_PATTERN.matcher(notification.getParameter());
    if (!matcher.find()) {
        return null;
    }
    Integer commentId = null;
    try {
        commentId = Integer.parseInt(matcher.group(3));
    } catch (final NumberFormatException exception) {
        throw new IllegalStateException(exception);
    }
    final IComment comment = CommentManager.get(provider).getCommentById(commentId);
    if (comment == null) {
        return null;
    }
    final String databaseOperation = matcher.group(2);
    Integer parentId = null;
    try {
        parentId = matcher.group(4).equalsIgnoreCase("null") ? null : Integer.parseInt(matcher.group(4));
    } catch (final NumberFormatException exception) {
        throw new IllegalStateException(exception);
    }
    // parent.
    if (databaseOperation.equals("DELETE")) {
        if (((parentId == null) && (comment.getParent() != null)) || ((parentId != null) && (comment.getParent() != null) && (!parentId.equals(comment.getParent().getId())))) {
            final Integer localCommentParentId = parentId;
            final Integer notificationCommentParentId = comment.getParent() != null ? comment.getParent().getId() : null;
            throw new IllegalStateException("IE02521: The parent comment of the localy stored comment: " + localCommentParentId + " is not equal to the " + "notification comments parent comment: " + notificationCommentParentId);
        }
    }
    final String commentContent = matcher.group(9);
    if (!commentContent.equals(comment.getComment()) && databaseOperation.equals("DELETE")) {
        throw new IllegalStateException("IE02522: The local comments comment: " + comment.getComment() + "is not equal to the notification comments content: " + commentContent);
    }
    Integer commentUserId = null;
    try {
        commentUserId = Integer.parseInt(matcher.group(7));
    } catch (final NumberFormatException exception) {
        throw new IllegalStateException(exception);
    }
    if (!commentUserId.equals(comment.getUser().getUserId())) {
        throw new IllegalStateException("IE02523: The user of the localy stored comment: " + commentUserId + " is not equal to the " + "notifications comments user: " + comment.getUser().getUserId());
    }
    final IComment parentComment = CommentManager.get(provider).getCommentById(parentId);
    final IComment newComment = new CComment(comment.getId(), comment.getUser(), parentComment, commentContent);
    final CommentOperation operation = databaseOperation.equalsIgnoreCase("UPDATE") ? CommentOperation.EDIT : CommentOperation.DELETE;
    return new CommentNotificationContainer(comment, newComment, operation);
}
Also used : BigInteger(java.math.BigInteger) CommentOperation(com.google.security.zynamics.binnavi.disassembly.CommentManager.CommentOperation) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) Matcher(java.util.regex.Matcher) TypeInstanceCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TypeInstanceCommentNotificationContainer) GroupNodeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.GroupNodeCommentNotificationContainer) TextNodeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TextNodeCommentNotificationContainer) FunctionNodeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.FunctionNodeCommentNotificationContainer) CodeNodeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.CodeNodeCommentNotificationContainer) CommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.CommentNotificationContainer) FunctionCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.FunctionCommentNotificationContainer) InstructionCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.InstructionCommentNotificationContainer) EdgeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.EdgeCommentNotificationContainer)

Aggregations

CommentOperation (com.google.security.zynamics.binnavi.disassembly.CommentManager.CommentOperation)12 BigInteger (java.math.BigInteger)12 Matcher (java.util.regex.Matcher)12 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)8 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)5 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)5 CodeNodeCommentNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.CodeNodeCommentNotificationContainer)3 EdgeCommentNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.EdgeCommentNotificationContainer)3 InstructionCommentNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.InstructionCommentNotificationContainer)3 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)3 FunctionCommentNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.FunctionCommentNotificationContainer)2 FunctionNodeCommentNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.FunctionNodeCommentNotificationContainer)2 GroupNodeCommentNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.GroupNodeCommentNotificationContainer)2 TextNodeCommentNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TextNodeCommentNotificationContainer)2 TypeInstanceCommentNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TypeInstanceCommentNotificationContainer)2 CommentNotification (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification)2 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)2 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)2 ArrayList (java.util.ArrayList)2 CommentNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.CommentNotificationContainer)1