Search in sources :

Example 1 with FunctionNodeCommentNotificationContainer

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

the class PostgreSQLNotificationParserTest method testFunctionNodeCommentParsingAppendComment.

@Test
public void testFunctionNodeCommentParsingAppendComment() {
    new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
    MockPGNotification notification = new MockPGNotification("comment_changes", "bn_function_nodes UPDATE 1 6666 4608 3333");
    final CommentNotification result = PostgreSQLCommentNotificationParser.processFunctionNodeCommentNotification(notification, provider);
    assertNotNull(result);
    final FunctionNodeCommentNotificationContainer container = (FunctionNodeCommentNotificationContainer) result;
    final INaviFunction function = container.getNode().getFunction();
    assertEquals(new CAddress(4608), function.getAddress());
    assertEquals(CommentOperation.APPEND, container.getOperation());
    assertEquals(new Integer(3333), container.getCommentId());
}
Also used : CommentNotification(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) FunctionNodeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.FunctionNodeCommentNotificationContainer) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 2 with FunctionNodeCommentNotificationContainer

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

the class PostgreSQLNotificationParserTest method testFunctionNodeCommentParsingDeleteComment.

@Test
public void testFunctionNodeCommentParsingDeleteComment() {
    new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
    MockPGNotification notification = new MockPGNotification("comment_changes", "bn_function_nodes UPDATE 1 6666 4608 null");
    final CommentNotification result = PostgreSQLCommentNotificationParser.processFunctionNodeCommentNotification(notification, provider);
    assertNotNull(result);
    final FunctionNodeCommentNotificationContainer container = (FunctionNodeCommentNotificationContainer) result;
    final INaviFunctionNode functionNode = container.getNode();
    assertEquals(new CAddress(4608), functionNode.getAddress());
    assertEquals(CommentOperation.DELETE, container.getOperation());
    assertNull(container.getCommentId());
}
Also used : CommentNotification(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) FunctionNodeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.FunctionNodeCommentNotificationContainer) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 3 with FunctionNodeCommentNotificationContainer

use of com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.FunctionNodeCommentNotificationContainer 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

FunctionNodeCommentNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.FunctionNodeCommentNotificationContainer)3 CommentNotification (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification)2 INaviFunctionNode (com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode)2 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)2 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)2 Test (org.junit.Test)2 CommentOperation (com.google.security.zynamics.binnavi.disassembly.CommentManager.CommentOperation)1 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)1 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)1 BigInteger (java.math.BigInteger)1 Matcher (java.util.regex.Matcher)1