Search in sources :

Example 56 with CConnection

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

the class PostgreSQLTraceFunctions method setName.

/**
   * Changes the name of a trace.
   *
   * @param provider The SQL provider that provides the connection.
   * @param trace The trace whose name is changed.
   * @param name The new name of the trace.
   *
   * @throws CouldntSaveDataException Thrown if the name of the trace could not be changed.
   */
public static void setName(final AbstractSQLProvider provider, final TraceList trace, final String name) throws CouldntSaveDataException {
    Preconditions.checkNotNull(provider, "IE00586: Provider argument can not be null");
    Preconditions.checkNotNull(trace, "IE00587: Trace list argument can not be null");
    Preconditions.checkNotNull(name, "IE00588: Name argument can not be null");
    Preconditions.checkArgument(trace.inSameDatabase(provider), "IE00589: Trace list is not part of this database");
    final CConnection connection = provider.getConnection();
    final String query = "UPDATE " + CTableNames.TRACES_TABLE + " SET name = ? WHERE id = ?";
    try {
        final PreparedStatement statement = connection.getConnection().prepareStatement(query);
        try {
            statement.setString(1, name);
            statement.setInt(2, trace.getId());
            statement.executeUpdate();
        } finally {
            statement.close();
        }
    } catch (final SQLException e) {
        throw new CouldntSaveDataException(e);
    }
}
Also used : CConnection(com.google.security.zynamics.binnavi.Database.CConnection) SQLException(java.sql.SQLException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) PreparedStatement(java.sql.PreparedStatement)

Example 57 with CConnection

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

the class PostgreSQLTraceFunctions method deleteTrace.

/**
   * Deletes a trace from the database.
   *
   * @param provider The SQL provider that provides the connection.
   * @param trace The trace to be deleted.
   *
   * @throws CouldntDeleteException Thrown if the trace could not be deleted.
   */
