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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations