Search in sources :

Example 1 with ImmutableNaviViewConfiguration

use of com.google.security.zynamics.binnavi.disassembly.views.ImmutableNaviViewConfiguration in project binnavi by google.

the class PostgreSQLProjectFlowgraphsLoader method loadFlowGraphInformation.

public static ImmutableNaviViewConfiguration loadFlowGraphInformation(final SQLProvider provider, final INaviProject project, final Integer viewId) throws CouldntLoadDataException {
    Preconditions.checkNotNull(provider, "IE02618: provider argument can not be null");
    Preconditions.checkNotNull(project, "IE02619: project argument can not be null");
    Preconditions.checkNotNull(viewId, "IE02620: viewId argument can not be null");
    final CConnection connection = provider.getConnection();
    final String query = " SELECT * FROM load_project_flowGraph(?,?) ";
    try {
        final PreparedStatement statement = connection.getConnection().prepareStatement(query);
        statement.setInt(1, project.getConfiguration().getId());
        statement.setInt(2, viewId);
        final ResultSet resultSet = statement.executeQuery();
        while (resultSet.next()) {
            final int databaseViewId = resultSet.getInt("view_id");
            final String name = PostgreSQLHelpers.readString(resultSet, "name");
            final String description = PostgreSQLHelpers.readString(resultSet, "description");
            final ViewType viewType = resultSet.getString("type").equalsIgnoreCase("native") ? ViewType.Native : ViewType.NonNative;
            final Timestamp creationDate = resultSet.getTimestamp("creation_date");
            final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
            final boolean isStared = resultSet.getBoolean("stared");
            final int nodeCount = resultSet.getInt("bbcount");
            final int edgeCount = resultSet.getInt("edgecount");
            final ImmutableNaviViewConfiguration viewConfiguration = new ImmutableNaviViewConfiguration(databaseViewId, name, description, viewType, creationDate, modificationDate, isStared, nodeCount, edgeCount);
            return viewConfiguration;
        }
        return null;
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException(exception);
    }
}
Also used : CConnection(com.google.security.zynamics.binnavi.Database.CConnection) ImmutableNaviViewConfiguration(com.google.security.zynamics.binnavi.disassembly.views.ImmutableNaviViewConfiguration) SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp) ViewType(com.google.security.zynamics.zylib.disassembly.ViewType)

Example 2 with ImmutableNaviViewConfiguration

use of com.google.security.zynamics.binnavi.disassembly.views.ImmutableNaviViewConfiguration in project binnavi by google.

the class PostgreSQLViewNotificationParser method informProjectNotification.

/**
   * The inform function for notifications from the bn_project_views table. This function is used
   * when a project view is created or deleted.
   *
   * @param projectNotificationContainer The {@link ViewNotificationContainer} to use as data
   *        source.
   * @param provider The {@link SQLProvider} to access the database.
   * @throws CouldntLoadDataException if the information could not be loaded from the database.
   */
private void informProjectNotification(final ViewNotificationContainer projectNotificationContainer, final SQLProvider provider) throws CouldntLoadDataException {
    if (projectNotificationContainer.getDatabaseOperation().equals("INSERT")) {
        final INaviProject project = projectNotificationContainer.getNotificationProject().get();
        if (!project.isLoaded()) {
            return;
        }
        final Integer viewId = projectNotificationContainer.getViewId();
        final ImmutableNaviViewConfiguration databaseViewConfiguration = provider.loadFlowGraphInformation(project, viewId);
        final CProjectViewGenerator generator = new CProjectViewGenerator(provider, project);
        final INaviView view = generator.generate(databaseViewConfiguration);
        project.getContent().addView(view);
    }
    if (projectNotificationContainer.getDatabaseOperation().equals("UPDATE")) {
        // updates will not happen as this is only a mapping of id to id.
        return;
    }
    if (projectNotificationContainer.getDatabaseOperation().equals("DELETE")) {
        final INaviProject project = projectNotificationContainer.getNotificationProject().get();
        if (!project.isLoaded()) {
            return;
        }
        final Integer viewId = projectNotificationContainer.getViewId();
        final INaviView view = ViewManager.get(provider).getView(viewId);
        project.getContent().deleteViewInternal(view);
    }
}
Also used : ImmutableNaviViewConfiguration(com.google.security.zynamics.binnavi.disassembly.views.ImmutableNaviViewConfiguration) INaviProject(com.google.security.zynamics.binnavi.disassembly.INaviProject) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) CProjectViewGenerator(com.google.security.zynamics.binnavi.Database.CProjectViewGenerator)

