Search in sources :

Example 11 with IDatabaseListener

use of com.google.security.zynamics.binnavi.Database.Interfaces.IDatabaseListener in project binnavi by google.

the class CDatabaseContent method delete.

@Override
public void delete(final INaviRawModule rawModule) throws CouldntDeleteException {
    Preconditions.checkNotNull(rawModule, "IE00006: Raw module can not be null");
    Preconditions.checkArgument(m_database.isConnected(), "IE00031: Database must be connected before you can delete raw modules");
    Preconditions.checkArgument(m_database.isLoaded(), "IE00036: Database must be loaded before you can delete raw modules");
    Preconditions.checkArgument(m_rawModules.contains(rawModule), "IE00038: Raw module does not belong to this database");
    m_provider.deleteRawModule(rawModule);
    m_rawModules.remove(rawModule);
    for (final IDatabaseListener listener : m_listeners) {
        try {
            listener.deletedRawModule(m_database, rawModule);
        } catch (final Exception exception) {
            CUtilityFunctions.logException(exception);
        }
    }
}
Also used : IDatabaseListener(com.google.security.zynamics.binnavi.Database.Interfaces.IDatabaseListener) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)

Example 12 with IDatabaseListener

use of com.google.security.zynamics.binnavi.Database.Interfaces.IDatabaseListener in project binnavi by google.

the class CDatabaseContent method delete.

@Override
public void delete(final INaviProject project) throws CouldntDeleteException {
    Preconditions.checkNotNull(project, "IE00674: Project can not be null");
    Preconditions.checkArgument(m_database.isConnected(), "IE00675: Database must be connected before you can delete projects");
    Preconditions.checkArgument(m_database.isLoaded(), "IE00676: Database must be loaded before you can delete projects");
    Preconditions.checkArgument(m_projects.contains(project), "IE00677: Project does not belong to the database");
    m_provider.deleteProject(project);
    m_projects.remove(project);
    for (final IDatabaseListener listener : m_listeners) {
        try {
            listener.deletedProject(m_database, project);
        } catch (final Exception exception) {
            CUtilityFunctions.logException(exception);
        }
    }
}
Also used : IDatabaseListener(com.google.security.zynamics.binnavi.Database.Interfaces.IDatabaseListener) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)

Example 13 with IDatabaseListener

use of com.google.security.zynamics.binnavi.Database.Interfaces.IDatabaseListener in project binnavi by google.

the class CDatabaseContent method addProject.

/**
 * Adds a new project to the database.
 *
 * This function is guaranteed to be thread-safe. If the new project could not be saved to the
 * database, the state of the database object remains unchanged.
 *
 * @param name The name of the new project.
 *
 * @return The added project.
 *
 * @throws IllegalArgumentException Thrown if the name of the new project is null.
 * @throws CouldntSaveDataException Thrown if the new project could not be saved to the database.
 */
@Override
public INaviProject addProject(final String name) throws CouldntSaveDataException {
    Preconditions.checkNotNull(name, "IE00661: Project name can not be null");
    Preconditions.checkArgument(m_database.isConnected(), "IE00662: Database must be connected before a project can be added");
    Preconditions.checkArgument(m_database.isLoaded(), "IE00663: Database must be loaded before a project can be added");
    final CProject newProject = m_provider.createProject(name);
    m_projects.add(newProject);
    for (final IDatabaseListener listener : m_listeners) {
        try {
            listener.addedProject(m_database, newProject);
        } catch (final Exception exception) {
            CUtilityFunctions.logException(exception);
        }
    }
    return newProject;
}
Also used : CProject(com.google.security.zynamics.binnavi.disassembly.CProject) IDatabaseListener(com.google.security.zynamics.binnavi.Database.Interfaces.IDatabaseListener) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)

Example 14 with IDatabaseListener

use of com.google.security.zynamics.binnavi.Database.Interfaces.IDatabaseListener in project binnavi by google.

the class CDatabase method connect.

