use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException in project binnavi by google.
the class CAddressSpaceFunctions method loadAddressSpaces.
/**
* Loads one or more address spaces.
*
* @param projectTree Project tree of the main window.
* @param addressSpaces The address spaces to load.
*/
public static void loadAddressSpaces(final JTree projectTree, final INaviAddressSpace[] addressSpaces) {
new Thread() {
@Override
public void run() {
final CDefaultProgressOperation operation = new CDefaultProgressOperation("Loading address spaces", false, true);
operation.getProgressPanel().setMaximum(addressSpaces.length);
for (final INaviAddressSpace addressSpace : addressSpaces) {
operation.getProgressPanel().setText("Loading address spaces" + ": '" + addressSpace.getConfiguration().getName() + "'");
try {
addressSpace.load();
new SwingInvoker() {
@Override
protected void operation() {
CNodeExpander.expandNode(projectTree, addressSpace);
}
}.invokeLater();
} catch (final CouldntLoadDataException exception) {
CUtilityFunctions.logException(exception);
final String message = "E00109: " + "Address space could not be loaded";
final String description = CUtilityFunctions.createDescription(String.format("The address space '%s' could not be loaded. Try loading the address space again. If the problem persists, disconnect from and reconnect to the database, restart com.google.security.zynamics.binnavi, or contact the BinNavi support.", addressSpace.getConfiguration().getName()), new String[] { "Database connection problems." }, new String[] { "The address space was not loaded." });
NaviErrorDialog.show(SwingUtilities.getWindowAncestor(projectTree), message, description, exception);
} catch (final LoadCancelledException e) {
// Do nothing
} finally {
operation.getProgressPanel().next();
}
}
operation.stop();
}
}.start();
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException 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.Exceptions.CouldntLoadDataException in project binnavi by google.
the class PostgreSQLAddressSpaceLoader method loadImageBases.
/**
* Loads the image bases of the given modules within the given address space.
*
* The address space ID and the modules in the module list must all reference items that are
* stored in the database connected to by connection argument.
*
* @param connection Connection to the database.
* @param addressSpaceId ID of the address space.
* @param list Modules whose image bases are loaded.
*
* @return A mapping of modules -> image bases for all modules in the address space.
*
* @throws CouldntLoadDataException Thrown if the image bases could not be loaded.
*/
private static Map<INaviModule, IAddress> loadImageBases(final CConnection connection, final int addressSpaceId, final List<INaviModule> list) throws CouldntLoadDataException {
final HashMap<INaviModule, IAddress> imageBases = new HashMap<INaviModule, IAddress>();
final String query = "SELECT module_id, image_base FROM " + CTableNames.SPACE_MODULES_TABLE + " WHERE address_space_id = " + addressSpaceId;
try {
final ResultSet resultSet = connection.executeQuery(query, true);
try {
while (resultSet.next()) {
try {
final INaviModule module = findModule(list, resultSet.getInt("module_id"));
imageBases.put(module, PostgreSQLHelpers.loadAddress(resultSet, "image_base"));
} catch (final MaybeNullException exception) {
// I can not think of a scenario where this can happen.
CUtilityFunctions.logException(exception);
}
}
} finally {
resultSet.close();
}
return imageBases;
} 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 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.Exceptions.CouldntLoadDataException in project binnavi by google.
the class PostgreSQLEdgeLoader method loadGlobalEdgeComments.
/**
* Loads the edge comments of a view.
*
* @param provider The provider used to access the database.
* @param viewId ID of the view whose edges are loaded.
*
* @return A map of <Edge ID, Edge Comment>.
*
* @throws CouldntLoadDataException
*/
private static Map<Integer, ArrayList<IComment>> loadGlobalEdgeComments(final SQLProvider provider, final int viewId) throws CouldntLoadDataException {
// TODO (timkornau): this query needs to go into the database and needs to use the get all
// comment ancestors
// to build the complete
// comment structure for each edge comment.
final String query = "SELECT e.id, gc.comment_id FROM " + CTableNames.GLOBAL_EDGE_COMMENTS_TABLE + " AS gc " + " join " + CTableNames.INSTRUCTIONS_TABLE + " AS src_inst on gc.src_address = src_inst.address " + "AND gc.src_module_id = src_inst.module_id " + " join " + CTableNames.INSTRUCTIONS_TABLE + " AS dst_inst on gc.dst_address = dst_inst.address " + "AND gc.dst_module_id = dst_inst.module_id " + " join " + CTableNames.CODENODE_INSTRUCTIONS_TABLE + " AS src_nodes on src_nodes.address = gc.src_address AND src_nodes.position = 0 " + "AND src_nodes.module_id = gc.src_module_id " + " join " + CTableNames.CODENODE_INSTRUCTIONS_TABLE + " AS dst_nodes on dst_nodes.address = gc.dst_address AND dst_nodes.position = 0 " + "AND dst_nodes.module_id = gc.dst_module_id " + " join " + CTableNames.EDGES_TABLE + " AS e ON e.source_node_id = src_nodes.node_id AND e.target_node_id = dst_nodes.node_id " + " join " + CTableNames.NODES_TABLE + " AS src_n ON e.source_node_id = src_n.id " + " join " + CTableNames.NODES_TABLE + " AS dst_n ON e.target_node_id = dst_n.id " + " WHERE src_n.view_id = " + viewId + " AND dst_n.view_id = " + viewId;
final HashMap<Integer, Integer> commentIdsToEdgeIds = new HashMap<Integer, Integer>();
final HashMap<Integer, ArrayList<IComment>> edgeIdsToCommentArray = new HashMap<Integer, ArrayList<IComment>>();
try {
final ResultSet resultSet = provider.getConnection().executeQuery(query, true);
try {
while (resultSet.next()) {
final int edgeId = resultSet.getInt("id");
final int commentId = resultSet.getInt("comment_id");
commentIdsToEdgeIds.put(commentId, edgeId);
}
} finally {
resultSet.close();
}
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
if (!commentIdsToEdgeIds.isEmpty()) {
final HashMap<Integer, ArrayList<IComment>> commentIdsToComments = PostgreSQLCommentFunctions.loadMultipleCommentsById(provider, commentIdsToEdgeIds.keySet());
for (final Entry<Integer, ArrayList<IComment>> commentIdToComment : commentIdsToComments.entrySet()) {
edgeIdsToCommentArray.put(commentIdsToEdgeIds.get(commentIdToComment.getKey()), commentIdToComment.getValue());
}
}
return edgeIdsToCommentArray;
}
Aggregations