Search in sources :

Example 1 with CommentOperation

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

the class PostgreSQLCommentNotificationParser method processGroupNodeCommentNotification.

/**
   * Parses the notifications from the database back end for group node comments by using a regular
   * expression. If the regular expression matches the supplied {@link PGNotification} notification,
   * it is determined if the group 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 processGroupNodeCommentNotification(final PGNotification notification, final SQLProvider provider) {
    final Matcher matcher = GROUP_NODE_PATTERN.matcher(notification.getParameter());
    if (!matcher.find()) {
        return null;
    }
    final Integer nodeId = Integer.parseInt(matcher.group(3));
    final Integer commentId = matcher.group(4).equals("null") ? null : Integer.parseInt(matcher.group(4));
    final INaviGroupNode groupNode = (INaviGroupNode) NodeCache.get(provider).getNodeById(nodeId);
    if (groupNode == null) {
        return null;
    }
    final CommentOperation operation = commentId == null ? CommentOperation.DELETE : CommentOperation.APPEND;
    return new GroupNodeCommentNotificationContainer(groupNode, operation, commentId);
}
Also used : BigInteger(java.math.BigInteger) CommentOperation(com.google.security.zynamics.binnavi.disassembly.CommentManager.CommentOperation) Matcher(java.util.regex.Matcher) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) GroupNodeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.GroupNodeCommentNotificationContainer)

Example 2 with CommentOperation

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

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

the class PostgreSQLCommentNotificationParser method processFunctionCommentNotification.

/**
   * Parses the notifications from the database back end for function comments by using a regular
   * expression. If the regular expression matches the supplied {@link PGNotification} notification,
   * 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 processFunctionCommentNotification(final PGNotification notification, final SQLProvider provider) {
    final Matcher matcher = FUNCTION_PATTERN.matcher(notification.getParameter());
    if (!matcher.find()) {
        return null;
    }
    final Integer notificationModuleId = Integer.parseInt(matcher.group(3));
    final IAddress notificationFunctionAddress = new CAddress(new BigInteger(matcher.group(4)));
    final Integer commentId = matcher.group(5).equals("null") ? null : Integer.parseInt(matcher.group(5));
    final INaviModule module = provider.findModule(notificationModuleId);
    if ((module == null) || !module.isLoaded()) {
        return null;
    }
    final INaviFunction function = module.getContent().getFunctionContainer().getFunction(notificationFunctionAddress);
    if (function == null) {
        return null;
    }
    final CommentOperation operation = commentId == null ? CommentOperation.DELETE : CommentOperation.APPEND;
    return new FunctionCommentNotificationContainer(function, operation, commentId);
}
Also used : BigInteger(java.math.BigInteger) CommentOperation(com.google.security.zynamics.binnavi.disassembly.CommentManager.CommentOperation) FunctionCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.FunctionCommentNotificationContainer) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) Matcher(java.util.regex.Matcher) BigInteger(java.math.BigInteger) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 4 with CommentOperation

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

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

the class PostgreSQLCommentNotificationParser method processFunctionNodeCommentNotification.

/**
   * Parses the notifications from the database back end for function node comments by using a
   * regular expression. If the regular expression matches the supplied {@link PGNotification}
   * notification, it is determined if the function node in question 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 processFunctionNodeCommentNotification(final PGNotification notification, final SQLProvider provider) {
    final Matcher matcher = FUNCTION_NODE_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 == null) || !module.isLoaded()) {
        return null;
    }
    final INaviFunctionNode functionNode = (INaviFunctionNode) NodeCache.get(provider).getNodeById(nodeId);
    if (functionNode == null) {
        return null;
    }
    final CommentOperation operation = commentId == null ? CommentOperation.DELETE : CommentOperation.APPEND;
    return new FunctionNodeCommentNotificationContainer(functionNode, operation, 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) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) FunctionNodeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.FunctionNodeCommentNotificationContainer)

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