Search in sources :

Example 61 with CouldntSaveDataException

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

the class PostgresSQLDebuggerFunctions method setHost.

/**
   * Changes the host of an existing debugger template.
   * 
   * The debugger must be stored in the database the provider argument is connected to.
   * 
   * @param provider The connection to the database.
   * @param debugger The debugger whose host value is changed.
   * @param host The new host value of the debugger template.
   * 
   * @throws CouldntSaveDataException Thrown if the host value could not be updated.
   */
public static void setHost(final AbstractSQLProvider provider, final DebuggerTemplate debugger, final String host) throws CouldntSaveDataException {
    Preconditions.checkNotNull(debugger, "IE00422: Debugger argument can not be null");
    Preconditions.checkNotNull(host, "IE00423: Host argument can not be null");
    Preconditions.checkArgument(debugger.inSameDatabase(provider), "IE00424: Debugger is not part of this database");
    final String query = "UPDATE " + CTableNames.DEBUGGERS_TABLE + " SET host = ? WHERE id = ?";
    try (PreparedStatement statement = provider.getConnection().getConnection().prepareStatement(query)) {
        statement.setString(1, host);
        statement.setInt(2, debugger.getId());
        statement.executeUpdate();
    } catch (final SQLException e) {
        throw new CouldntSaveDataException(e);
    }
}
Also used : SQLException(java.sql.SQLException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) PreparedStatement(java.sql.PreparedStatement)

Example 62 with CouldntSaveDataException

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

the class PostgreSQLViewSaver method save.

/**
   * Saves a view to the database.
   * 
   * @param provider The SQL provider that provides the connection.
   * @param view The view to save to the database.
   * 
   * @throws CouldntSaveDataException Thrown if the view could not be saved to the database.
   */
public static void save(final AbstractSQLProvider provider, final CView view) throws CouldntSaveDataException {
    PostgreSQLViewSaver.checkArguments(provider, view);
    final CConnection connection = provider.getConnection();
    try {
        PostgreSQLHelpers.beginTransaction(connection);
        final int viewId = view.getConfiguration().getId();
        final List<INaviViewNode> nodes = view.getGraph().getNodes();
        final List<INaviEdge> edges = view.getGraph().getEdges();
        PostgreSQLViewSaver.deleteNodes(connection, viewId);
        // Store all nodes
        PostgreSQLNodeSaver.writeNodes(provider, viewId, nodes);
        // Store all edges
        PostgreSQLEdgeSaver.writeEdges(provider, edges);
        PostgreSQLHelpers.endTransaction(connection);
    } catch (final SQLException exception) {
        try {
            PostgreSQLHelpers.rollback(connection);
        } catch (final SQLException e) {
            CUtilityFunctions.logException(e);
        }
        throw new CouldntSaveDataException(exception);
    }
}
Also used : CConnection(com.google.security.zynamics.binnavi.Database.CConnection) SQLException(java.sql.SQLException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge)

Example 63 with CouldntSaveDataException

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

the class PostgreSQLTypeFunctions method updateTypeSubstitution.

/**
   * Updates the given type substitution in the database.
   *
   * @param connection The connection to the database.
   * @param substitution The type substitution to update.
   * @param baseType The new base type for the type substitution.
   * @param position The zero-based index position of the operand within its instruction.
   * @param offset The new offset for the type substitution.
   * @param module The module that contains the type substitution.
   * @throws CouldntSaveDataException Thrown if the type substitution could not be updated in the
   *         database.
   */
public static void updateTypeSubstitution(final Connection connection, final TypeSubstitution substitution, final BaseType baseType, final List<Integer> memberPath, final int position, final int offset, final INaviModule module) throws CouldntSaveDataException {
    try {
        final PreparedStatement statement = connection.prepareStatement("UPDATE " + CTableNames.EXPRESSION_TYPES_TABLE + " SET base_type_id = ?, \"position\" = ?, \"offset\" = ?, path = ? " + "WHERE module_id = ? AND expression_id = ? AND address = ?");
        try {
            statement.setInt(1, baseType.getId());
            statement.setInt(2, position);
            statement.setInt(3, offset);
            statement.setArray(4, connection.createArrayOf("int4", memberPath.toArray()));
            statement.setInt(5, module.getConfiguration().getId());
            statement.setInt(6, substitution.getExpressionId());
            statement.setLong(7, substitution.getAddress().toLong());
            statement.executeUpdate();
        } finally {
            statement.close();
        }
    } catch (final SQLException exception) {
        throw new CouldntSaveDataException(exception);
    }
}
Also used : SQLException(java.sql.SQLException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) PreparedStatement(java.sql.PreparedStatement)