Example 3 with ImmutableNaviViewConfiguration

use of com.google.security.zynamics.binnavi.disassembly.views.ImmutableNaviViewConfiguration in project binnavi by google.

the class PostgreSQLViewNotificationParser method informModuleNotification.

/**
   * The inform function for notifications from the bn_module_views table. This function is used
   * when a module view is created or deleted.
   *
   * @param moduleViewNotificationContainer The {@link ViewNotificationContainer} to use as data
   *        source.
   * @param provider The {@link SQLProvider} to access the database.
   * @throws CouldntLoadDataException if the information could not be loaded from the database.
   */
private void informModuleNotification(final ViewNotificationContainer moduleViewNotificationContainer, final SQLProvider provider) throws CouldntLoadDataException {
    if (moduleViewNotificationContainer.getDatabaseOperation().equals("INSERT")) {
        final INaviModule module = moduleViewNotificationContainer.getNotificationModule().get();
        if (!module.isLoaded()) {
            return;
        }
        final Integer viewId = moduleViewNotificationContainer.getViewId();
        final ImmutableNaviViewConfiguration databaseViewConfiguration = provider.loadFlowGraphInformation(module, viewId);
        final CModuleViewGenerator generator = new CModuleViewGenerator(provider, module);
        final INaviView view = generator.generate(databaseViewConfiguration, GraphType.FLOWGRAPH);
        module.getContent().getViewContainer().addView(view);
    }
    if (moduleViewNotificationContainer.getDatabaseOperation().equals("UPDATE")) {
        // updates will not happen as this is only a mapping of id to id.
        return;
    }
    if (moduleViewNotificationContainer.getDatabaseOperation().equals("DELETE")) {
        final INaviModule module = moduleViewNotificationContainer.getNotificationModule().get();
        if (!module.isLoaded()) {
            return;
        }
        final Integer viewId = moduleViewNotificationContainer.getViewId();
        final INaviView view = ViewManager.get(provider).getView(viewId);
        module.getContent().getViewContainer().deleteViewInternal(view);
    }
}
Also used : ImmutableNaviViewConfiguration(com.google.security.zynamics.binnavi.disassembly.views.ImmutableNaviViewConfiguration) CModuleViewGenerator(com.google.security.zynamics.binnavi.Database.CModuleViewGenerator) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule)

Example 4 with ImmutableNaviViewConfiguration

use of com.google.security.zynamics.binnavi.disassembly.views.ImmutableNaviViewConfiguration in project binnavi by google.

the class PostgreSQLViewNotificationParser method informViewNotification.

/**
   * The inform function for notifications from the bn_views table. This function is used when a
   * view gets edited. But this function will not perform any action when a view is deleted or
   * created.
   *
   * @param viewNotificationContainer The {@link ViewNotificationContainer} to use as data source.
   * @param provider The {@link SQLProvider} to access the database with.
   * @throws CouldntLoadDataException if the information could not be loaded from the database.
   */
