Search in sources :

Example 6 with CouldntLoadDataException

use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException in project binnavi by google.

the class PostgreSQLFunctionsLoader method loadFunction.

/**
   * This function loads a {@link INaviFunction} from the database given the {@link INaviModule}
   * where it is associated to and the {@link IAddress} of the function.
   *
   * @param provider The {@link SQLProvider} to access the database with.
   * @param module The {@link INaviModule} in which the function is located.
   * @param address The {@link IAddress} of the function to load.
   *
   * @return A {@link INaviFunction} if found.
   *
   * @throws CouldntLoadDataException if the function information could not be loaded from the
   *         database.
   */
public static INaviFunction loadFunction(final SQLProvider provider, final INaviModule module, final IAddress address) throws CouldntLoadDataException {
    checkArguments(provider, module);
    final String query = " SELECT * FROM load_function_information(?,?) ";
    try {
        final PreparedStatement statement = provider.getConnection().getConnection().prepareStatement(query);
        statement.setInt(1, module.getConfiguration().getId());
        statement.setObject(2, address.toBigInteger(), Types.BIGINT);
        final ResultSet resultSet = statement.executeQuery();
        return Iterables.getFirst(parseFunctionInformation(resultSet, provider, module), null);
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException(exception);
    }
}
Also used : SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 7 with CouldntLoadDataException

use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException in project binnavi by google.

the class PostgreSQLFunctionsLoader method loadFunctions.

/**
   * Loads the functions of a module.
   *
   * @param provider The SQL provider that provides the connection.
   * @param module The module whose functions are loaded.
   * @param views The views that potentially back the function.
   *
   * @return A list of functions that belong to the module.
   *
   * @throws CouldntLoadDataException Thrown if the functions of the module could not be loaded.
   */
public static List<INaviFunction> loadFunctions(final SQLProvider provider, final INaviModule module, final List<IFlowgraphView> views) throws CouldntLoadDataException {
    checkArguments(provider, module);
    final String query = " SELECT * FROM load_function_information(?) ";
    try {
        final PreparedStatement statement = provider.getConnection().getConnection().prepareStatement(query);
        statement.setInt(1, module.getConfiguration().getId());
        final ResultSet resultSet = statement.executeQuery();
        return parseFunctionInformation(resultSet, provider, module);
    } catch (final SQLException e) {
        throw new CouldntLoadDataException(e);
    }
}
Also used : SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 8 with CouldntLoadDataException

use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException in project binnavi by google.

the class PostgreSQLModuleFlowgraphsLoader method loadModuleFlowgraphs.

/**
   * Loads the flow graphs of a module.
   * 
   * @param provider The connection to the database.
   * @param module The module whose flow graph views are loaded.
   * @param viewTagManager The tag manager responsible for tagging the views.
   * @param nodeTagManager The tag manager responsible for tagging view nodes.
   * @param viewType The type of the views to load.
   * 
   * @return The loaded views.
   * 
   * @throws CouldntLoadDataException Thrown if the views could not be loaded.
   */
private static ImmutableList<IFlowgraphView> loadModuleFlowgraphs(final AbstractSQLProvider provider, final CModule module, final CTagManager viewTagManager, final CTagManager nodeTagManager, final ViewType viewType) throws CouldntLoadDataException {
    checkArguments(provider, module, viewTagManager);
    final String query = " SELECT * FROM load_module_flow_graphs(?, ?) ";
    final CConnection connection = provider.getConnection();
    try {
        final PreparedStatement statement = connection.getConnection().prepareStatement(query);
        statement.setInt(1, module.getConfiguration().getId());
        statement.setObject(2, viewType == ViewType.Native ? "native" : "non-native", Types.OTHER);
        final ResultSet resultSet = statement.executeQuery();
        final Map<Integer, Set<CTag>> tags = loadTags(connection, module, viewTagManager);
        return new ImmutableList.Builder<IFlowgraphView>().addAll(processQueryResults(resultSet, module, tags, nodeTagManager, provider, new ArrayList<CView>(), viewType, GraphType.FLOWGRAPH)).build();
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException(exception);
    }
}
Also used : CConnection(com.google.security.zynamics.binnavi.Database.CConnection) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) Set(java.util.Set) ResultSet(java.sql.ResultSet) SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 9 with CouldntLoadDataException

use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException in project binnavi by google.

the class PostgreSQLProjectCallgraphLoader method loadCallgraphViews.