Example 64 with CouldntSaveDataException

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

the class PostgreSQLTypeFunctions method setTypeInstanceName.

/**
   * This function sets the name of a {@link TypeInstance} in the database to the given name.
   *
   * @param provider The {@link SQLProvider} to access the database with.
   * @param moduleId The id of the {@link INaviModule} the {@link TypeInstance} is associated to.
   * @param id The id of the {@link TypeInstance}.
   * @param name The new name of the {@link TypeInstance}.
   *
   * @throws CouldntSaveDataException if the changes to the {@link TypeInstance} name could not be
   *         saved to the database.
   */
public static void setTypeInstanceName(final PostgreSQLProvider provider, final int moduleId, final int id, final String name) throws CouldntSaveDataException {
    Preconditions.checkNotNull(provider, "Error: provider argument can not be null");
    Preconditions.checkArgument(moduleId > 0, "Error: module id must be larger then zero");
    Preconditions.checkArgument(id >= 0, "Error: type instance id must be larger or equal to zero");
    Preconditions.checkNotNull(name, "Error: name argument can not be null");
    final String function = " { call set_type_instance_name(?, ?, ?) } ";
    try {
        final CallableStatement setTypeInstanceNameStatement = provider.getConnection().getConnection().prepareCall(function);
        try {
            setTypeInstanceNameStatement.setInt(1, moduleId);
            setTypeInstanceNameStatement.setInt(2, id);
            setTypeInstanceNameStatement.setString(3, name);
            setTypeInstanceNameStatement.execute();
        } finally {
            setTypeInstanceNameStatement.close();
        }
    } catch (final SQLException exception) {
        throw new CouldntSaveDataException(exception);
    }
}
Also used : SQLException(java.sql.SQLException) CallableStatement(java.sql.CallableStatement) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)

Example 65 with CouldntSaveDataException

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

the class PostgreSQLViewFunctions method saveSettings.

/**
   * Stores the settings map of a view to the database.
   * 
   * @param provider The SQL provider that provides the connection.
   * @param view The view whose settings are stored.
   * @param settings The settings map to store to the database.
   * 
   * @throws CouldntSaveDataException Thrown if the view settings could not be stored in the
   *         database.
   */
public static void saveSettings(final AbstractSQLProvider provider, final CView view, final Map<String, String> settings) throws CouldntSaveDataException {
    checkArguments(provider, view);
    Preconditions.checkNotNull(settings, "IE02414: settings argument can not be null");
    if (settings.isEmpty()) {
        return;
    }
    final CConnection connection = provider.getConnection();
    final StringBuilder deleteQuery = new StringBuilder("DELETE FROM " + CTableNames.VIEW_SETTINGS_TABLE + " WHERE ");
    final StringBuilder insertQuery = new StringBuilder("INSERT INTO " + CTableNames.VIEW_SETTINGS_TABLE + " VALUES");
    boolean first = true;
    for (final Map.Entry<String, String> pair : settings.entrySet()) {
        final String value = pair.getValue();
        final String key = pair.getKey();
        if ((value == null) || (key == null)) {
            continue;
        } else {
            if (!first) {
                deleteQuery.append("OR");
                insertQuery.append(',');
            }
            deleteQuery.append(" (view_id = " + view.getConfiguration().getId() + " AND name = '" + key + "') ");
            insertQuery.append(" (" + view.getConfiguration().getId() + ", '" + key + "', '" + value + "' ) ");
        }
        first = false;
    }
    try {
        connection.executeUpdate(deleteQuery.toString(), true);
        connection.executeUpdate(insertQuery.toString(), true);
    } catch (final SQLException exception) {
        throw new CouldntSaveDataException("E00115: Could not update settings in " + CTableNames.VIEW_SETTINGS_TABLE);
    }
}
Also used : CConnection(com.google.security.zynamics.binnavi.Database.CConnection) SQLException(java.sql.SQLException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)133 SQLException (java.sql.SQLException)71 PreparedStatement (java.sql.PreparedStatement)38 CConnection (com.google.security.zynamics.binnavi.Database.CConnection)35 CallableStatement (java.sql.CallableStatement)20 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)17 CouldntDeleteException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)13 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)10 CDefaultProgressOperation (com.google.security.zynamics.binnavi.Gui.Progress.CDefaultProgressOperation)10 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)9 ArrayList (java.util.ArrayList)9 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)8 CComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment)8 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)8 BigInteger (java.math.BigInteger)8 Connection (java.sql.Connection)8 ResultSet (java.sql.ResultSet)8 TraceList (com.google.security.zynamics.binnavi.debug.models.trace.TraceList)7 LoadCancelledException (com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException)6 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)5