private void informViewNotification(final ViewNotificationContainer viewNotificationContainer, final SQLProvider provider) throws CouldntLoadDataException {
    if (viewNotificationContainer.getDatabaseOperation().equals("INSERT")) {
        // we ignore inserts as we need to know if this was a module or project view.
        return;
    }
    if (viewNotificationContainer.getDatabaseOperation().equals("UPDATE")) {
        final Integer viewId = viewNotificationContainer.getViewId();
        final INaviView view = viewNotificationContainer.getView().get();
        final ImmutableNaviViewConfiguration databaseViewConfiguration = view.getConfiguration().getModule() == null ? provider.loadFlowGraphInformation(view.getConfiguration().getProject(), viewId) : provider.loadFlowGraphInformation(view.getConfiguration().getModule(), viewId);
        if (databaseViewConfiguration == null) {
            return;
        }
        if (!databaseViewConfiguration.getName().equals(view.getConfiguration().getName())) {
            view.getConfiguration().setNameInternal(databaseViewConfiguration.getName());
        }
        if (databaseViewConfiguration.getDescription() != view.getConfiguration().getDescription() && !databaseViewConfiguration.getDescription().equals(view.getConfiguration().getDescription())) {
            view.getConfiguration().setDescriptionInternal(databaseViewConfiguration.getDescription());
        }
        if (databaseViewConfiguration.getStarState() != view.getConfiguration().isStared()) {
            view.getConfiguration().setStaredInternal(databaseViewConfiguration.getStarState());
        }
        view.getConfiguration().setModificationDateInternal(databaseViewConfiguration.getModificationDate());
    }
    if (viewNotificationContainer.getDatabaseOperation().equals("DELETE")) {
        // we ignore deletes as we need to know if this was a module or project view.
        return;
    }
}
Also used : ImmutableNaviViewConfiguration(com.google.security.zynamics.binnavi.disassembly.views.ImmutableNaviViewConfiguration) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView)

Example 5 with ImmutableNaviViewConfiguration

use of com.google.security.zynamics.binnavi.disassembly.views.ImmutableNaviViewConfiguration in project binnavi by google.

the class PostgreSQLModuleFlowgraphsLoader method loadFlowGraphInformation.

public static ImmutableNaviViewConfiguration loadFlowGraphInformation(final SQLProvider provider, final INaviModule module, final Integer viewId) throws CouldntLoadDataException {
    Preconditions.checkNotNull(provider, "IE02275: provider argument can not be null");
    Preconditions.checkNotNull(module, "IE02394: module argument can not be null");
    Preconditions.checkNotNull(viewId, "IE02419: viewId argument can not be null");
    final CConnection connection = provider.getConnection();
    final String query = " SELECT * FROM load_module_flowgraph_information(?,?) ";
    try {
        final PreparedStatement statement = connection.getConnection().prepareStatement(query);
        statement.setInt(1, module.getConfiguration().getId());
        statement.setInt(2, viewId);
        final ResultSet resultSet = statement.executeQuery();
        while (resultSet.next()) {
            final int databaseViewId = resultSet.getInt("view_id");
            final String name = PostgreSQLHelpers.readString(resultSet, "name");
            final String description = PostgreSQLHelpers.readString(resultSet, "description");
            final ViewType viewType = resultSet.getString("type").equalsIgnoreCase("native") ? ViewType.Native : ViewType.NonNative;
            final Timestamp creationDate = resultSet.getTimestamp("creation_date");
            final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
            final boolean isStared = resultSet.getBoolean("stared");
            final int nodeCount = resultSet.getInt("bbcount");
            final int edgeCount = resultSet.getInt("edgecount");
            final ImmutableNaviViewConfiguration viewConfiguration = new ImmutableNaviViewConfiguration(databaseViewId, name, description, viewType, creationDate, modificationDate, isStared, nodeCount, edgeCount);
            return viewConfiguration;
        }
        return null;
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException(exception);
    }
}
Also used : CConnection(com.google.security.zynamics.binnavi.Database.CConnection) ImmutableNaviViewConfiguration(com.google.security.zynamics.binnavi.disassembly.views.ImmutableNaviViewConfiguration) SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp) ViewType(com.google.security.zynamics.zylib.disassembly.ViewType)

Aggregations

ImmutableNaviViewConfiguration (com.google.security.zynamics.binnavi.disassembly.views.ImmutableNaviViewConfiguration)5 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)3 CConnection (com.google.security.zynamics.binnavi.Database.CConnection)2 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)2 ViewType (com.google.security.zynamics.zylib.disassembly.ViewType)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Timestamp (java.sql.Timestamp)2 CModuleViewGenerator (com.google.security.zynamics.binnavi.Database.CModuleViewGenerator)1 CProjectViewGenerator (com.google.security.zynamics.binnavi.Database.CProjectViewGenerator)1 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)1 INaviProject (com.google.security.zynamics.binnavi.disassembly.INaviProject)1