use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException in project binnavi by google.
the class PostgreSQLTypeFunctions method loadRawTypes.
/**
* Loads all {@link RawBaseType} for the given module from the database.
*
* @param connection The {@link Connection} to the database.
* @param module The {@link INaviModule} whose types should be loaded from the database.
* @return The list of all loaded base types.
* @throws CouldntLoadDataException Thrown if the raw types coudln't be loaded from the database.
*/
public static List<RawBaseType> loadRawTypes(final Connection connection, final INaviModule module) throws CouldntLoadDataException {
final String query = " SELECT * FROM load_types(?) ";
final List<RawBaseType> rawTypes = new ArrayList<RawBaseType>();
try {
final PreparedStatement statement = connection.prepareStatement(query);
statement.setInt(1, module.getConfiguration().getId());
final ResultSet results = statement.executeQuery();
try {
while (results.next()) {
Integer pointer = results.getInt("pointer");
if (results.wasNull()) {
pointer = null;
}
rawTypes.add(new RawBaseType(results.getInt("id"), results.getString("name"), results.getInt("size"), pointer, results.getBoolean("signed"), BaseTypeCategory.fromString(results.getString("category"))));
}
} finally {
results.close();
statement.close();
}
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
return rawTypes;
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException in project binnavi by google.
the class PostgreSQLTypeFunctions method loadRawTypeInstanceReference.
/**
* Loads a single {@link RawTypeInstanceReference cross reference} from the database.
*
* @param provider The {@link SQLProvider} to access the database with.
* @param module The {@link INaviModule} the {@link RawTypeInstanceReference cross reference} is
* associated to.
* @param typeInstanceId The id of the {@link RawTypeInstance type instance} this
* {@link RawTypeInstanceReference cross reference} references.
* @param address The {@link INaviInstruction instruction} address where this
* {@link RawTypeInstanceReference cross reference} is associated to.
* @param position The {@link INaviOperandTree operand tree} position to which this
* {@link RawTypeInstanceReference type reference} is associated to.
* @param expressionId The {@link INaviOperandTreeNode operand node} where this
* {@link RawTypeInstanceReference type reference} is associated to.
*
* @return The {@link RawTypeInstanceReference type reference} from the database which matches the
* given arguments.
* @throws CouldntLoadDataException
*/
public static RawTypeInstanceReference loadRawTypeInstanceReference(final SQLProvider provider, final INaviModule module, final Integer typeInstanceId, final BigInteger address, final Integer position, final Integer expressionId) throws CouldntLoadDataException {
Preconditions.checkNotNull(provider, "Error: provider argument can not be null");
Preconditions.checkNotNull(module, "Error: module argument can not be null");
Preconditions.checkNotNull(typeInstanceId, "Error: typeInstanceId argument can not be null");
Preconditions.checkNotNull(address, "Error: address argument can not be null");
Preconditions.checkNotNull(position, "Error: position argument can not be null");
Preconditions.checkNotNull(expressionId, "Error: expressionId argument can not be null");
final String query = " SELECT * FROM load_expression_type_instance(?, ?, ?, ?, ?) ";
try {
final PreparedStatement statement = provider.getConnection().getConnection().prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
statement.setInt(1, module.getConfiguration().getId());
statement.setInt(2, typeInstanceId);
statement.setObject(3, address, Types.BIGINT);
statement.setInt(4, position);
statement.setInt(5, expressionId);
final ResultSet resultSet = statement.executeQuery();
try {
while (resultSet.next()) {
if (resultSet.isFirst()) {
final int viewId = resultSet.getInt("view_id");
final int moduleId = resultSet.getInt("module_id");
return new RawTypeInstanceReference(moduleId, viewId, new CAddress(address), position, expressionId, typeInstanceId);
}
}
} finally {
resultSet.close();
statement.close();
}
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
throw new CouldntLoadDataException("Error: could not load single cross reference from the database.");
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException in project binnavi by google.
the class PostgreSQLTypeFunctions method loadRawTypeSubstitutions.
/**
* Loads all {@link RawTypeSubstitution} for the given module from the database.
*
* @param connection The {@link Connection} to access the database with.
* @param module The {@link INaviModule} to load the {@link RawTypeSubstitution} for.
*
* @return The {@link List} of {@link RawTypeSubstitution} for the given {@link INaviModule}.
*
* @throws CouldntLoadDataException if the {@link RawTypeSubstitution} could not be loaded from
* the database.
*/
public static List<RawTypeSubstitution> loadRawTypeSubstitutions(final Connection connection, final INaviModule module) throws CouldntLoadDataException {
Preconditions.checkNotNull(connection, "Error: connection argument can not be null");
Preconditions.checkNotNull(module, "Error: module argument can not be null");
final String query = " SELECT * FROM load_type_substitutions(?) ";
final List<RawTypeSubstitution> rawSubstitutions = new ArrayList<RawTypeSubstitution>();
try {
final PreparedStatement statement = connection.prepareStatement(query);
statement.setInt(1, module.getConfiguration().getId());
final ResultSet results = statement.executeQuery();
try {
while (results.next()) {
final long address = results.getLong("address");
final int position = results.getInt("position");
final int expressionId = results.getInt("expression_id");
final int baseTypeId = results.getInt("base_type_id");
final Array arr = results.getArray("path");
Integer[] path = (Integer[]) arr.getArray();
if (results.wasNull()) {
path = new Integer[0];
}
Integer offset = results.getInt("offset");
if (results.wasNull()) {
offset = null;
}
rawSubstitutions.add(new RawTypeSubstitution(new CAddress(address), position, expressionId, baseTypeId, path, offset));
}
} finally {
results.close();
statement.close();
}
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
return rawSubstitutions;
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException in project binnavi by google.
the class PostgreSQLDataFunctions method loadData.
/**
* Loads the data of a module from the database.
*
* The module must be a module stored in the database.
*
* @param provider Provides the connection to the database.
* @param module The module whose data is loaded.
*
* @return The module data loaded from the database.
*
* @throws CouldntLoadDataException Thrown if the module data could not be loaded.
*/
public static byte[] loadData(final AbstractSQLProvider provider, final CModule module) throws CouldntLoadDataException {
Preconditions.checkNotNull(provider, "IE01265: Provider argument can not be null");
Preconditions.checkNotNull(module, "IE01266: Module argument can not be null");
Preconditions.checkArgument(module.inSameDatabase(provider), "IE00532: Module is not stored in the given database");
try {
return ByteHelpers.combine(loadDataChunks(provider, module));
} catch (final SQLException e) {
throw new CouldntLoadDataException(e);
}
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException in project binnavi by google.
the class PostgreSQLDatabaseFunctions method loadProjects.
/**
* Loads the projects of a database.
*
* @param provider The SQL provider that provides the connection.
* @param debuggerManager Debugger manager object that belongs to the given database.
*
* @return A list of projects that contains the projects stored in the database.
*
* @throws CouldntLoadDataException Thrown if the projects could not be loaded from the database.
*/
public static List<INaviProject> loadProjects(final AbstractSQLProvider provider, final DebuggerTemplateManager debuggerManager) throws CouldntLoadDataException {
PostgreSQLDatabaseFunctions.checkArguments(provider, debuggerManager);
final CConnection connection = provider.getConnection();
final List<INaviProject> projects = new ArrayList<>();
if (!PostgreSQLHelpers.hasTable(connection, CTableNames.PROJECTS_TABLE)) {
return projects;
}
String query = "SELECT id, name, description, creation_date, modification_date, " + " (SELECT count(*) FROM " + CTableNames.ADDRESS_SPACES_TABLE + " WHERE project_id = " + CTableNames.PROJECTS_TABLE + ".id) " + " AS addressspace_count FROM " + CTableNames.PROJECTS_TABLE;
try (ResultSet resultSet = connection.executeQuery(query, true)) {
while (resultSet.next()) {
final int projectId = resultSet.getInt("id");
final String name = PostgreSQLHelpers.readString(resultSet, "name");
final String description = PostgreSQLHelpers.readString(resultSet, "description");
final int addressSpaceCount = resultSet.getInt("addressspace_count");
final Timestamp creationDate = resultSet.getTimestamp("creation_date");
final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
final List<DebuggerTemplate> debuggers = PostgreSQLDatabaseFunctions.getAssignedDebuggers(connection, projectId, debuggerManager);
projects.add(new CProject(projectId, name, description == null ? "" : description, creationDate, modificationDate, addressSpaceCount, debuggers, provider));
}
} catch (final SQLException e) {
throw new CouldntLoadDataException(e);
}
return new ArrayList<INaviProject>(projects);
}
Aggregations