Search in sources :

Example 16 with CouldntLoadDataException

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;
}
Also used : RawBaseType(com.google.security.zynamics.binnavi.disassembly.types.RawBaseType) BigInteger(java.math.BigInteger) SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 17 with CouldntLoadDataException

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.");
}
Also used : SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ResultSet(java.sql.ResultSet) RawTypeInstanceReference(com.google.security.zynamics.binnavi.disassembly.types.RawTypeInstanceReference) PreparedStatement(java.sql.PreparedStatement) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 18 with CouldntLoadDataException

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;
}
Also used : SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Array(java.sql.Array) BigInteger(java.math.BigInteger) ResultSet(java.sql.ResultSet) RawTypeSubstitution(com.google.security.zynamics.binnavi.disassembly.types.RawTypeSubstitution)

Example 19 with CouldntLoadDataException

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);
    }
}
Also used : SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)

Example 20 with CouldntLoadDataException

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);
}
Also used : CProject(com.google.security.zynamics.binnavi.disassembly.CProject) DebuggerTemplate(com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate) SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ArrayList(java.util.ArrayList) Timestamp(java.sql.Timestamp) CConnection(com.google.security.zynamics.binnavi.Database.CConnection) INaviProject(com.google.security.zynamics.binnavi.disassembly.INaviProject) ResultSet(java.sql.ResultSet)

Aggregations

CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)85 SQLException (java.sql.SQLException)53 ResultSet (java.sql.ResultSet)47 ArrayList (java.util.ArrayList)30 PreparedStatement (java.sql.PreparedStatement)27 CConnection (com.google.security.zynamics.binnavi.Database.CConnection)20 LoadCancelledException (com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException)17 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)16 HashMap (java.util.HashMap)12 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)10 BigInteger (java.math.BigInteger)9 CPartialLoadException (com.google.security.zynamics.binnavi.Database.Exceptions.CPartialLoadException)8 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)8 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)8 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)8 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)7 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)6 Set (java.util.Set)6 CouldntDeleteException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)5 CDefaultProgressOperation (com.google.security.zynamics.binnavi.Gui.Progress.CDefaultProgressOperation)5