use of com.google.security.zynamics.binnavi.Database.CConnection in project binnavi by google.
the class PostgreSQLAddressSpaceLoader method loadAddressSpaces.
/**
* Loads the address spaces of a project.
*
* The project, the debugger manager, and all modules in the module list must be stored in the
* database connected to by the provider argument.
*
* @param provider The SQL provider that provides the connection.
* @param project The parent project of the address spaces to load.
* @param debuggerManager Debugger manager of the database.
* @param list A list of all modules that belong to the database.
*
* @return A list that contains the address spaces of the project.
*
* @throws CouldntLoadDataException Thrown if the address spaces could not be loaded.
*/
public static List<CAddressSpace> loadAddressSpaces(final AbstractSQLProvider provider, final INaviProject project, final DebuggerTemplateManager debuggerManager, final List<INaviModule> list) throws CouldntLoadDataException {
checkArguments(provider, project);
Preconditions.checkNotNull(debuggerManager, "IE01543: Debugger provider argument can not be null");
Preconditions.checkNotNull(list, "IE01545: Modules argument can not be null");
NaviLogger.info("Loading address spaces of project %s", project.getConfiguration().getName());
final CConnection connection = provider.getConnection();
final List<CAddressSpace> addressSpaces = new ArrayList<CAddressSpace>();
final String query = "SELECT id, name, description, creation_date, modification_date, debugger_id " + " FROM " + CTableNames.ADDRESS_SPACES_TABLE + " WHERE project_id = " + project.getConfiguration().getId();
try {
final ResultSet resultSet = connection.executeQuery(query, true);
try {
while (resultSet.next()) {
final int addressSpaceId = resultSet.getInt("id");
final Map<INaviModule, IAddress> imageBases = loadImageBases(connection, addressSpaceId, list);
final String name = PostgreSQLHelpers.readString(resultSet, "name");
final String description = PostgreSQLHelpers.readString(resultSet, "description");
final Timestamp creationDate = resultSet.getTimestamp("creation_date");
final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
final DebuggerTemplate debuggerDescription = debuggerManager.findDebugger(resultSet.getInt("debugger_id"));
addressSpaces.add(new CAddressSpace(addressSpaceId, name, description, creationDate, modificationDate, imageBases, debuggerDescription, provider, project));
}
return addressSpaces;
} finally {
resultSet.close();
}
} catch (final SQLException e) {
throw new CouldntLoadDataException(e);
}
}
use of com.google.security.zynamics.binnavi.Database.CConnection in project binnavi by google.
the class PostgreSQLCallgraphLoader method loadCallgraph.
/**
* Loads the call graph of a module.
*
* The module, the call graph ID, and all functions of the function list must refer to objects
* stored in the database connected to by the provider argument.
*
* @param provider The SQL provider that provides the connection.
* @param module The module whose call graph is loaded.
* @param callgraphId The view ID of the call graph to load.
* @param functions A list that contains all functions of the module.
*
* @return The loaded call graph.
*
* @throws CouldntLoadDataException Thrown if the call graph could not be loaded.
*/
public static CCallgraph loadCallgraph(final AbstractSQLProvider provider, final CModule module, final int callgraphId, final List<INaviFunction> functions) throws CouldntLoadDataException {
checkArguments(provider, module, functions);
final CConnection connection = provider.getConnection();
try {
final Pair<List<ICallgraphNode>, Map<Integer, CCallgraphNode>> nodeResult = loadNodes(connection, callgraphId, functions);
final List<ICallgraphEdge> edges = loadEdges(connection, callgraphId, nodeResult.second());
return new CCallgraph(nodeResult.first(), edges);
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
}
use of com.google.security.zynamics.binnavi.Database.CConnection 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.CConnection 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.CConnection in project binnavi by google.
the class PostgreSQLModuleFunctions method deleteModule.
/**
* Deletes a module from the database.
*
* The module must be stored in the database connected to by the provider argument.
*
* @param provider The SQL provider that provides the connection.
* @param module The module to be deleted.
*
* @throws CouldntDeleteException Thrown if the module could not be deleted.
*/
public static void deleteModule(final AbstractSQLProvider provider, final INaviModule module) throws CouldntDeleteException {
PostgreSQLModuleFunctions.checkArguments(provider, module);
NaviLogger.info("Deleting module %s", module.getConfiguration().getName());
final CConnection connection = provider.getConnection();
try {
final String moduleViewQuery = "DELETE FROM " + CTableNames.VIEWS_TABLE + " " + " WHERE id IN (SELECT view_id FROM " + CTableNames.MODULE_VIEWS_TABLE + " WHERE module_id = " + module.getConfiguration().getId() + ")";
connection.executeUpdate(moduleViewQuery, true);
final String nodeQuery = "DELETE FROM " + CTableNames.NODES_TABLE + " " + " WHERE id IN " + " (SELECT view_id FROM " + CTableNames.MODULE_VIEWS_TABLE + " WHERE module_id = " + module.getConfiguration().getId() + ")";
connection.executeUpdate(nodeQuery, true);
final String instructionsQuery = String.format("DELETE FROM " + CTableNames.INSTRUCTIONS_TABLE + " WHERE module_id = %d", module.getConfiguration().getId());
connection.executeUpdate(instructionsQuery, true);
connection.executeUpdate(String.format("delete FROM " + CTableNames.EXPRESSION_TREE_TABLE + "_mapping where module_id = %d", module.getConfiguration().getId()), true);
connection.executeUpdate(String.format("delete FROM " + CTableNames.EXPRESSION_TREE_TABLE + " where module_id = %d", module.getConfiguration().getId()), true);
connection.executeUpdate(String.format("delete FROM " + CTableNames.EXPRESSION_TREE_TABLE + "_ids where module_id = %d", module.getConfiguration().getId()), true);
connection.executeUpdate(String.format("delete FROM " + CTableNames.CODE_NODES_TABLE + " where module_id = %d", module.getConfiguration().getId()), true);
connection.executeUpdate(String.format("delete from " + CTableNames.MODULES_TABLE + " where id = %d", module.getConfiguration().getId()), true);
} catch (final SQLException e) {
throw new CouldntDeleteException(e);
}
}
Aggregations