Search in sources :

Example 1 with InstructionCommentNotificationContainer

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

the class PostgreSQLNotificationParserTest method testLocalInstructionCommentParsingAppend.

@Test
public void testLocalInstructionCommentParsingAppend() {
    new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
    MockPGNotification notification = new MockPGNotification("comment_changes", "bn_codenode_instructions UPDATE 1 1111 0 4608 3333");
    CommentNotification result = PostgreSQLCommentNotificationParser.processNodeLocalInstructionCommentNotification(notification, provider);
    assertNotNull(result);
    final InstructionCommentNotificationContainer container = (InstructionCommentNotificationContainer) result;
    final INaviInstruction instruction = container.getInstruction();
    assertEquals(new CAddress(4608), instruction.getAddress());
    assertEquals(CommentOperation.APPEND, container.getOperation());
    assertEquals(new Integer(3333), container.getCommentId());
    assertEquals(CommentScope.LOCAL, container.getScope());
}
Also used : CommentNotification(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) InstructionCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.InstructionCommentNotificationContainer) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 2 with InstructionCommentNotificationContainer

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

the class PostgreSQLNotificationParserTest method testLocalInstructionCommentParsingDelete.

@Test
public void testLocalInstructionCommentParsingDelete() {
    new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
    MockPGNotification notification = new MockPGNotification("comment_changes", "bn_codenode_instructions UPDATE 1 1111 0 4608 null");
    CommentNotification result = PostgreSQLCommentNotificationParser.processNodeLocalInstructionCommentNotification(notification, provider);
    assertNotNull(result);
    final InstructionCommentNotificationContainer container = (InstructionCommentNotificationContainer) result;
    final INaviInstruction instruction = container.getInstruction();
    assertEquals(new CAddress(4608), instruction.getAddress());
    assertEquals(CommentOperation.DELETE, container.getOperation());
    assertNull(container.getCommentId());
    assertEquals(CommentScope.LOCAL, container.getScope());
}
Also used : CommentNotification(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) InstructionCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.InstructionCommentNotificationContainer) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 3 with InstructionCommentNotificationContainer

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

the class PostgreSQLNotificationParserTest method testGlobalInstructionCommentParsingDelete.

@Test
public void testGlobalInstructionCommentParsingDelete() {
    new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
    MockPGNotification notification = new MockPGNotification("comment_changes", "bn_instructions UPDATE 1 4608 null");
    final CommentNotification result = PostgreSQLCommentNotificationParser.processInstructionGlobalCommentNotification(notification, provider);
    assertNotNull(result);
    final InstructionCommentNotificationContainer container = (InstructionCommentNotificationContainer) result;
    final INaviInstruction instruction = container.getInstruction();
    assertEquals(new CAddress(4608), instruction.getAddress());
    assertEquals(CommentOperation.DELETE, container.getOperation());
    assertNull(container.getCommentId());
    assertEquals(CommentScope.GLOBAL, container.getScope());
}
Also used : CommentNotification(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) InstructionCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.InstructionCommentNotificationContainer) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 4 with InstructionCommentNotificationContainer

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

the class PostgreSQLNotificationParserTest method testGlobalInstructionCommentParsingAppend.

@Test
public void testGlobalInstructionCommentParsingAppend() {
    new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
    MockPGNotification notification = new MockPGNotification("comment_changes", "bn_instructions UPDATE 1 4608 3333");
    final CommentNotification result = PostgreSQLCommentNotificationParser.processInstructionGlobalCommentNotification(notification, provider);
    assertNotNull(result);
    final InstructionCommentNotificationContainer container = (InstructionCommentNotificationContainer) result;
    final INaviInstruction instruction = container.getInstruction();
    assertEquals(new CAddress(4608), instruction.getAddress());
    assertEquals(CommentOperation.APPEND, container.getOperation());
    assertEquals(new Integer(3333), container.getCommentId());
    assertEquals(CommentScope.GLOBAL, container.getScope());
}
Also used : CommentNotification(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) InstructionCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.InstructionCommentNotificationContainer) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 5 with InstructionCommentNotificationContainer

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

Aggregations

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