Search in sources :

Example 1 with RawTypeInstanceReference

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

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

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

the class PostgreSQLTypeInstanceFunctionsTests method loadSingleTypeInstanceReference6.

@Test
public void loadSingleTypeInstanceReference6() throws CouldntLoadDataException, LoadCancelledException, CPartialLoadException {
    module.load();
    for (final INaviView view : module.getContent().getViewContainer().getViews().subList(10, 20)) {
        view.load();
        final TypeInstanceContainer container = module.getContent().getTypeInstanceContainer();
        for (final TypeInstance typeInstance : container.getTypeInstances()) {
            for (final TypeInstanceReference reference : container.getReferences(typeInstance)) {
                if (reference.getTreeNode().isPresent()) {
                    final RawTypeInstanceReference rawReference = provider.loadTypeInstanceReference(module, typeInstance.getId(), reference.getAddress().toBigInteger(), reference.getPosition(), reference.getTreeNode().get().getId());
                    Assert.assertEquals(reference.getAddress(), rawReference.getAddress());
                }
            }
        }
        view.close();
    }
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) TypeInstanceReference(com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceReference) RawTypeInstanceReference(com.google.security.zynamics.binnavi.disassembly.types.RawTypeInstanceReference) RawTypeInstanceReference(com.google.security.zynamics.binnavi.disassembly.types.RawTypeInstanceReference) RawTypeInstance(com.google.security.zynamics.binnavi.disassembly.types.RawTypeInstance) TypeInstance(com.google.security.zynamics.binnavi.disassembly.types.TypeInstance) TypeInstanceContainer(com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceContainer) Test(org.junit.Test)

Aggregations

RawTypeInstanceReference (com.google.security.zynamics.binnavi.disassembly.types.RawTypeInstanceReference)3 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 RawTypeInstance (com.google.security.zynamics.binnavi.disassembly.types.RawTypeInstance)1 TypeInstance (com.google.security.zynamics.binnavi.disassembly.types.TypeInstance)1 TypeInstanceContainer (com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceContainer)1 TypeInstanceReference (com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceReference)1 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)1 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)1 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)1 Test (org.junit.Test)1