Search in sources :

Example 1 with FunctionCommentNotificationContainer

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

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

the class PostgreSQLNotificationParserTest method testFunctionCommentParsingAppendComment.

@Test
public void testFunctionCommentParsingAppendComment() {
    new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
    MockPGNotification notification = new MockPGNotification("comment_changes", "bn_functions UPDATE 1 4608 3333");
    final CommentNotification result = PostgreSQLCommentNotificationParser.processFunctionCommentNotification(notification, provider);
    assertNotNull(result);
    final FunctionCommentNotificationContainer container = (FunctionCommentNotificationContainer) result;
    final INaviFunction function = container.getFunction();
    assertEquals(new CAddress(4608), function.getAddress());
    assertEquals(CommentOperation.APPEND, container.getOperation());
    assertEquals(new Integer(3333), container.getCommentId());
}
Also used : FunctionCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.FunctionCommentNotificationContainer) 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) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 3 with FunctionCommentNotificationContainer

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

the class PostgreSQLNotificationParserTest method testFunctionCommentParsingDeleteComment.

@Test
public void testFunctionCommentParsingDeleteComment() {
    new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
    MockPGNotification notification = new MockPGNotification("comment_changes", "bn_functions UPDATE 1 4608 null");
    final CommentNotification result = PostgreSQLCommentNotificationParser.processFunctionCommentNotification(notification, provider);
    assertNotNull(result);
    final FunctionCommentNotificationContainer container = (FunctionCommentNotificationContainer) result;
    final INaviFunction function = container.getFunction();
    assertEquals(new CAddress(4608), function.getAddress());
    assertEquals(CommentOperation.DELETE, container.getOperation());
    assertNull(container.getCommentId());
}
Also used : FunctionCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.FunctionCommentNotificationContainer) 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) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Aggregations

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