Search in sources :

Example 1 with CouldntDeleteException

use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException in project binnavi by google.

the class CProjectFunctions method removeAddressSpace.

/**
   * Removes an address spaces from a project.
   * 
   * @param parent Parent window used for dialogs.
   * @param project The project the address space belongs to.
   * @param addressSpaces The address spaces to be removed from the project.
   * @param updater Updates the project tree after the address space was removed.
   */
public static void removeAddressSpace(final JFrame parent, final INaviProject project, final INaviAddressSpace[] addressSpaces, final ITreeUpdater updater) {
    if (CMessageBox.showYesNoQuestion(parent, String.format("Do you really want to delete the following address spaces from the project?\n\n%s", CNameListGenerators.getNameList(addressSpaces))) == JOptionPane.YES_OPTION) {
        for (final INaviAddressSpace addressSpace : addressSpaces) {
            new Thread() {

                @Override
                public void run() {
                    final CDefaultProgressOperation operation = new CDefaultProgressOperation("", false, true);
                    operation.getProgressPanel().setMaximum(1);
                    operation.getProgressPanel().setText("Removing address space" + ": " + addressSpace.getConfiguration().getName());
                    operation.getProgressPanel().next();
                    if (addressSpace.isLoaded()) {
                        addressSpace.close();
                    }
                    if (addressSpace.isLoaded()) {
                        final String innerMessage = "E00123: " + "Address space could not be deleted";
                        final String innerDescription = CUtilityFunctions.createDescription(String.format("BinNavi could not delete the address space '%s'.", addressSpace.getConfiguration().getName()), new String[] { "BinNavi or one of the active plugins vetoed the deletion " + "operation." }, new String[] { "The address space can not be deleted until the delete " + "operation is not vetoed anymore." });
                        NaviErrorDialog.show(parent, innerMessage, innerDescription);
                    } else {
                        try {
                            project.getContent().removeAddressSpace(addressSpace);
                            updater.update();
                        } catch (final CouldntDeleteException exception) {
                            CUtilityFunctions.logException(exception);
                            final String innerMessage = "E00143: " + "Address space could not be deleted";
                            final String innerDescription = CUtilityFunctions.createDescription("The selected address space could not be deleted.", new String[] { "There was a problem with the database connection." }, new String[] { "The address space was not deleted." });
                            NaviErrorDialog.show(parent, innerMessage, innerDescription, exception);
                        }
                    }
                    operation.stop();
                }
            }.start();
        }
    }
}
Also used : CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException) CDefaultProgressOperation(com.google.security.zynamics.binnavi.Gui.Progress.CDefaultProgressOperation) INaviAddressSpace(com.google.security.zynamics.binnavi.disassembly.INaviAddressSpace)

Example 2 with CouldntDeleteException

use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException in project binnavi by google.

the class CDatabaseFunctions method deleteDebuggers.

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

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

Example 3 with CouldntDeleteException

use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException 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 4 with CouldntDeleteException

use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException in project binnavi by google.

the class PostgreSQLModuleFunctions method deleteModule.

/**
   * Deletes a module from the database.
   *
   * The module must be stored in the database connected to by the provider argument.
   *
   * @param provider The SQL provider that provides the connection.
   * @param module The module to be deleted.
   *
   * @throws CouldntDeleteException Thrown if the module could not be deleted.
   */