public static void deleteTrace(final AbstractSQLProvider provider, final TraceList trace) throws CouldntDeleteException {
    Preconditions.checkNotNull(provider, "IE00576: Provider argument can not be null");
    Preconditions.checkNotNull(trace, "IE00577: Trace argument can not be null");
    Preconditions.checkArgument(trace.inSameDatabase(provider), "IE00578: Trace list is not part of this database");
    final CConnection connection = provider.getConnection();
    final String query = "DELETE FROM " + CTableNames.TRACES_TABLE + " WHERE id = " + trace.getId();
    try {
        connection.executeUpdate(query, 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 58 with CConnection

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

the class PostgreSQLTraceFunctions method setDescription.

/**
   * Changes the description of a trace.
   *
   * @param provider The SQL provider that provides the connection.
   * @param trace The trace whose description is changed.
   * @param description The new description of the trace.
   *
   * @throws CouldntSaveDataException Thrown if the description of the trace could not be changed.
   */
public static void setDescription(final AbstractSQLProvider provider, final TraceList trace, final String description) throws CouldntSaveDataException {
    Preconditions.checkNotNull(provider, "IE00582: Provider argument can not be null");
    Preconditions.checkNotNull(trace, "IE00583: Trace list argument can not be null");
    Preconditions.checkNotNull(description, "IE00584: Description argument can not be null");
    Preconditions.checkArgument(trace.inSameDatabase(provider), "IE00585: Trace list is not part of this database");
    final CConnection connection = provider.getConnection();
    final String query = "UPDATE " + CTableNames.TRACES_TABLE + " SET description = ? WHERE id = ?";
    try {
        final PreparedStatement statement = connection.getConnection().prepareStatement(query);
        try {
            statement.setString(1, description);
            statement.setInt(2, trace.getId());
            statement.executeUpdate();
        } finally {
            statement.close();
        }
    } catch (final SQLException e) {
        throw new CouldntSaveDataException(e);
    }
}
Also used : CConnection(com.google.security.zynamics.binnavi.Database.CConnection) SQLException(java.sql.SQLException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) PreparedStatement(java.sql.PreparedStatement)

Example 59 with CConnection

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

the class PostgreSQLFunctionFunctions method setName.

/**
   * Changes the name of a function.
   *
   * The function must be stored in the database connected to by the provider argument.
   *
   * @param provider The SQL provider that provides the connection.
   * @param function The function whose name is changed.
   * @param name The new name of the function.
   *
   * @throws CouldntSaveDataException Thrown if storing the new name to the database failed.
   */
public static void setName(final AbstractSQLProvider provider, final INaviFunction function, final String name) throws CouldntSaveDataException {
    Preconditions.checkNotNull(provider, "IE00456: Provider argument can not be null");
    Preconditions.checkNotNull(function, "IE00457: Function argument can not be null");
    Preconditions.checkNotNull(name, "IE00458: Name argument can not be null");
    Preconditions.checkArgument(function.inSameDatabase(provider), "IE00459: Function is not part of this database");
    final CConnection connection = provider.getConnection();
    final int module = function.getModule().getConfiguration().getId();
    final IAddress address = function.getAddress();
    final String query = "UPDATE " + CTableNames.FUNCTIONS_TABLE + " SET name = ? WHERE module_id = ? and address = ?";
    try (PreparedStatement statement = connection.getConnection().prepareStatement(query)) {
        statement.setString(1, name);
        statement.setInt(2, module);
        statement.setObject(3, address.toBigInteger(), java.sql.Types.BIGINT);
        statement.executeUpdate();
    } catch (final SQLException exception) {
        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) PreparedStatement(java.sql.PreparedStatement) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress)

Example 60 with CConnection

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

the class PostgreSQLInstructionFunctions method addReference.

/**
   * Adds a new outgoing reference to an operand expression.
   *
   *  The node for which the reference is added must be stored in the database
   * connected to by the provider argument.
   *
   * @param provider The connection to the database.
   * @param node The operand expression the reference is added to.
   * @param targetAddress The target address of the reference.
   * @param type The type of the reference.
   *
   * @throws CouldntSaveDataException Thrown if the reference could not be
   *         created.
   */
public static void addReference(final SQLProvider provider, final INaviOperandTreeNode node, final IAddress targetAddress, final ReferenceType type) throws CouldntSaveDataException {
    Preconditions.checkNotNull(provider, "IE00473: Provider argument can not be null");
    Preconditions.checkNotNull(node, "IE00474: Node argument can not be null");
    Preconditions.checkNotNull(targetAddress, "IE01548: Address argument can not be null");
    Preconditions.checkNotNull(type, "IE00475: Type argument can not be null");
    final CConnection connection = provider.getConnection();
    final int moduleId = node.getOperand().getInstruction().getModule().getConfiguration().getId();
    final BigInteger address = node.getInstructionAddress().toBigInteger();
    final int position = node.getOperandPosition();
    final int expressionId = node.getId();
    final String query = String.format("INSERT INTO " + CTableNames.ADDRESS_REFERENCES_TABLE + "(module_id, address, position, expression_id, type, target) " + "VALUES(%d, %d, %d, %d, '%s', %s)", moduleId, address, position, expressionId, type.toString().toLowerCase(), targetAddress.toBigInteger().toString());
    try {
        connection.executeUpdate(query, true);
    } catch (final SQLException e) {
        throw new CouldntSaveDataException(e);
    }
}
Also used : CConnection(com.google.security.zynamics.binnavi.Database.CConnection) SQLException(java.sql.SQLException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) BigInteger(java.math.BigInteger)

Aggregations

CConnection (com.google.security.zynamics.binnavi.Database.CConnection)70 SQLException (java.sql.SQLException)59 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)31 PreparedStatement (java.sql.PreparedStatement)25 ResultSet (java.sql.ResultSet)25 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)20 ArrayList (java.util.ArrayList)15 CouldntDeleteException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)7 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)6 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)6 Timestamp (java.sql.Timestamp)6 HashMap (java.util.HashMap)6 Set (java.util.Set)6 DebuggerTemplate (com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate)5 AbstractSQLProvider (com.google.security.zynamics.binnavi.Database.AbstractSQLProvider)4 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)4 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)4 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)4 CallableStatement (java.sql.CallableStatement)4 Test (org.junit.Test)4