Search in sources :

Example 1 with TypeInstanceCommentNotificationContainer

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

the class PostgreSQLNotificationParserTest method testTypeInstanceCommentParsingAppendComment.

@Test
public void testTypeInstanceCommentParsingAppendComment() throws CouldntSaveDataException, CouldntLoadDataException {
    final INaviModule module = new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
    module.getContent().getSections().createSection("A", new CAddress(0), new CAddress(1234), SectionPermission.READ, null);
    final TypeInstance fakeInstance = module.getContent().getTypeInstanceContainer().createInstance("TYPE INSTANCE", null, module.getTypeManager().getTypes().get(0), module.getContent().getSections().getSection(0), 0);
    MockPGNotification notification = new MockPGNotification("comment_changes", "bn_type_instances UPDATE 1 " + fakeInstance.getId() + " 3333");
    final CommentNotification result = PostgreSQLCommentNotificationParser.processTypeInstanceCommentNotification(notification, provider);
    assertNotNull(result);
    final TypeInstanceCommentNotificationContainer container = (TypeInstanceCommentNotificationContainer) result;
    assertNotNull(container);
    final TypeInstance instance = container.getInstance();
    assertEquals(fakeInstance.getId(), instance.getId());
    assertEquals(CommentOperation.APPEND, container.getOperation());
    assertEquals(new Integer(3333), container.getCommentId());
}
Also used : TypeInstanceCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TypeInstanceCommentNotificationContainer) CommentNotification(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) TypeInstance(com.google.security.zynamics.binnavi.disassembly.types.TypeInstance) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 2 with TypeInstanceCommentNotificationContainer

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

the class PostgreSQLNotificationParserTest method testTypeInstanceCommentParsingDeleteComment.

@Test
public void testTypeInstanceCommentParsingDeleteComment() throws CouldntSaveDataException, CouldntLoadDataException {
    final INaviModule module = new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
    module.getContent().getSections().createSection("A", new CAddress(0), new CAddress(1234), SectionPermission.READ, null);
    final TypeInstance fakeInstance = module.getContent().getTypeInstanceContainer().createInstance("TYPE INSTANCE", null, module.getTypeManager().getTypes().get(0), module.getContent().getSections().getSection(0), 0);
    final PGNotification notification = new MockPGNotification("comment_changes", "bn_type_instances UPDATE 1 " + fakeInstance.getId() + " null");
    final CommentNotification result = PostgreSQLCommentNotificationParser.processTypeInstanceCommentNotification(notification, provider);
    assertNotNull(result);
    final TypeInstanceCommentNotificationContainer container = (TypeInstanceCommentNotificationContainer) result;
    assertNotNull(container);
    final TypeInstance instance = container.getInstance();
    assertEquals(fakeInstance.getId(), instance.getId());
    assertEquals(CommentOperation.DELETE, container.getOperation());
    assertNull(container.getCommentId());
}
Also used : TypeInstanceCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TypeInstanceCommentNotificationContainer) CommentNotification(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) PGNotification(org.postgresql.PGNotification) TypeInstance(com.google.security.zynamics.binnavi.disassembly.types.TypeInstance) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 3 with TypeInstanceCommentNotificationContainer

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

Aggregations

TypeInstanceCommentNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TypeInstanceCommentNotificationContainer)3 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)3 TypeInstance (com.google.security.zynamics.binnavi.disassembly.types.TypeInstance)3 CommentNotification (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification)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 BigInteger (java.math.BigInteger)1 Matcher (java.util.regex.Matcher)1 PGNotification (org.postgresql.PGNotification)1