Search in sources :

Example 11 with CouldntLoadDataException

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

the class PostgreSQLSectionFunctions method loadSections.

/**
   * Loads all sections that are associated with the given module.
   * 
   * @param provider The SQL provider that holds the database connection.
   * @param module The module whose sections should be loaded.
   * @return The list of sections loaded from the database.
   * @throws CouldntLoadDataException Thrown if the sections could not be loaded from the database.
   */
public static Map<Section, Integer> loadSections(final SQLProvider provider, final INaviModule module) throws CouldntLoadDataException {
    Preconditions.checkNotNull(provider, "Error: provider argument can not be null");
    Preconditions.checkNotNull(module, "Error: module argument can not be null");
    final HashMap<Section, Integer> sections = Maps.newHashMap();
    final String query = "SELECT * FROM get_sections(?)";
    try (PreparedStatement statement = provider.getConnection().getConnection().prepareStatement(query)) {
        statement.setInt(1, module.getConfiguration().getId());
        final ResultSet result = statement.executeQuery();
        while (result.next()) {
            final int id = result.getInt("id");
            final String name = result.getString("name");
            Integer commentId = result.getInt("comment_id");
            if (result.wasNull()) {
                commentId = null;
            }
            final IAddress startAddress = new CAddress(result.getLong("start_address"));
            final IAddress endAddress = new CAddress(result.getLong("end_address"));
            final SectionPermission permission = SectionPermission.valueOf(result.getString("permission"));
            final byte[] data = result.getBytes("data");
            sections.put(new Section(id, name, CommentManager.get(provider), module, startAddress, endAddress, permission, data), commentId);
        }
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException(exception);
    }
    return sections;
}
Also used : SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) PreparedStatement(java.sql.PreparedStatement) Section(com.google.security.zynamics.binnavi.disassembly.types.Section) SectionPermission(com.google.security.zynamics.binnavi.disassembly.types.SectionPermission) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) BigInteger(java.math.BigInteger) ResultSet(java.sql.ResultSet)

Example 12 with CouldntLoadDataException

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

the class PostgreSQLTypeFunctions method loadRawTypeInstanceReferences.

public static List<RawTypeInstanceReference> loadRawTypeInstanceReferences(final Connection connection, final INaviModule module) throws CouldntLoadDataException {
    final ArrayList<RawTypeInstanceReference> rawReferences = Lists.newArrayList();
    final String query = " SELECT * FROM load_expression_type_instances(?) ";
    try {
        final PreparedStatement statement = connection.prepareStatement(query);
        statement.setInt(1, module.getConfiguration().getId());
        try {
            final ResultSet resultSet = statement.executeQuery();
            while (resultSet.next()) {
                final int viewId = resultSet.getInt("view_id");
                final int moduleId = resultSet.getInt("module_id");
                final IAddress address = PostgreSQLHelpers.loadAddress(resultSet, "address");
                final int position = resultSet.getInt("position");
                final int expressionId = resultSet.getInt("expression_id");
                final int typeInstanceId = resultSet.getInt("type_instance_id");
                rawReferences.add(new RawTypeInstanceReference(moduleId, viewId, address, position, expressionId, typeInstanceId));
            }
        } finally {
            statement.close();
        }
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException(exception);
    }
    return rawReferences;
}
Also used : SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) RawTypeInstanceReference(com.google.security.zynamics.binnavi.disassembly.types.RawTypeInstanceReference) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress)

Example 13 with CouldntLoadDataException

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

the class PostgreSQLTypeFunctions method loadRawBaseType.

/**
   * Loads a single {@link RawBaseType base type} from the database.
   *
   * @param provider The {@link SQLProvider} to access the database with.
   * @param module The {@link INaviModule} to which this {@link RawBaseType base type} is associated
   *        to.
   * @param baseTypeId The id of the {@link RawBaseType base type} to load from the database.
   *
   * @return The {@link RawBaseType base type} from the database which matches the given arguments.
   * @throws CouldntLoadDataException
   */
public static RawBaseType loadRawBaseType(final SQLProvider provider, final INaviModule module, final Integer baseTypeId) throws CouldntLoadDataException {
    Preconditions.checkNotNull(provider, "Error: provider argument can not be null.");
    Preconditions.checkNotNull(module, "Error: module argument can not be null.");
    Preconditions.checkNotNull(baseTypeId, "Error: baseTypeId argument can not be null.");
    final String query = " SELECT * FROM load_type(?, ?) ";
    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, baseTypeId);
        final ResultSet resultSet = statement.executeQuery();
        try {
            while (resultSet.next()) {
                if (resultSet.first()) {
                    Integer pointer = resultSet.getInt("pointer");
                    if (resultSet.wasNull()) {
                        pointer = null;
                    }
                    return new RawBaseType(resultSet.getInt("id"), resultSet.getString("name"), resultSet.getInt("size"), pointer, resultSet.getBoolean("signed"), BaseTypeCategory.fromString(resultSet.getString("category")));
                }
            }
        } finally {
            resultSet.close();
            statement.close();
        }
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException(exception);
    }
    throw new CouldntLoadDataException("Error: could not load single base type from the database.");
}
Also used : BigInteger(java.math.BigInteger) RawBaseType(com.google.security.zynamics.binnavi.disassembly.types.RawBaseType) SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 14 with CouldntLoadDataException

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

the class PostgreSQLTypeFunctions method loadRawTypeMembers.

/**
   * Loads the raw type members for the given module from the database.
   *
   * @param connection The connection to the database.
   * @param module The module where the type members belong to.
   * @return The list of type members.
   * @throws CouldntLoadDataException Thrown if the type members couldn't be loaded.
   */
public static List<RawTypeMember> loadRawTypeMembers(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 List<RawTypeMember> rawMembers = new ArrayList<RawTypeMember>();
    final String query = " SELECT * FROM load_type_members(?) ";
    try {
        final PreparedStatement statement = connection.prepareStatement(query);
        statement.setInt(1, module.getConfiguration().getId());
        final ResultSet results = statement.executeQuery();
        try {
            while (results.next()) {
                final Integer parentId = results.getInt("parent_id");
                if (results.wasNull()) {
                    continue;
                }
                Integer argument = results.getInt("argument");
                if (results.wasNull()) {
                    argument = null;
                }
                Integer offset = results.getInt("offset");
                if (results.wasNull()) {
                    offset = null;
                }
                Integer numberOfElements = results.getInt("number_of_elements");
                if (results.wasNull()) {
                    numberOfElements = null;
                }
                rawMembers.add(new RawTypeMember(results.getInt("id"), results.getString("name"), results.getInt("base_type"), parentId, offset, argument, numberOfElements));
            }
        } finally {
            results.close();
            statement.close();
        }
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException(exception);
    }
    return rawMembers;
}
Also used : BigInteger(java.math.BigInteger) RawTypeMember(com.google.security.zynamics.binnavi.disassembly.types.RawTypeMember) 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 15 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)

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