Search in sources :

Example 1 with SectionPermission

use of com.google.security.zynamics.binnavi.disassembly.types.SectionPermission 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;
}
Also used : SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) PreparedStatement(java.sql.PreparedStatement) Section(com.google.security.zynamics.binnavi.disassembly.types.Section) SectionPermission(com.google.security.zynamics.binnavi.disassembly.types.SectionPermission) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) BigInteger(java.math.BigInteger) ResultSet(java.sql.ResultSet)

Aggregations

CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)1 Section (com.google.security.zynamics.binnavi.disassembly.types.Section)1 SectionPermission (com.google.security.zynamics.binnavi.disassembly.types.SectionPermission)1 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)1 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)1 BigInteger (java.math.BigInteger)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1