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