/**
   * Loads the non-native call graph views of a project.
   * 
   * The project, the node tag manager, and the view tag manager must be stored in the database
   * connected to by the provider argument.
   * 
   * @param provider The SQL provider that provides the connection.
   * @param project The project from where the views are loaded.
   * @param viewTagManager View tag manager that contains all view tags of the database.
   * @param nodeTagManager The tag manager responsible for tagging view nodes.
   * 
   * @return A list of non-native call graph views.
   * 
   * @throws CouldntLoadDataException Thrown if the views could not be loaded.
   */
public static List<ICallgraphView> loadCallgraphViews(final AbstractSQLProvider provider, final CProject project, final CTagManager viewTagManager, final CTagManager nodeTagManager) throws CouldntLoadDataException {
    checkArguments(provider, project, viewTagManager);
    final String query = " SELECT * FROM load_project_call_graphs(?, ?) ";
    try {
        final CConnection connection = provider.getConnection();
        final PreparedStatement statement = connection.getConnection().prepareStatement(query);
        statement.setInt(1, project.getConfiguration().getId());
        statement.setObject(2, "non-native", Types.OTHER);
        final ResultSet resultSet = statement.executeQuery();
        final Map<Integer, Set<CTag>> tags = loadTags(connection, project, viewTagManager);
        return new ArrayList<ICallgraphView>(processQueryResults(resultSet, project, tags, nodeTagManager, provider, new ArrayList<CView>(), ViewType.NonNative, GraphType.CALLGRAPH));
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException(exception);
    }
}
Also used : CConnection(com.google.security.zynamics.binnavi.Database.CConnection) Set(java.util.Set) ResultSet(java.sql.ResultSet) SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement)

Example 10 with CouldntLoadDataException

use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException in project binnavi by google.

the class PostgreSQLModuleFunctions method readModule.

public static CModule readModule(final CConnection connection, final int moduleId, final INaviRawModule rawModule, final SQLProvider provider) throws CouldntLoadDataException {
    Preconditions.checkNotNull(rawModule, "IE01797: Raw module argument can not be null");
    Preconditions.checkNotNull(provider, "IE01798: Provider argument can not be null");
    final String query = "SELECT id, " + CTableNames.MODULES_TABLE + ".name, md5, sha1, " + " description, import_time, modification_date, image_base, file_base, stared, " + " initialization_state " + " FROM " + CTableNames.MODULES_TABLE + " WHERE id = " + moduleId + " ORDER by id";
    try {
        final ResultSet resultSet = connection.executeQuery(query, true);
        try {
            while (resultSet.next()) {
                final String name = PostgreSQLHelpers.readString(resultSet, "name");
                final String md5 = PostgreSQLHelpers.readString(resultSet, "md5");
                final String sha1 = PostgreSQLHelpers.readString(resultSet, "sha1");
                final String comment = PostgreSQLHelpers.readString(resultSet, "description");
                final Timestamp importTime = resultSet.getTimestamp("import_time");
                final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
                final int functionCount = rawModule.getFunctionCount();
                final int viewCount = 0;
                final IAddress imageBase = PostgreSQLHelpers.loadAddress(resultSet, "image_base");
                final IAddress fileBase = PostgreSQLHelpers.loadAddress(resultSet, "file_base");
                final boolean isStared = resultSet.getBoolean("stared");
                final int initializationState = resultSet.getInt("initialization_state");
                return new CModule(moduleId, name, comment, importTime, modificationDate, md5, sha1, functionCount, viewCount, fileBase, imageBase, null, rawModule, initializationState, isStared, provider);
            }
        } finally {
            resultSet.close();
        }
    } catch (final SQLException e) {
        throw new CouldntLoadDataException(e);
    }
    throw new CouldntLoadDataException("Error: No module with the given ID exists");
}
Also used : SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ResultSet(java.sql.ResultSet) Timestamp(java.sql.Timestamp) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress)

Aggregations

CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)85 SQLException (java.sql.SQLException)53 ResultSet (java.sql.ResultSet)47 ArrayList (java.util.ArrayList)30 PreparedStatement (java.sql.PreparedStatement)27 CConnection (com.google.security.zynamics.binnavi.Database.CConnection)20 LoadCancelledException (com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException)17 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)16 HashMap (java.util.HashMap)12 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)10 BigInteger (java.math.BigInteger)9 CPartialLoadException (com.google.security.zynamics.binnavi.Database.Exceptions.CPartialLoadException)8 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)8 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)8 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)8 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)7 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)6 Set (java.util.Set)6 CouldntDeleteException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)5 CDefaultProgressOperation (com.google.security.zynamics.binnavi.Gui.Progress.CDefaultProgressOperation)5