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.");
}
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;
}
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();
}
}
Aggregations