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());
}
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());
}
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());
}
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());
}
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);
}
Aggregations