Search in sources :

Example 1 with RawTypeInstance

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

the class MockSqlProvider method setTypeInstanceName.

@Override
public void setTypeInstanceName(final int moduleId, final int id, final String name) throws CouldntSaveDataException {
    final List<RawTypeInstance> rawInstances = typeInstances.get(moduleId);
    final RawTypeInstance rawInstance = Iterables.find(rawInstances, new Predicate<RawTypeInstance>() {

        @Override
        public boolean apply(final RawTypeInstance instance) {
            return instance.getId() == id;
        }
    });
    final RawTypeInstance newRawInstance = new RawTypeInstance(moduleId, id, name, rawInstance.getCommentId(), rawInstance.getTypeId(), rawInstance.getSectionId(), rawInstance.getSectionOffset());
    typeInstances.remove(moduleId, rawInstance);
    typeInstances.put(moduleId, newRawInstance);
}
Also used : RawTypeInstance(com.google.security.zynamics.binnavi.disassembly.types.RawTypeInstance)

Example 2 with RawTypeInstance

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

the class MockSqlProvider method createTypeInstance.

@Override
public int createTypeInstance(final int moduleId, final String name, final Integer commentId, final int typeId, final int sectionId, final long sectionOffset) throws CouldntSaveDataException {
    final RawTypeInstance rawTypeInstance = new RawTypeInstance(moduleId, typeInstanceCounter++, name, commentId, typeId, sectionId, sectionOffset);
    typeInstances.put(moduleId, rawTypeInstance);
    return rawTypeInstance.getId();
}
Also used : RawTypeInstance(com.google.security.zynamics.binnavi.disassembly.types.RawTypeInstance)

Example 3 with RawTypeInstance

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

the class MockSqlProvider method loadTypeInstance.

@Override
public RawTypeInstance loadTypeInstance(final INaviModule module, final Integer typeInstanceId) throws CouldntLoadDataException {
    final RawTypeInstance instance = new RawTypeInstance(module.getConfiguration().getId(), typeInstanceId, "TEST_INSTANCE", null, module.getTypeManager().getTypes().get(0).getId(), 0, 11143);
    typeInstances.put(typeInstanceId, instance);
    return instance;
}
Also used : RawTypeInstance(com.google.security.zynamics.binnavi.disassembly.types.RawTypeInstance)

Example 4 with RawTypeInstance

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

the class PostgreSQLTypeFunctions method loadRawTypeInstance.

/**
   * Loads a single {@link RawTypeInstance type instance} from the database.
   *
   * @param provider The {@link SQLProvider} to access the database with.
   * @param module The {@link INaviModule} the {@link RawTypeInstance type instance} is associated
   *        to.
   * @param typeInstanceId The id of the {@link RawTypeInstance type instance} to load from the
   *        database.
   *
   * @return The {@link RawTypeInstance type instance} from the database which matches the given
   *         arguments.
   * @throws CouldntLoadDataException if the {@link RawTypeInstance type instance} could not be
   *         loaded from the database.
   */
public static RawTypeInstance loadRawTypeInstance(final SQLProvider provider, final INaviModule module, final Integer typeInstanceId) 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");
    final String query = " SELECT * FROM load_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);
        final ResultSet resultSet = statement.executeQuery();
        try {
            while (resultSet.next()) {
                if (resultSet.first()) {
                    final int moduleId = resultSet.getInt("module_id");
                    final int id = resultSet.getInt("id");
                    final String name = resultSet.getString("name");
                    final int commentId = resultSet.getInt("comment_id");
                    final int typeId = resultSet.getInt("type_id");
                    final int sectionId = resultSet.getInt("section_id");
                    final long sectionOffset = resultSet.getLong("section_offset");
                    return new RawTypeInstance(moduleId, id, name, commentId, typeId, sectionId, sectionOffset);
                }
            }
        } finally {
            resultSet.close();
            statement.close();
        }
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException(exception);
    }
    throw new CouldntLoadDataException("Error: could not load singe type instance from the database.");
}
Also used : SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ResultSet(java.sql.ResultSet) RawTypeInstance(com.google.security.zynamics.binnavi.disassembly.types.RawTypeInstance) PreparedStatement(java.sql.PreparedStatement)

Example 5 with RawTypeInstance

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

the class PostgreSQLTypeFunctions method loadRawTypeInstances.

/**
   * Loads all type instances for the given module from the database.
   *
   * @param connection The connection to the database.
   * @param module The module for which to load all type instances.
   * @return The list of type instances for the given module.
   * @throws CouldntLoadDataException Thrown if the type instances could not be loaded from the
   *         database.
   */
public static List<RawTypeInstance> loadRawTypeInstances(final Connection connection, final INaviModule module) throws CouldntLoadDataException {
    final List<RawTypeInstance> instances = new ArrayList<RawTypeInstance>();
    try {
        final String query = "SELECT * FROM load_type_instances(?)";
        final PreparedStatement statement = connection.prepareStatement(query);
        statement.setInt(1, module.getConfiguration().getId());
        try {
            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 int typeId = result.getInt("type_id");
                final int sectionId = result.getInt("section_id");
                final long sectionOffset = result.getLong("section_offset");
                instances.add(new RawTypeInstance(module.getConfiguration().getId(), id, name, commentId, typeId, sectionId, sectionOffset));
            }
        } finally {
            statement.close();
        }
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException(exception);
    }
    return instances;
}
Also used : 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) RawTypeInstance(com.google.security.zynamics.binnavi.disassembly.types.RawTypeInstance) PreparedStatement(java.sql.PreparedStatement)

Aggregations

RawTypeInstance (com.google.security.zynamics.binnavi.disassembly.types.RawTypeInstance)6 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 TypeInstance (com.google.security.zynamics.binnavi.disassembly.types.TypeInstance)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1