public static void deleteModule(final AbstractSQLProvider provider, final INaviModule module) throws CouldntDeleteException {
    PostgreSQLModuleFunctions.checkArguments(provider, module);
    NaviLogger.info("Deleting module %s", module.getConfiguration().getName());
    final CConnection connection = provider.getConnection();
    try {
        final String moduleViewQuery = "DELETE FROM " + CTableNames.VIEWS_TABLE + " " + " WHERE id IN (SELECT view_id FROM " + CTableNames.MODULE_VIEWS_TABLE + " WHERE module_id = " + module.getConfiguration().getId() + ")";
        connection.executeUpdate(moduleViewQuery, true);
        final String nodeQuery = "DELETE FROM " + CTableNames.NODES_TABLE + " " + " WHERE id IN " + " (SELECT view_id FROM " + CTableNames.MODULE_VIEWS_TABLE + " WHERE module_id = " + module.getConfiguration().getId() + ")";
        connection.executeUpdate(nodeQuery, true);
        final String instructionsQuery = String.format("DELETE FROM " + CTableNames.INSTRUCTIONS_TABLE + " WHERE module_id = %d", module.getConfiguration().getId());
        connection.executeUpdate(instructionsQuery, true);
        connection.executeUpdate(String.format("delete FROM " + CTableNames.EXPRESSION_TREE_TABLE + "_mapping where module_id = %d", module.getConfiguration().getId()), true);
        connection.executeUpdate(String.format("delete FROM " + CTableNames.EXPRESSION_TREE_TABLE + " where module_id = %d", module.getConfiguration().getId()), true);
        connection.executeUpdate(String.format("delete FROM " + CTableNames.EXPRESSION_TREE_TABLE + "_ids where module_id = %d", module.getConfiguration().getId()), true);
        connection.executeUpdate(String.format("delete FROM " + CTableNames.CODE_NODES_TABLE + " where module_id = %d", module.getConfiguration().getId()), true);
        connection.executeUpdate(String.format("delete from " + CTableNames.MODULES_TABLE + " where id = %d", module.getConfiguration().getId()), true);
    } catch (final SQLException e) {
        throw new CouldntDeleteException(e);
    }
}
Also used : CConnection(com.google.security.zynamics.binnavi.Database.CConnection) CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException) SQLException(java.sql.SQLException)

Example 5 with CouldntDeleteException

use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException in project binnavi by google.

the class PostgreSQLNodeFunctions method deleteGroupNodeComment.

/**
   * Deletes a group node comment from the list of comments associated with the group node given as
   * argument.
   *
   * @param provider The provider to access the database.
   * @param groupNode The group node to which the comment is associated.
   * @param commentId The comment id of the comment to be deleted.
   * @param userId The user id of the currently active user.
   *
   * @throws CouldntDeleteException if the comment could not be deleted from the database.
   */
public static void deleteGroupNodeComment(final SQLProvider provider, final INaviGroupNode groupNode, final Integer commentId, final Integer userId) throws CouldntDeleteException {
    Preconditions.checkNotNull(provider, "IE02469: provider argument can not be null");
    Preconditions.checkNotNull(groupNode, "IE02470: groupNode argument can not be null");
    Preconditions.checkNotNull(commentId, "IE02471: commentId argument can not be null");
    Preconditions.checkNotNull(userId, "IE02472: userId argument can not be null");
    final String function = " { ? = call delete_group_node_comment(?, ?, ?) } ";
    try {
        final CallableStatement deleteCommentStatement = provider.getConnection().getConnection().prepareCall(function);
        try {
            deleteCommentStatement.registerOutParameter(1, Types.INTEGER);
            deleteCommentStatement.setInt(2, groupNode.getId());
            deleteCommentStatement.setInt(3, commentId);
            deleteCommentStatement.setInt(4, userId);
            deleteCommentStatement.execute();
            deleteCommentStatement.getInt(1);
            if (deleteCommentStatement.wasNull()) {
                throw new IllegalArgumentException("Error: the comment id returned from the database was null");
            }
        } finally {
            deleteCommentStatement.close();
        }
    } catch (final SQLException exception) {
        throw new CouldntDeleteException(exception);
    }
}
Also used : CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException) SQLException(java.sql.SQLException) CallableStatement(java.sql.CallableStatement)

Aggregations

CouldntDeleteException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)42 SQLException (java.sql.SQLException)27 CallableStatement (java.sql.CallableStatement)15 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)8 CDefaultProgressOperation (com.google.security.zynamics.binnavi.Gui.Progress.CDefaultProgressOperation)8 CConnection (com.google.security.zynamics.binnavi.Database.CConnection)7 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)5 PreparedStatement (java.sql.PreparedStatement)5 IDatabaseListener (com.google.security.zynamics.binnavi.Database.Interfaces.IDatabaseListener)3 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)3 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)3 TraceList (com.google.security.zynamics.binnavi.debug.models.trace.TraceList)2 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)2 ArrayList (java.util.ArrayList)2 LoadCancelledException (com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException)1 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)1 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)1 IUserManagerListener (com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUserManagerListener)1 DebuggerTemplate (com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate)1 IDebuggerTemplateManagerListener (com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebuggerTemplateManagerListener)1