use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException in project binnavi by google.
the class PostgreSQLSectionFunctions method loadSections.
/**
* Loads all sections that are associated with the given module.
*
* @param provider The SQL provider that holds the database connection.
* @param module The module whose sections should be loaded.
* @return The list of sections loaded from the database.
* @throws CouldntLoadDataException Thrown if the sections could not be loaded from the database.
*/
public static Map<Section, Integer> loadSections(final SQLProvider provider, final INaviModule module) throws CouldntLoadDataException {
Preconditions.checkNotNull(provider, "Error: provider argument can not be null");
Preconditions.checkNotNull(module, "Error: module argument can not be null");
final HashMap<Section, Integer> sections = Maps.newHashMap();
final String query = "SELECT * FROM get_sections(?)";
try (PreparedStatement statement = provider.getConnection().getConnection().prepareStatement(query)) {
statement.setInt(1, module.getConfiguration().getId());
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 IAddress startAddress = new CAddress(result.getLong("start_address"));
final IAddress endAddress = new CAddress(result.getLong("end_address"));
final SectionPermission permission = SectionPermission.valueOf(result.getString("permission"));
final byte[] data = result.getBytes("data");
sections.put(new Section(id, name, CommentManager.get(provider), module, startAddress, endAddress, permission, data), commentId);
}
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
return sections;
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException 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.Database.Exceptions.CouldntLoadDataException 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.");
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException 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;
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException 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;
}
Aggregations