Search in sources :

Example 36 with MaybeNullException

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

the class ThreadClosedSynchronizer method handleSuccess.

@Override
protected void handleSuccess(final ThreadClosedReply reply) {
    final ProcessManager processManager = getDebugger().getProcessManager();
    final long tid = reply.getThreadId();
    try {
        processManager.removeThread(processManager.getThread(tid));
    } catch (final MaybeNullException e) {
        CUtilityFunctions.logException(e);
    }
}
Also used : MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) ProcessManager(com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessManager)

Example 37 with MaybeNullException

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

the class SuspendThreadSynchronizer method handleSuccess.

@Override
protected void handleSuccess(final SuspendThreadReply reply) {
    try {
        final TargetProcessThread thread = getDebugger().getProcessManager().getThread(reply.getThreadId());
        thread.setState(ThreadState.SUSPENDED);
    } catch (final MaybeNullException exception) {
        // Unlike in the error case, this is really a bug.
        NaviLogger.severe("Error: Tried to suspend unknown thread '%d'", reply.getThreadId());
    }
}
Also used : TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)

Example 38 with MaybeNullException

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

the class PostgreSQLNodeFunctions method deleteLocalCodeNodeComment.

/**
 * Deletes a local code node comment from the list of local code node comments associated with the
 * given code node.
 *
 * @param provider The provider to access the database-
 * @param codeNode The code node where the comment will be deletes.
 * @param commentId The id of the comment which will be deleted.
 * @param userId The user id of the currently active user.
 *
 * @throws CouldntDeleteException Thrown if the comment could not be deleted from the database.
 */
public static void deleteLocalCodeNodeComment(final SQLProvider provider, final INaviCodeNode codeNode, final Integer commentId, final Integer userId) throws CouldntDeleteException {
    Preconditions.checkNotNull(provider, "IE02473: provider argument can not be null");
    Preconditions.checkNotNull(codeNode, "IE02474: codeNode argument can not be null");
    Preconditions.checkNotNull(commentId, "IE02475: comment argument can not be null");
    Preconditions.checkNotNull(userId, "IE02476: userId argument can not be null");
    final String function = " { ? = call delete_local_code_node_comment(?, ?, ?, ?) } ";
    try {
        final CallableStatement deleteCommentStatement = provider.getConnection().getConnection().prepareCall(function);
        try {
            deleteCommentStatement.registerOutParameter(1, Types.INTEGER);
            deleteCommentStatement.setInt(2, codeNode.getParentFunction().getModule().getConfiguration().getId());
            deleteCommentStatement.setInt(3, codeNode.getId());
            deleteCommentStatement.setInt(4, commentId);
            deleteCommentStatement.setInt(5, userId);
            deleteCommentStatement.execute();
            deleteCommentStatement.getInt(1);
            if (deleteCommentStatement.wasNull()) {
                throw new IllegalArgumentException("Error: the comment id returned from the database was null");
            }
        } catch (final MaybeNullException exception) {
            throw new CouldntDeleteException(exception);
        } finally {
            deleteCommentStatement.close();
        }
    } catch (final SQLException exception) {
        throw new CouldntDeleteException(exception);
    }
}
Also used : CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) SQLException(java.sql.SQLException) CallableStatement(java.sql.CallableStatement)

Example 39 with MaybeNullException

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

the class PostgreSQLEdgeFunctions method appendGlobalEdgeComment.

/**
 * Appends a global edge comment to the list of global edge comments associated with this edge.
 *
 * @param provider The provider to access the database with.
 * @param edge The Edge where to comment is associated with.
 * @param commentText The text of the comment which will be appended.
 * @param userId The user id of the currently active user.
 *
 * @throws CouldntSaveDataException If the data could not be stored in the database.
 */
