Search in sources :

Example 11 with CouldntDeleteException

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

the class PostgreSQLEdgeFunctions method deleteLocalEdgeComment.

/**
   * This function deletes a local edge comment from the list of edge comments associated with the
   * edge provided as argument.
   *
   * @param provider The provider to access the database.
   * @param edge The edge where the comment will be deleted.
   * @param commentId The comment id of the comment which will 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 deleteLocalEdgeComment(final AbstractSQLProvider provider, final INaviEdge edge, final Integer commentId, final Integer userId) throws CouldntDeleteException {
    Preconditions.checkNotNull(provider, "IE00509: provider argument can not be null");
    Preconditions.checkNotNull(edge, "IE00510: codeNode argument can not be null");
    Preconditions.checkNotNull(commentId, "IE00511: comment argument can not be null");
    Preconditions.checkNotNull(userId, "IE00512: userId argument can not be null");
    final String function = " { ? = call delete_local_edge_comment(?, ?, ?) } ";
    try {
        final CallableStatement deleteCommentFunction = provider.getConnection().getConnection().prepareCall(function);
        try {
            deleteCommentFunction.registerOutParameter(1, Types.INTEGER);
            deleteCommentFunction.setInt(2, edge.getId());
            deleteCommentFunction.setInt(3, commentId);
            deleteCommentFunction.setInt(4, userId);
            deleteCommentFunction.execute();
            deleteCommentFunction.getInt(1);
            if (deleteCommentFunction.wasNull()) {
                throw new IllegalArgumentException("Error: the comment id returned from the database was null");
            }
        } finally {
            deleteCommentFunction.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)

Example 12 with CouldntDeleteException

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

the class PostgreSQLFunctionFunctions method deleteGlobalFunctionComment.

/**
   * This function deletes a global function comment from the list of comments associated with the
   * function given as argument from the database.
   *
   * @param provider The provider to access the database.
   * @param function The function where the comment is deleted.
   * @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 deleteGlobalFunctionComment(final AbstractSQLProvider provider, final INaviFunction function, final Integer commentId, final Integer userId) throws CouldntDeleteException {
    Preconditions.checkNotNull(provider, "IE01243: provider argument can not be null");
    Preconditions.checkNotNull(function, "IE01245: codeNode argument can not be null");
    Preconditions.checkNotNull(commentId, "IE01247: comment argument can not be null");
    Preconditions.checkNotNull(userId, "IE01308: userId argument can not be null");
    final String deleteFunction = " { ? = call delete_function_comment(?, ?, ?, ?) } ";
    try (CallableStatement deleteCommentStatement = provider.getConnection().getConnection().prepareCall(deleteFunction)) {
        deleteCommentStatement.registerOutParameter(1, Types.INTEGER);
        deleteCommentStatement.setInt(2, function.getModule().getConfiguration().getId());
        deleteCommentStatement.setObject(3, function.getAddress().toBigInteger(), Types.BIGINT);
        deleteCommentStatement.setInt(4, commentId);
        deleteCommentStatement.setInt(5, userId);
        deleteCommentStatement.execute();
        deleteCommentStatement.getInt(1);
        if (deleteCommentStatement.wasNull()) {
            throw new IllegalArgumentException("Error: The comment id returned by the database was null");
        }
    } 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)

Example 13 with CouldntDeleteException

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

the class PostgreSQLInstructionFunctions method deleteReference.

/**
   * Deletes a reference from an operand expression.
   *
   *  The node from which the reference is removed must be stored in the
   * database connected to by the provider argument.
   *
   * @param provider The connection to the database.
   * @param node The operand expression from which the reference is deleted.
   * @param address The target address of the reference to delete.
   * @param type The type of the reference to delete.
   *
   * @throws CouldntDeleteException Thrown if the reference could not be
   *         deleted.
   */