@Override
public void connect() throws CouldntLoadDriverException, CouldntConnectException, InvalidDatabaseException, CouldntInitializeDatabaseException, InvalidExporterDatabaseFormatException, LoadCancelledException {
    loadReporter.start();
    isConnecting = true;
    try {
        final Pair<CConnection, SQLProvider> connectionData = CDatabaseConnection.connect(description, loadReporter);
        provider = connectionData.second();
    } catch (final CouldntLoadDriverException exception) {
        loadReporter.report(LoadEvents.LOADING_FINISHED);
        throw exception;
    } catch (final CouldntConnectException exception) {
        loadReporter.report(LoadEvents.LOADING_FINISHED);
        throw exception;
    } catch (final CouldntInitializeDatabaseException exception) {
        loadReporter.report(LoadEvents.LOADING_FINISHED);
        throw exception;
    } catch (final InvalidDatabaseException exception) {
        loadReporter.report(LoadEvents.LOADING_FINISHED);
        throw exception;
    } catch (final InvalidExporterDatabaseFormatException exception) {
        loadReporter.report(LoadEvents.LOADING_FINISHED);
        throw exception;
    } catch (final LoadCancelledException exception) {
        loadReporter.report(LoadEvents.LOADING_FINISHED);
        throw exception;
    } finally {
        isConnecting = false;
    }
    for (final IDatabaseListener listener : listeners) {
        try {
            listener.openedDatabase(this);
        } catch (final Exception exception) {
            CUtilityFunctions.logException(exception);
        }
    }
    try {
        final PostgreSQLNotificationProvider notificationProvider = PostgreSQLNotificationProvider.initialize(provider, description);
        notificationProvider.listen(NotificationChannel.all());
        notificationProvider.startPolling();
    } catch (final SQLException exception) {
        NaviLogger.severe("Error: Could not establish a channel for receiving notifications from the database %s", exception);
    }
}
Also used : SQLException(java.sql.SQLException) CouldntInitializeDatabaseException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntInitializeDatabaseException) InvalidExporterDatabaseFormatException(com.google.security.zynamics.binnavi.Database.Exceptions.InvalidExporterDatabaseFormatException) SQLProvider(com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider) IDatabaseListener(com.google.security.zynamics.binnavi.Database.Interfaces.IDatabaseListener) LoadCancelledException(com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException) CouldntInitializeDatabaseException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntInitializeDatabaseException) CouldntLoadDriverException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDriverException) InvalidExporterDatabaseFormatException(com.google.security.zynamics.binnavi.Database.Exceptions.InvalidExporterDatabaseFormatException) SQLException(java.sql.SQLException) InvalidDatabaseException(com.google.security.zynamics.binnavi.Database.Exceptions.InvalidDatabaseException) CouldntConnectException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntConnectException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) CouldntUpdateDatabaseException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntUpdateDatabaseException) InvalidDatabaseVersionException(com.google.security.zynamics.binnavi.Database.Exceptions.InvalidDatabaseVersionException) CouldntLoadDriverException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDriverException) PostgreSQLNotificationProvider(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.PostgreSQLNotificationProvider) InvalidDatabaseException(com.google.security.zynamics.binnavi.Database.Exceptions.InvalidDatabaseException) CouldntConnectException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntConnectException) LoadCancelledException(com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException)

Example 15 with IDatabaseListener

use of com.google.security.zynamics.binnavi.Database.Interfaces.IDatabaseListener in project binnavi by google.

the class CDatabase method close.

@Override
public boolean close() {
    Preconditions.checkArgument(isConnected(), "IE00664: Can not disconnect from the database because it is not connected");
    if (PostgreSQLNotificationProvider.contains(provider)) {
        PostgreSQLNotificationProvider.get(provider).unInitialize();
    }
    for (final IDatabaseListener listener : listeners) {
        try {
            if (!listener.closingDatabase(this)) {
                return false;
            }
        } catch (final Exception exception) {
            CUtilityFunctions.logException(exception);
        }
    }
    if (isLoaded()) {
        for (final INaviProject project : content.getProjects()) {
            if (project.isLoaded() && !project.close()) {
                return false;
            }
        }
    }
    provider.close();
    provider = null;
    for (final IDatabaseListener listener : listeners) {
        try {
            listener.closedDatabase(this);
        } catch (final Exception exception) {
            CUtilityFunctions.logException(exception);
        }
    }
    content = null;
    return true;
}
Also used : INaviProject(com.google.security.zynamics.binnavi.disassembly.INaviProject) IDatabaseListener(com.google.security.zynamics.binnavi.Database.Interfaces.IDatabaseListener) LoadCancelledException(com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException) CouldntInitializeDatabaseException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntInitializeDatabaseException) CouldntLoadDriverException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDriverException) InvalidExporterDatabaseFormatException(com.google.security.zynamics.binnavi.Database.Exceptions.InvalidExporterDatabaseFormatException) SQLException(java.sql.SQLException) InvalidDatabaseException(com.google.security.zynamics.binnavi.Database.Exceptions.InvalidDatabaseException) CouldntConnectException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntConnectException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) CouldntUpdateDatabaseException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntUpdateDatabaseException) InvalidDatabaseVersionException(com.google.security.zynamics.binnavi.Database.Exceptions.InvalidDatabaseVersionException)

Aggregations

IDatabaseListener (com.google.security.zynamics.binnavi.Database.Interfaces.IDatabaseListener)15 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)8 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)8 CouldntDeleteException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)5 CouldntConnectException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntConnectException)3 CouldntInitializeDatabaseException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntInitializeDatabaseException)3 CouldntLoadDriverException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDriverException)3 CouldntUpdateDatabaseException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntUpdateDatabaseException)3 InvalidDatabaseException (com.google.security.zynamics.binnavi.Database.Exceptions.InvalidDatabaseException)3 InvalidDatabaseVersionException (com.google.security.zynamics.binnavi.Database.Exceptions.InvalidDatabaseVersionException)3 InvalidExporterDatabaseFormatException (com.google.security.zynamics.binnavi.Database.Exceptions.InvalidExporterDatabaseFormatException)3 LoadCancelledException (com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException)3 SQLException (java.sql.SQLException)3 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)2 INaviProject (com.google.security.zynamics.binnavi.disassembly.INaviProject)2 INaviRawModule (com.google.security.zynamics.binnavi.disassembly.INaviRawModule)2 SQLProvider (com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider)1 PostgreSQLNotificationProvider (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.PostgreSQLNotificationProvider)1 CTagManager (com.google.security.zynamics.binnavi.Tagging.CTagManager)1 DebuggerTemplateManager (com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplateManager)1