Search in sources :

Example 1 with INaviProject

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

the class PostgreSQLDatabaseFunctions method loadProjects.

/**
   * Loads the projects of a database.
   * 
   * @param provider The SQL provider that provides the connection.
   * @param debuggerManager Debugger manager object that belongs to the given database.
   * 
   * @return A list of projects that contains the projects stored in the database.
   * 
   * @throws CouldntLoadDataException Thrown if the projects could not be loaded from the database.
   */
public static List<INaviProject> loadProjects(final AbstractSQLProvider provider, final DebuggerTemplateManager debuggerManager) throws CouldntLoadDataException {
    PostgreSQLDatabaseFunctions.checkArguments(provider, debuggerManager);
    final CConnection connection = provider.getConnection();
    final List<INaviProject> projects = new ArrayList<>();
    if (!PostgreSQLHelpers.hasTable(connection, CTableNames.PROJECTS_TABLE)) {
        return projects;
    }
    String query = "SELECT id, name, description, creation_date, modification_date, " + " (SELECT count(*) FROM " + CTableNames.ADDRESS_SPACES_TABLE + " WHERE project_id = " + CTableNames.PROJECTS_TABLE + ".id) " + " AS addressspace_count FROM " + CTableNames.PROJECTS_TABLE;
    try (ResultSet resultSet = connection.executeQuery(query, true)) {
        while (resultSet.next()) {
            final int projectId = resultSet.getInt("id");
            final String name = PostgreSQLHelpers.readString(resultSet, "name");
            final String description = PostgreSQLHelpers.readString(resultSet, "description");
            final int addressSpaceCount = resultSet.getInt("addressspace_count");
            final Timestamp creationDate = resultSet.getTimestamp("creation_date");
            final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
            final List<DebuggerTemplate> debuggers = PostgreSQLDatabaseFunctions.getAssignedDebuggers(connection, projectId, debuggerManager);
            projects.add(new CProject(projectId, name, description == null ? "" : description, creationDate, modificationDate, addressSpaceCount, debuggers, provider));
        }
    } catch (final SQLException e) {
        throw new CouldntLoadDataException(e);
    }
    return new ArrayList<INaviProject>(projects);
}
Also used : CProject(com.google.security.zynamics.binnavi.disassembly.CProject) DebuggerTemplate(com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate) SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ArrayList(java.util.ArrayList) Timestamp(java.sql.Timestamp) CConnection(com.google.security.zynamics.binnavi.Database.CConnection) INaviProject(com.google.security.zynamics.binnavi.disassembly.INaviProject) ResultSet(java.sql.ResultSet)

Example 2 with INaviProject

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

the class CDatabaseFunctions method deleteProjects.

/**
   * Deletes a project from the database.
   * 
   * @param parent Parent frame used for dialogs.
   * @param database The database the project belongs to.
   * @param projects The project to be deleted.
   * @param updater Updates the project tree if deletion was successful.
   */
public static void deleteProjects(final JFrame parent, final IDatabase database, final INaviProject[] projects, final ITreeUpdater updater) {
    if (CMessageBox.showYesNoQuestion(parent, String.format("Do you really want to delete the following projects?\n\n%s", CNameListGenerators.getNameList(projects))) == JOptionPane.YES_OPTION) {
        for (final INaviProject project : projects) {
            new Thread() {

                @Override
                public void run() {
                    final CDefaultProgressOperation operation = new CDefaultProgressOperation("", false, true);
                    operation.getProgressPanel().setMaximum(1);
                    operation.getProgressPanel().setText("Deleting project" + ": " + project.getConfiguration().getName());
                    try {
                        database.getContent().delete(project);
                        operation.getProgressPanel().next();
                        updater.update();
                    } catch (final CouldntDeleteException exception) {
                        CUtilityFunctions.logException(exception);
                        final String message = "E00032: " + "Project could not be deleted";
                        final String description = CUtilityFunctions.createDescription(String.format("The project '%s' could not be deleted. " + "Try to delete the project again. If the problem persists, " + "disconnect from and reconnect to the database, " + "restart BinNavi, or contact the BinNavi support.", project.getConfiguration().getName()), new String[] { "Database connection problems." }, new String[] { "The project still exists." });
                        NaviErrorDialog.show(parent, message, description, exception);
                    } finally {
                        operation.stop();
                    }
                }
            }.start();
        }
    }
}
Also used : CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException) INaviProject(com.google.security.zynamics.binnavi.disassembly.INaviProject) CDefaultProgressOperation(com.google.security.zynamics.binnavi.Gui.Progress.CDefaultProgressOperation)

Example 3 with INaviProject

use of com.google.security.zynamics.binnavi.disassembly.INaviProject 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 4 with INaviProject

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

the class PostgreSQLProviderTest method testCProjectFunctionsgetViewsWithAddresses4.

@Test(expected = NullPointerException.class)
public void testCProjectFunctionsgetViewsWithAddresses4() throws CouldntLoadDataException {
    final INaviProject project = getProvider().loadProjects().get(0);
    PostgreSQLProjectFunctions.getViewsWithAddresses((AbstractSQLProvider) getProvider(), project, null, true);
}
Also used : INaviProject(com.google.security.zynamics.binnavi.disassembly.INaviProject) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 5 with INaviProject

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

the class PostgreSQLProviderTest method testCSettingsFunctionsReadSettings2.

@Test
public void testCSettingsFunctionsReadSettings2() throws CouldntLoadDataException {
    final INaviProject project = getProvider().loadProjects().get(0);
    PostgreSQLSettingsFunctions.readSetting((AbstractSQLProvider) getProvider(), project, "key");
}
Also used : INaviProject(com.google.security.zynamics.binnavi.disassembly.INaviProject) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Aggregations

INaviProject (com.google.security.zynamics.binnavi.disassembly.INaviProject)45 Test (org.junit.Test)31 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)27 TraceList (com.google.security.zynamics.binnavi.debug.models.trace.TraceList)6 ViewNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.ViewNotificationContainer)5 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)4 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)4 PostgreSQLViewNotificationParser (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.parsers.PostgreSQLViewNotificationParser)4 CProject (com.google.security.zynamics.binnavi.disassembly.CProject)4 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)4 MockProject (com.google.security.zynamics.binnavi.disassembly.MockProject)4 LoadCancelledException (com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException)3 CAddressSpace (com.google.security.zynamics.binnavi.disassembly.AddressSpaces.CAddressSpace)3 UnrelocatedAddress (com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress)3 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)3 SQLException (java.sql.SQLException)3 ArrayList (java.util.ArrayList)3 CouldntConnectException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntConnectException)2 CouldntInitializeDatabaseException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntInitializeDatabaseException)2 CouldntLoadDriverException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDriverException)2