use of com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException in project binnavi by google.
the class CDatabase method load.
@Override
public void load() throws CouldntLoadDataException, InvalidDatabaseVersionException, LoadCancelledException {
Preconditions.checkArgument(isConnected(), "IE00686: Not connected to the database");
try {
if (!loadReporter.report(LoadEvents.LOADING_DATABASE)) {
throw new LoadCancelledException();
}
if (!loadReporter.report(LoadEvents.DETERMINING_DATABASE_VERSION)) {
throw new LoadCancelledException();
}
final DatabaseVersion databaseVersion = provider.getDatabaseVersion();
final DatabaseVersion currentVersion = new DatabaseVersion(Constants.PROJECT_VERSION);
if ((databaseVersion.compareTo(currentVersion) != 0) && currentVersion.needsUpgrading(databaseVersion)) {
throw new InvalidDatabaseVersionException(databaseVersion);
}
if (!loadReporter.report(LoadEvents.LOADING_USERS)) {
throw new LoadCancelledException();
}
loadUserManager();
if (!loadReporter.report(LoadEvents.LOADING_VIEW_TAGS)) {
throw new LoadCancelledException();
}
final CTagManager viewTagManager = loadViewTagManager();
if (!loadReporter.report(LoadEvents.LOADING_NODE_TAGS)) {
throw new LoadCancelledException();
}
final CTagManager nodeTagManager = loadNodeTagManager();
if (!loadReporter.report(LoadEvents.LOADING_DEBUGGERS)) {
throw new LoadCancelledException();
}
final DebuggerTemplateManager debuggerDescriptionManager = provider.loadDebuggers();
if (!loadReporter.report(LoadEvents.LOADING_PROJECTS)) {
throw new LoadCancelledException();
}
final List<INaviProject> projects = provider.loadProjects();
if (!loadReporter.report(LoadEvents.LOADING_RAW_MODULES)) {
throw new LoadCancelledException();
}
final List<INaviRawModule> rawModules = provider.loadRawModules();
if (!loadReporter.report(LoadEvents.LOADING_MODULES)) {
throw new LoadCancelledException();
}
final List<INaviModule> modules = provider.loadModules();
debuggerDescriptionManager.addListener(internalDebuggerTemplateListener);
content = new CDatabaseContent(provider, this, listeners, projects, modules, rawModules, viewTagManager, nodeTagManager, debuggerDescriptionManager);
} catch (final CouldntLoadDataException exception) {
loadReporter.report(LoadEvents.LOADING_FINISHED);
close();
throw exception;
} catch (final InvalidDatabaseVersionException exception) {
loadReporter.report(LoadEvents.LOADING_FINISHED);
throw exception;
} catch (final LoadCancelledException exception) {
loadReporter.report(LoadEvents.LOADING_FINISHED);
close();
throw exception;
} finally {
isLoading = false;
}
content.initializeRawModules(content.getModules(), content.getRawModules());
for (final IDatabaseListener listener : listeners) {
try {
listener.loadedDatabase(this);
} catch (final Exception exception) {
CUtilityFunctions.logException(exception);
}
}
loadReporter.report(LoadEvents.LOADING_FINISHED);
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException in project binnavi by google.
the class CDatabaseLoader method loadDatabase.
/**
* Loads the content of a database.
*
* @param parent Parent window used for dialogs.
* @param database The database to load.
*/
public static void loadDatabase(final Window parent, final IDatabase database) {
final CDatabaseLoaderOperation operation = new CDatabaseLoaderOperation(database);
try {
database.connect();
database.load();
} catch (final CouldntLoadDriverException exception) {
final String message = "E00012: " + "Database driver could not be loaded";
final String description = CUtilityFunctions.createDescription(String.format("BinNavi could not create a database connection because the database " + "driver '%s' could not be loaded", database.getConfiguration().getDriver()), new String[] { "The database driver string is wrong.", "The database driver file could not be found." }, new String[] { "BinNavi can not load data from the given database until the " + "problem is resolved." });
NaviErrorDialog.show(parent, message, description, exception);
} catch (final CouldntLoadDataException exception) {
final String message = "E00014: " + "Could not load data from the database";
final String description = CUtilityFunctions.createDescription("An error occurred when loading data from the database.", new String[] { "The connection to the database was dropped while the data was loaded.", "The database contains inconsistent information." }, new String[] { "Close the database and open it again. Maybe close and re-start " + "BinNavi too. If the program persists, please contact the BinNavi support." });
NaviErrorDialog.show(parent, message, description, exception);
} catch (final InvalidDatabaseException exception) {
final String message = "E00015: " + "Database is in an inconsistent state";
final String description = CUtilityFunctions.createDescription("The selected database contains an invalid combination of BinNavi tables.", new String[] { "An earlier connection attempt failed and left the database in an " + "inconsistent state.", "Some BinNavi tables were deleted accidentally by an outside program." }, new String[] { "BinNavi can not use this database anymore. If the database is " + "empty, please delete the database and create a new database to work with " + "BinNavi. If the database already contains data please contact the BinNavi " + "support." });
NaviErrorDialog.show(parent, message, description, exception);
} catch (final CouldntInitializeDatabaseException exception) {
final String message = "E00016: Database could not be initialized";
final String description = CUtilityFunctions.createDescription("BinNavi could not initialize the tables required for storing disassembly data " + "in the database.", new String[] { "There might have been a communication problem with the database." }, new String[] { "The database is probably corrupted at this point. It is " + "recommended to delete the database. Afterwards you can try again with a " + "fresh database. If you do not want to do this please contact the BinNavi " + "support to find out what other options exist for you." });
NaviErrorDialog.show(parent, message, description, exception);
} catch (final InvalidExporterDatabaseFormatException exception) {
final String message = "E00017: " + "Database has invalid exporter tables";
final String description = CUtilityFunctions.createDescription("BinNavi could not load data from the selected database because the database " + "contains invalid exporter tables", new String[] { "The database is too old to use with BinNavi." }, new String[] { "It is recommended to create a database for this version of " + "BinNavi. If you do not want to do this please contact the BinNavi support " + "to find out what other options exist for you." });
NaviErrorDialog.show(parent, message, description, exception);
} catch (final InvalidDatabaseVersionException exception) {
final String exceptionVersion = exception.getVersion().getString();
if (!exceptionVersion.equals("4.0.0") || !exceptionVersion.equals("5.0.0")) {
CMessageBox.showInformation(parent, String.format("You are trying to connect to an outdated BinNavi %s database.\n\n" + "Unfortunately you can not upgrade this database. Please create a " + "new database and export your modules again.", exceptionVersion));
} else {
CMessageBox.showInformation(parent, String.format("You are trying to connect to an outdated BinNavi %s database.\n\n" + "You have the option to update the database.", exceptionVersion));
if (JOptionPane.YES_OPTION == CMessageBox.showYesNoQuestion(parent, "Do you want to upgrade the database now?\n\n(The upgrade process can take " + "very long depending on the size of your current database)\n\n(Make " + "sure that the identity field contains a user name)")) {
final CDefaultProgressOperation updateOperation = new CDefaultProgressOperation("Upgrading database", true, false);
updateOperation.getProgressPanel().setText("Upgrading database");
try {
database.update();
database.close();
} catch (final CouldntUpdateDatabaseException upgradeException) {
CUtilityFunctions.logException(upgradeException);
final String message = "E00018: " + "Database could not be upgraded";
final String description = CUtilityFunctions.createDescription(String.format("BinNavi could not upgrade the database (database error %d). " + "This is a serious problem because the database could be " + "left in an inconsistent state. Please try to fix the " + "problem that led to the error and try to update the " + "database again.", upgradeException.getErrorCode()), new String[] { getErrorCode(upgradeException) }, new String[] { "Please note that nobody must work with this database " + "until the database conversion process is complete. If someone " + "works with the database in its current state, partial or total " + "data loss could happen." });
NaviErrorDialog.show(parent, message, description, exception);
} finally {
updateOperation.stop();
}
loadDatabase(parent, database);
} else {
database.close();
}
}
} catch (final CouldntConnectException exception) {
final CDatabaseConfiguration config = database.getConfiguration();
if (exception.getSqlState().equalsIgnoreCase(PostgreSQLErrorCodes.INVALID_PASSWORD)) {
CMessageBox.showInformation(parent, String.format("The password for user '%s' on database '%s' is invalid", config.getUser(), config.getUrl()));
return;
}
if (exception.getSqlState().equalsIgnoreCase(PostgreSQLErrorCodes.POSTGRES_INVALID_CATALOG_NAME)) {
if (JOptionPane.YES_OPTION == CMessageBox.showYesNoCancelQuestion(parent, String.format("The database '%s' does not exist. Do you want to create it now?", config.getUrl()))) {
CDatabaseCreator.createDatabase(parent, config);
}
} else {
final String message = "E00013: Database connection could not be established";
final String description = CUtilityFunctions.createDescription(String.format("BinNavi could not connect to the database '%s'", database.getConfiguration().getName()), new String[] { exception.getMessage() }, new String[] { "BinNavi can not load data from the given database until the " + "problem is resolved." });
NaviErrorDialog.show(parent, message, description, exception);
}
} catch (final LoadCancelledException exception) {
// We do not signal to the user that he cancelled loading.
} finally {
operation.stop();
}
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException in project binnavi by google.
the class CCodeNodeParser method createCurrentNode.
/**
* Creates a new code node.
*
* @param resultSet Provides the data for the code node.
*
* @return The created code node object.
*
* @throws ParserException Thrown if the node data could not be read.
* @throws CPartialLoadException Thrown if not all required modules are loaded.
*/
private CCodeNode createCurrentNode(final ICodeNodeProvider resultSet) throws ParserException, CPartialLoadException {
final int nodeId = resultSet.getNodeId();
final int moduleId = resultSet.getModule();
final IAddress parentFunction = resultSet.getParentFunction();
final INaviModule module = modules.get(moduleId);
if (module == null) {
throw new ParserException(String.format("Node with ID %d has unknown parent module with ID %d", nodeId, moduleId));
}
if (!module.isLoaded()) {
try {
module.load();
} catch (final CouldntLoadDataException e) {
throw new CPartialLoadException("E00066: The view could not be loaded because not all modules that form the view could be loaded", module);
} catch (final LoadCancelledException e) {
throw new CPartialLoadException("E00067: The view could not be loaded because it was cancelled", module);
}
}
final INaviFunction function = parentFunction == null ? null : module.getContent().getFunctionContainer().getFunction(parentFunction);
if ((parentFunction != null) && (function == null)) {
throw new ParserException(String.format("Node with ID %d has unknown parent function with address %s", nodeId, parentFunction.toHexString()));
}
final double x = resultSet.getX();
final double y = resultSet.getY();
final double width = resultSet.getWidth();
final double height = resultSet.getHeight();
final Color color = new Color(resultSet.getColor());
final Color bordercolor = new Color(resultSet.getBorderColor());
final boolean selected = resultSet.isSelected();
final boolean visible = resultSet.isVisible();
final Integer localCodeNodeCommentId = resultSet.getLocalNodeCommentId();
final Integer globalCodeNodeCommentId = resultSet.getGlobalNodeCommentId();
// TODO(timkornau): final new Set<CTag>! must replaced by a set which
// contains the loaded node
// tags from the DB
final CCodeNode codeNode = new CCodeNode(nodeId, x, y, width, height, color, bordercolor, selected, visible, null, function, new HashSet<CTag>(), sqlProvider);
if (localCodeNodeCommentId != null) {
localCommentIdToCodeNode.put(localCodeNodeCommentId, codeNode);
}
if (globalCodeNodeCommentId != null) {
globalCommentIdToCodeNode.put(globalCodeNodeCommentId, codeNode);
}
return codeNode;
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException in project binnavi by google.
the class CProjectContentTest method testRemoveTrace.
@Test
public void testRemoveTrace() throws CouldntLoadDataException, LoadCancelledException, CouldntSaveDataException, CouldntDeleteException {
final CProjectContent projectContent = new CProjectContent(m_project, m_listeners, m_provider, m_addressSpaces, m_views, m_traces);
@SuppressWarnings("unused") final INaviView view = new MockView(m_provider);
@SuppressWarnings("unused") final INaviView view2 = projectContent.createView("Name", "description");
assertNotNull(CViewFilter.getTaggedViews(projectContent.getViews(), new CTag(4, "foo", "bar", TagType.VIEW_TAG, m_provider)));
final CAddressSpace spaceOne = projectContent.createAddressSpace("Address Space 1");
spaceOne.load();
final CAddressSpace spaceTwo = projectContent.createAddressSpace("Address Space 2");
spaceTwo.load();
final CAddressSpace spaceThree = projectContent.createAddressSpace("Address Space 3");
spaceThree.load();
final CAddressSpace spaceFour = projectContent.createAddressSpace("Address Space 4");
spaceFour.load();
m_project.load();
final TraceList trace = new TraceList(3, "name", "desc", m_provider);
projectContent.removeTrace(trace);
try {
projectContent.removeTrace(null);
fail();
} catch (final NullPointerException e) {
}
final TraceList trace2 = new TraceList(3, "name", "desc", new MockSqlProvider());
try {
projectContent.removeTrace(trace2);
fail();
} catch (final Exception e) {
}
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException in project binnavi by google.
the class CModule method load.
@Override
public void load() throws CouldntLoadDataException, LoadCancelledException {
synchronized (m_loadReporter) {
if (isLoaded()) {
return;
}
if (!isInitialized()) {
throw new IllegalStateException("IE02617: The module is not initialized yet");
}
m_isLoading = true;
try {
if (!m_loadReporter.report(ModuleLoadEvents.Starting)) {
throw new LoadCancelledException();
}
if (!m_loadReporter.report(ModuleLoadEvents.LoadingCallgraphView)) {
throw new LoadCancelledException();
}
final ICallgraphView nativeCallgraph = m_provider.loadNativeCallgraph(this);
if (!m_loadReporter.report(ModuleLoadEvents.LoadingFlowgraphs)) {
throw new LoadCancelledException();
}
// When loading views, an empty flow graph (imported function) can not
// be distinguished
// from an empty call graph. This leads to problems in modules without
// functions. In
// these cases, the empty call graph is loaded as an imported function
// view. This is
// obviously wrong, so we are correcting this here.
final ImmutableList<IFlowgraphView> nativeFlowgraphs = nativeCallgraph.getNodeCount() == 0 ? new ImmutableList.Builder<IFlowgraphView>().build() : m_provider.loadNativeFlowgraphs(this);
if (!m_loadReporter.report(ModuleLoadEvents.LoadingCallgraphViews)) {
throw new LoadCancelledException();
}
final List<ICallgraphView> userCallgraphs = m_provider.loadCallgraphViews(this);
if (!m_loadReporter.report(ModuleLoadEvents.LoadingFlowgraphViews)) {
throw new LoadCancelledException();
}
final ImmutableList<IFlowgraphView> userFlowgraphs = m_provider.loadFlowgraphs(this);
if (!m_loadReporter.report(ModuleLoadEvents.LoadingMixedViews)) {
throw new LoadCancelledException();
}
final List<INaviView> userMixedGraphs = m_provider.loadMixedgraphs(this);
if (!m_loadReporter.report(ModuleLoadEvents.LoadingCallgraph)) {
throw new LoadCancelledException();
}
if (!m_loadReporter.report(ModuleLoadEvents.LoadingFunctions)) {
throw new LoadCancelledException();
}
// Note: the type manager needs to be loaded prior to functions, since a function might
// have an associated stack frame, which in turn needs the type system.
typeManager = new TypeManager(new TypeManagerDatabaseBackend(m_provider, this));
final List<INaviFunction> functions = m_provider.loadFunctions(this, nativeFlowgraphs);
final ImmutableBiMap<INaviView, INaviFunction> viewFunctionMap = m_provider.loadViewFunctionMapping(nativeFlowgraphs, functions, this);
final CCallgraph callgraph = m_provider.loadCallgraph(this, nativeCallgraph.getConfiguration().getId(), functions);
if (!m_loadReporter.report(ModuleLoadEvents.LoadingTraces)) {
throw new LoadCancelledException();
}
final List<TraceList> traces = m_provider.loadTraces(this);
if (!m_loadReporter.report(ModuleLoadEvents.LoadingGlobalVariables)) {
throw new LoadCancelledException();
}
final List<INaviView> customViews = new ArrayList<INaviView>();
customViews.addAll(userCallgraphs);
customViews.addAll(userFlowgraphs);
customViews.addAll(userMixedGraphs);
final List<INaviView> currentViews = new ArrayList<INaviView>(nativeFlowgraphs);
currentViews.addAll(customViews);
Collections.sort(currentViews, new Comparator<INaviView>() {
@Override
public int compare(final INaviView lhs, final INaviView rhs) {
return lhs.getConfiguration().getId() - rhs.getConfiguration().getId();
}
});
// Map viewId to corresponding index in currentViews.
final Map<Integer, Integer> viewIdToIndex = new HashMap<Integer, Integer>();
for (int i = 0; i < currentViews.size(); ++i) {
viewIdToIndex.put(currentViews.get(i).getConfiguration().getId(), i);
}
if (!m_loadReporter.report(ModuleLoadEvents.LoadingTypes)) {
throw new LoadCancelledException();
}
final SectionContainer sections = new SectionContainer(new SectionContainerBackend(m_provider, this));
final TypeInstanceContainer typeInstances = new TypeInstanceContainer(new TypeInstanceContainerBackend(m_provider, this, typeManager, sections), m_provider);
m_content = new CModuleContent(this, m_provider, m_listeners, callgraph, functions, nativeCallgraph, nativeFlowgraphs, customViews, viewFunctionMap, traces, sections, typeInstances);
typeInstances.initialize();
} catch (final CouldntLoadDataException e) {
m_isLoading = false;
throw e;
} catch (final LoadCancelledException e) {
m_isLoading = false;
throw e;
} finally {
m_loadReporter.report(ModuleLoadEvents.Finished);
}
for (final IModuleListener listener : m_listeners) {
try {
listener.loadedModule(this);
} catch (final Exception exception) {
CUtilityFunctions.logException(exception);
}
}
m_isLoading = false;
}
}
Aggregations