public static Integer appendGlobalEdgeComment(final AbstractSQLProvider provider, final INaviEdge edge, final String commentText, final Integer userId) throws CouldntSaveDataException {
    Preconditions.checkNotNull(provider, "IE00482: provider argument can not be null");
    Preconditions.checkNotNull(edge, "IE00483: edge argument can not be null");
    Preconditions.checkNotNull(commentText, "IE00484: commentText argument can not be null");
    Preconditions.checkNotNull(userId, "IE00485: userId argument can not be null");
    final Connection connection = provider.getConnection().getConnection();
    final String function = "{ ? = call append_global_edge_comment(?, ?, ?, ?, ?, ?) }";
    try {
        final int sourceModuleId = getModuleId(edge.getSource());
        final int destinationModuleId = getModuleId(edge.getTarget());
        final IAddress sourceAddress = CViewNodeHelpers.getAddress(edge.getSource());
        final IAddress destinationAddress = CViewNodeHelpers.getAddress(edge.getTarget());
        try {
            final CallableStatement appendCommentFunction = connection.prepareCall(function);
            try {
                appendCommentFunction.registerOutParameter(1, Types.INTEGER);
                appendCommentFunction.setInt(2, sourceModuleId);
                appendCommentFunction.setInt(3, destinationModuleId);
                appendCommentFunction.setObject(4, sourceAddress.toBigInteger(), Types.BIGINT);
                appendCommentFunction.setObject(5, destinationAddress.toBigInteger(), Types.BIGINT);
                appendCommentFunction.setInt(6, userId);
                appendCommentFunction.setString(7, commentText);
                appendCommentFunction.execute();
                final int commentId = appendCommentFunction.getInt(1);
                if (appendCommentFunction.wasNull()) {
                    throw new CouldntSaveDataException("Error: Got an comment id of null from the database");
                }
                return commentId;
            } finally {
                appendCommentFunction.close();
            }
        } catch (final SQLException exception) {
            throw new CouldntSaveDataException(exception);
        }
    } catch (final MaybeNullException exception) {
        throw new CouldntSaveDataException(exception);
    }
}
Also used : MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) SQLException(java.sql.SQLException) CallableStatement(java.sql.CallableStatement) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) Connection(java.sql.Connection) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress)

Example 40 with MaybeNullException

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

the class PostgreSQLEdgeFunctions method deleteGlobalEdgeComment.

/**
 * This function deletes a global edge comment from the database.
 *
 * @param provider The provider to access the database.
 * @param edge The edge 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 deleteGlobalEdgeComment(final AbstractSQLProvider provider, final INaviEdge edge, final Integer commentId, final Integer userId) throws CouldntDeleteException {
    Preconditions.checkNotNull(provider, "IE00505: provider argument can not be null");
    Preconditions.checkNotNull(edge, "IE00506: codeNode argument can not be null");
    Preconditions.checkNotNull(commentId, "IE00507: comment argument can not be null");
    Preconditions.checkNotNull(userId, "IE00508: userId argument can not be null");
    final String function = " { ? = call delete_global_edge_comment(?, ?, ?, ?, ?, ?) } ";
    try {
        final CallableStatement deleteCommentFunction = provider.getConnection().getConnection().prepareCall(function);
        try {
            deleteCommentFunction.registerOutParameter(1, Types.INTEGER);
            deleteCommentFunction.setInt(2, getModuleId(edge.getSource()));
            deleteCommentFunction.setInt(3, getModuleId(edge.getTarget()));
            deleteCommentFunction.setObject(4, ((INaviCodeNode) edge.getSource()).getAddress().toBigInteger(), Types.BIGINT);
            deleteCommentFunction.setObject(5, ((INaviCodeNode) edge.getTarget()).getAddress().toBigInteger(), Types.BIGINT);
            deleteCommentFunction.setInt(6, commentId);
            deleteCommentFunction.setInt(7, 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 (SQLException | MaybeNullException exception) {
        throw new CouldntDeleteException(exception);
    }
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) SQLException(java.sql.SQLException) CallableStatement(java.sql.CallableStatement)

Aggregations

MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)42 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)11 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)11 TargetProcessThread (com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread)10 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)8 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)7 SQLException (java.sql.SQLException)7 ProcessManager (com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessManager)6 CallableStatement (java.sql.CallableStatement)6 ArrayList (java.util.ArrayList)5 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)4 INaviFunctionNode (com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode)4 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)4 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)4 CouldntDeleteException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)3 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)3 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)3 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)3 CConnection (com.google.security.zynamics.binnavi.Database.CConnection)2 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)2