Search in sources :

Example 1 with RawBaseType

use of com.google.security.zynamics.binnavi.disassembly.types.RawBaseType 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 2 with RawBaseType

use of com.google.security.zynamics.binnavi.disassembly.types.RawBaseType 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 3 with RawBaseType

use of com.google.security.zynamics.binnavi.disassembly.types.RawBaseType in project binnavi by google.

the class MockSqlProvider method deleteType.

@Override
public void deleteType(final BaseType baseType, final INaviModule module) {
    final RawBaseType rawBaseType = new RawBaseType(baseType.getId(), baseType.getName(), baseType.getBitSize(), baseType.pointsTo() != null ? baseType.pointsTo().getId() : null, baseType.isSigned(), baseType.getCategory());
    types.remove(module.getConfiguration().getId(), rawBaseType);
}
Also used : RawBaseType(com.google.security.zynamics.binnavi.disassembly.types.RawBaseType)

Example 4 with RawBaseType

use of com.google.security.zynamics.binnavi.disassembly.types.RawBaseType in project binnavi by google.

the class MockSqlProvider method createType.

@Override
public int createType(final int moduleId, final String name, final int size, final Integer previousPointerTypeId, final boolean signed, final BaseTypeCategory category) {
    final RawBaseType rawBaseType = new RawBaseType(++typeId, name, size, previousPointerTypeId, signed, category);
    types.put(moduleId, rawBaseType);
    return rawBaseType.getId();
}
Also used : RawBaseType(com.google.security.zynamics.binnavi.disassembly.types.RawBaseType)

Example 5 with RawBaseType

use of com.google.security.zynamics.binnavi.disassembly.types.RawBaseType in project binnavi by google.

the class MockSqlProvider method updateType.

@Override
public void updateType(final BaseType baseType, final String name, final int size, final boolean isSigned, final INaviModule module) {
    final RawBaseType rawType = findType(baseType, module);
    if (rawType != null) {
        types.remove(module.getConfiguration().getId(), rawType);
        types.put(module.getConfiguration().getId(), new RawBaseType(rawType.getId(), name, size, rawType.getPointerId(), isSigned, rawType.getCategory()));
    } else {
        throw new IllegalStateException("Trying to update non-existing type.");
    }
}
Also used : RawBaseType(com.google.security.zynamics.binnavi.disassembly.types.RawBaseType)

Aggregations

RawBaseType (com.google.security.zynamics.binnavi.disassembly.types.RawBaseType)5 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)2 BigInteger (java.math.BigInteger)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)1