public static void deleteReference(final SQLProvider provider, final INaviOperandTreeNode node, final IAddress address, final ReferenceType type) throws CouldntDeleteException {
    Preconditions.checkNotNull(provider, "IE00476: Provider argument can not be null");
    Preconditions.checkNotNull(node, "IE00477: Node argument can not be null");
    Preconditions.checkNotNull(address, "IE01619: Address argument can not be null");
    Preconditions.checkNotNull(type, "IE00478: Type argument can not be null");
    final CConnection connection = provider.getConnection();
    final BigInteger instructionAddress = node.getInstructionAddress().toBigInteger();
    final int position = node.getOperandPosition();
    final int expressionId = node.getId();
    final BigInteger targetAddress = address.toBigInteger();
    final String deleteQuery = "DELETE FROM " + CTableNames.ADDRESS_REFERENCES_TABLE + " WHERE address = ? AND position = ? AND expression_id = ? AND type = '" + type.toString().toLowerCase() + "' AND target = ?";
    try {
        final PreparedStatement deleteStatement = connection.getConnection().prepareStatement(deleteQuery);
        try {
            deleteStatement.setObject(1, instructionAddress, java.sql.Types.BIGINT);
            deleteStatement.setInt(2, position);
            deleteStatement.setInt(3, expressionId);
            deleteStatement.setObject(4, targetAddress, java.sql.Types.BIGINT);
            deleteStatement.execute();
        } catch (final SQLException exception) {
            throw new CouldntDeleteException(exception);
        } finally {
            deleteStatement.close();
        }
    } catch (final SQLException exception) {
        throw new CouldntDeleteException(exception);
    }
}
Also used : CConnection(com.google.security.zynamics.binnavi.Database.CConnection) CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException) SQLException(java.sql.SQLException) BigInteger(java.math.BigInteger) PreparedStatement(java.sql.PreparedStatement)

Example 14 with CouldntDeleteException

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

the class PostgreSQLViewFunctions method deleteView.

/**
   * Deletes a view from the database.
   * 
   * Note that only non-native views can be deleted from the database.
   * 
   * @param provider The SQL provider that provides the connection.
   * @param view View to delete from the database.
   * 
   * @throws CouldntDeleteException Thrown if the view could not be deleted.
   */
public static void deleteView(final AbstractSQLProvider provider, final INaviView view) throws CouldntDeleteException {
    checkArguments(provider, view);
    Preconditions.checkArgument(view.getType() != ViewType.Native, "IE00614: Native views can not be deleted");
    final CConnection connection = provider.getConnection();
    NaviLogger.info("Deleting view %s", view.getName());
    final int viewId = view.getConfiguration().getId();
    if (!(viewId == -1)) {
        try {
            PostgreSQLHelpers.beginTransaction(connection);
            PostgreSQLHelpers.deleteById(connection, CTableNames.VIEWS_TABLE, viewId);
            PostgreSQLHelpers.deleteByColumnValue(connection, "" + CTableNames.NODES_TABLE + "", "view_id", viewId);
            PostgreSQLHelpers.deleteByColumnValue(connection, "" + CTableNames.TRACES_TABLE + "", "view_id", viewId);
            PostgreSQLHelpers.endTransaction(connection);
        } catch (final SQLException exception) {
            throw new CouldntDeleteException(exception);
        }
    }
}
Also used : CConnection(com.google.security.zynamics.binnavi.Database.CConnection) CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException) SQLException(java.sql.SQLException)

Example 15 with CouldntDeleteException

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

the class PostgreSQLTagFunctions method deleteTag.

/**
   * Deletes a tag from the database.
   * 
   * @param provider The connection to the database.
   * @param tag The tag to delete.
   * 
   * @throws CouldntDeleteException Thrown if the tag could not be deleted.
   */
public static void deleteTag(final AbstractSQLProvider provider, final ITreeNode<CTag> tag) throws CouldntDeleteException {
    checkArguments(provider, tag);
    Preconditions.checkNotNull(tag.getParent(), "IE00558: Can not delete the root tag");
    final CConnection connection = provider.getConnection();
    try {
        final ITreeNode<CTag> parent = tag.getParent();
        final String parentId = parent.getObject().getId() == 0 ? "null" : String.valueOf(parent.getObject().getId());
        final String query_1 = String.format("UPDATE %s SET parent_id = %s WHERE parent_id = ?", CTableNames.TAGS_TABLE, parentId);
        try (PreparedStatement statement_1 = connection.getConnection().prepareStatement(query_1)) {
            statement_1.setInt(1, tag.getObject().getId());
            statement_1.executeUpdate();
        }
        final String query_2 = String.format("DELETE FROM %s WHERE id = ?", CTableNames.TAGS_TABLE);
        try (PreparedStatement statement_2 = connection.getConnection().prepareStatement(query_2)) {
            statement_2.setInt(1, tag.getObject().getId());
            statement_2.executeUpdate();
        }
    } 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) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) PreparedStatement(java.sql.PreparedStatement)

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