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