Search in sources :

Example 1 with RawTypeMember

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

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

the class MockSqlProvider method createTypeMember.

@Override
public int createTypeMember(final INaviModule module, final int containingTypeId, final int baseTypeId, final String name, final Optional<Integer> position, final Optional<Integer> numberelements, Optional<Integer> argumentIndex) {
    final int id = ++typeId;
    members.put(module, new RawTypeMember(id, name, baseTypeId, containingTypeId, position.orNull(), null, numberelements.orNull()));
    return id;
}
Also used : RawTypeMember(com.google.security.zynamics.binnavi.disassembly.types.RawTypeMember)

Example 3 with RawTypeMember

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

the class MockSqlProvider method updateMember.

@Override
public void updateMember(final TypeMember member, final String newName, final BaseType newBaseType, final Optional<Integer> newOffset, final Optional<Integer> newNumberOfElements, final Optional<Integer> newArgumentIndex, final INaviModule module) {
    final RawTypeMember rawMember = findMember(member, module);
    if (rawMember != null) {
        members.remove(module, rawMember);
        members.put(module, new RawTypeMember(rawMember.getId(), newName, newBaseType.getId(), rawMember.getParentId(), newOffset.orNull(), newArgumentIndex.orNull(), newNumberOfElements.orNull()));
    } else {
        throw new IllegalStateException("Trying to update non-existing member.");
    }
}
Also used : RawTypeMember(com.google.security.zynamics.binnavi.disassembly.types.RawTypeMember)

Example 4 with RawTypeMember

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

the class PostgreSQLTypeFunctions method loadRawTypeMember.

/**
   * Loads a single {@link RawTypeMember type member} from the database
   *
   * @param provider The {@link SQLProvider} to access the database with.
   * @param module The {@link INaviModule} to which this {@link RawTypeMember type member} is
   *        associated to.
   * @param typeId The id of the {@link RawTypeMember type member} to load from the database.
   *
   * @return The {@link RawTypeMember type member} from the database which matches the given
   *         arguments.
   * @throws CouldntLoadDataException if the {@link RawTypeMember type member} could not be loaded
   *         from the database.
   */
public static RawTypeMember loadRawTypeMember(final SQLProvider provider, final INaviModule module, final Integer typeId) throws CouldntLoadDataException {
    Preconditions.checkNotNull(provider, "Error: provider argument can not be null");
    Preconditions.checkNotNull(module, "Error: module argument can not be null");
    Preconditions.checkNotNull(typeId, "Error: typeId argument can not be null");
    final String query = " SELECT * FROM load_type_member(?, ?) ";
    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, typeId);
        final ResultSet resultSet = statement.executeQuery();
        try {
            while (resultSet.next()) {
                if (resultSet.first()) {
                    final int id = resultSet.getInt("id");
                    final String name = resultSet.getString("name");
                    final int baseTypeId = resultSet.getInt("base_type");
                    final Integer parentId = resultSet.getInt("parent_id");
                    Integer offset = resultSet.getInt("offset");
                    if (resultSet.wasNull()) {
                        offset = null;
                    }
                    Integer argument = resultSet.getInt("argument");
                    if (resultSet.wasNull()) {
                        argument = null;
                    }
                    Integer numberOfElements = resultSet.getInt("number_of_elements");
                    if (resultSet.wasNull()) {
                        numberOfElements = null;
                    }
                    return new RawTypeMember(id, name, baseTypeId, parentId, offset, argument, numberOfElements);
                }
            }
        } finally {
            resultSet.close();
            statement.close();
        }
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException(exception);
    }
    throw new CouldntLoadDataException("Error: could not load single type member from the database.");
}
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) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Aggregations

RawTypeMember (com.google.security.zynamics.binnavi.disassembly.types.RawTypeMember)4 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