use of com.google.security.zynamics.binnavi.Database.CConnection in project binnavi by google.
the class PostgreSQLInstructionFunctions method appendGlobalInstructionComment.
/**
* This function appends a global instruction comment to the list of global
* instruction comments associated with this instruction in the database.
*
* @param provider The provider to access the database.
* @param instruction The instruction to which the comment is associated.
* @param commentText The comment text of the comment.
* @param userId The user id of the currently active user.
* @return The id of the comment generated by the database.
*
* @throws CouldntSaveDataException if the comment could not be stored in the
* database.
*/
public static int appendGlobalInstructionComment(final SQLProvider provider, final INaviInstruction instruction, final String commentText, final Integer userId) throws CouldntSaveDataException {
Preconditions.checkNotNull(provider, "IE01648: provider argument can not be null");
Preconditions.checkNotNull(instruction, "IE02040: instruction argument can not be null");
Preconditions.checkNotNull(commentText, "IE02041: commentText argument can not be null");
Preconditions.checkNotNull(userId, "IE02142: userId argument can not be null");
final CConnection connection = provider.getConnection();
final String function = "{ ? = call append_global_instruction_comment(?, ?, ?, ?) }";
try {
final CallableStatement appendCommentFunction = connection.getConnection().prepareCall(function);
try {
appendCommentFunction.registerOutParameter(1, Types.INTEGER);
appendCommentFunction.setInt(2, instruction.getModule().getConfiguration().getId());
appendCommentFunction.setObject(3, instruction.getAddress().toBigInteger(), Types.BIGINT);
appendCommentFunction.setInt(4, userId);
appendCommentFunction.setString(5, 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);
}
}
use of com.google.security.zynamics.binnavi.Database.CConnection in project binnavi by google.
the class PostgreSQLInstructionFunctions method appendLocalInstructionComment.
/**
* This function appends a local instruction comment to the list of local
* instruction comments associated with the given instruction residing in the
* given code node to the database.
*
* @param provider The provider to access the database.
* @param codeNode The code node in which the instruction resides.
* @param instruction The instruction to which the comment is associated.
* @param commentText The text of the comment to be appended.
* @param userId The user id of the currently active user.
* @return The id of the comment generated by the database.
*
* @throws CouldntSaveDataException if the comment could not be stored in the
* database.
*/
public static int appendLocalInstructionComment(final SQLProvider provider, final INaviCodeNode codeNode, final INaviInstruction instruction, final String commentText, final Integer userId) throws CouldntSaveDataException {
Preconditions.checkNotNull(provider, "IE02423: provider argument can not be null");
Preconditions.checkNotNull(codeNode, "IE02424: codeNode argument can not be null");
Preconditions.checkNotNull(instruction, "IE02425: instruction argument can not be null");
Preconditions.checkNotNull(commentText, "IE02426: comment argument can not be null");
Preconditions.checkNotNull(userId, "IE02427: userId argument can not be null");
final CConnection connection = provider.getConnection();
final String function = "{ ? = call append_local_instruction_comment( ?, ?, ?, ?, ?) }";
try {
final CallableStatement appendCommentFunction = connection.getConnection().prepareCall(function);
try {
appendCommentFunction.registerOutParameter(1, Types.INTEGER);
appendCommentFunction.setInt(2, instruction.getModule().getConfiguration().getId());
appendCommentFunction.setInt(3, codeNode.getId());
appendCommentFunction.setObject(4, instruction.getAddress().toBigInteger(), Types.BIGINT);
appendCommentFunction.setInt(5, userId);
appendCommentFunction.setString(6, 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);
}
}
use of com.google.security.zynamics.binnavi.Database.CConnection 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);
}
}
use of com.google.security.zynamics.binnavi.Database.CConnection 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);
}
}
}
use of com.google.security.zynamics.binnavi.Database.CConnection in project binnavi by google.
the class PostgreSQLViewFunctions method getModificationDate.
/**
* Returns the modification date of a view.
*
* @param provider The SQL provider that provides the connection.
* @param view The view whose modification date is determined.
*
* @return The modification date of the view.
*
* @throws CouldntLoadDataException Thrown if the modification date of the view could not be
* determined.
*/
public static Date getModificationDate(final AbstractSQLProvider provider, final INaviView view) throws CouldntLoadDataException {
checkArguments(provider, view);
final CConnection connection = provider.getConnection();
return PostgreSQLHelpers.getModificationDate(connection, CTableNames.VIEWS_TABLE, view.getConfiguration().getId());
}
Aggregations