Search in sources :

Example 6 with FunctionNotificationContainer

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

the class PostgreSQLFunctionNotificationParserTest method testFunctionInform3Resolve.

@Test
public void testFunctionInform3Resolve() throws CouldntLoadDataException {
    final INaviFunction forwardFunction = new MockFunction(provider);
    function.setForwardedFunctionInternal(forwardFunction);
    assertTrue(function.isForwarded());
    assertEquals(forwardFunction.getAddress(), function.getForwardedFunctionAddress());
    assertEquals(forwardFunction.getModule().getConfiguration().getId(), function.getForwardedFunctionModuleId());
    final FunctionNotificationContainer container = new FunctionNotificationContainer(module.getConfiguration().getId(), module, function.getAddress(), "UPDATE");
    final PostgreSQLFunctionNotificationParser parser = new PostgreSQLFunctionNotificationParser();
    parser.inform(Lists.newArrayList(container), provider);
    assertFalse(function.isForwarded());
    assertNull(function.getForwardedFunctionAddress());
    assertEquals(0, function.getForwardedFunctionModuleId());
}
Also used : MockFunction(com.google.security.zynamics.binnavi.disassembly.MockFunction) FunctionNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.FunctionNotificationContainer) PostgreSQLFunctionNotificationParser(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.parsers.PostgreSQLFunctionNotificationParser) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Test(org.junit.Test)

Example 7 with FunctionNotificationContainer

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

the class PostgreSQLFunctionNotificationParser method parse.

@Override
public Collection<FunctionNotificationContainer> parse(final Collection<PGNotification> notifications, final SQLProvider provider) {
    Preconditions.checkNotNull(notifications, "IE02629: notifications argument can not be null");
    Preconditions.checkNotNull(provider, "IE02630: provider argument can not be null");
    final Collection<FunctionNotificationContainer> containers = new ArrayList<FunctionNotificationContainer>();
    for (final PGNotification notification : notifications) {
        if (notification.getParameter().startsWith(CTableNames.FUNCTIONS_TABLE)) {
            containers.add(parseFunctionNotification(notification, provider));
        } else {
            throw new IllegalStateException("IE02738: Table name supplied in notification: " + notification.getParameter() + " does not match tables where function notifications are accepted on.");
        }
    }
    return containers;
}
Also used : FunctionNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.FunctionNotificationContainer) ArrayList(java.util.ArrayList) PGNotification(org.postgresql.PGNotification)

Example 8 with FunctionNotificationContainer

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

the class PostgreSQLFunctionNotificationParser method parseFunctionNotification.

private FunctionNotificationContainer parseFunctionNotification(final PGNotification notification, final SQLProvider provider) {
    final Pattern pattern = Pattern.compile(functionNotificationPattern);
    final Matcher matcher = pattern.matcher(notification.getParameter());
    if (!matcher.find()) {
        throw new IllegalStateException("IE02739: compiled pattern: " + pattern.toString() + " did not match notification: " + notification.getParameter());
    }
    final String databaseOperation = matcher.group(2);
    final Integer moduleId = Integer.parseInt(matcher.group(3));
    final IAddress functionAddress = new CAddress(new BigInteger(matcher.group(4)));
    final INaviModule module = provider.findModule(moduleId);
    return new FunctionNotificationContainer(moduleId, module, functionAddress, databaseOperation);
}
Also used : BigInteger(java.math.BigInteger) Pattern(java.util.regex.Pattern) FunctionNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.FunctionNotificationContainer) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) Matcher(java.util.regex.Matcher) BigInteger(java.math.BigInteger) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Aggregations

FunctionNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.FunctionNotificationContainer)8 PostgreSQLFunctionNotificationParser (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.parsers.PostgreSQLFunctionNotificationParser)5 Test (org.junit.Test)4 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)2 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)1 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)1 MockFunction (com.google.security.zynamics.binnavi.disassembly.MockFunction)1 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 PGNotification (org.postgresql.PGNotification)1