use of com.google.security.zynamics.binnavi.disassembly.INaviRawModule 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.disassembly.INaviRawModule in project binnavi by google.
the class CDatabaseContent method refreshRawModules.
@Override
public void refreshRawModules() throws CouldntLoadDataException {
Preconditions.checkArgument(m_database.isConnected(), "IE00687: Not connected to the database");
Preconditions.checkArgument(m_database.isLoaded(), "IE00688: Raw modules were not loaded previously");
final List<INaviRawModule> oldModules = m_rawModules;
final List<INaviRawModule> refreshedModules = m_provider.loadRawModules();
m_rawModules.clear();
m_rawModules.addAll(refreshedModules);
final List<INaviModule> newModules = initializeRawModules(m_modules, refreshedModules);
for (final IDatabaseListener listener : m_listeners) {
try {
listener.changedRawModules(m_database, oldModules, refreshedModules);
} catch (final Exception exception) {
CUtilityFunctions.logException(exception);
}
}
for (final INaviModule naviModule : newModules) {
for (final IDatabaseListener listener : m_listeners) {
try {
listener.addedModule(m_database, naviModule);
} catch (final Exception exception) {
CUtilityFunctions.logException(exception);
}
}
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviRawModule in project binnavi by google.
the class PostgreSQLDatabaseFunctions method findRawModule.
/**
* Returns the raw module with the given ID.
*
* @param rawModuleId The ID to search for.
* @param rawModules The raw modules to search through.
* @return The raw module with the given ID.
*/
protected static INaviRawModule findRawModule(final int rawModuleId, final List<INaviRawModule> rawModules) {
Preconditions.checkArgument(rawModuleId > 0, "Raw module id %s must be positive integer", rawModuleId);
Preconditions.checkNotNull(rawModules, "IE02263: raw modules argument can not be null");
for (final INaviRawModule rawModule : rawModules) {
if (rawModule.getId() == rawModuleId) {
return rawModule;
}
}
throw new IllegalStateException("IE00160: Could not find raw module");
}
use of com.google.security.zynamics.binnavi.disassembly.INaviRawModule in project binnavi by google.
the class PostgreSQLDatabaseFunctions method loadModules.
/**
* Loads the modules of a database.
*
* @param provider The SQL provider that provides the connection.
* @param rawModules Previously loaded raw module objects.
* @param debuggerManager Debugger manager object that belongs to the given database.
*
* @return A list of modules that contains the modules stored in the database.
*
* @throws CouldntLoadDataException Thrown if the modules could not be loaded from the database.
*/
public static List<INaviModule> loadModules(final AbstractSQLProvider provider, final List<INaviRawModule> rawModules, final DebuggerTemplateManager debuggerManager) throws CouldntLoadDataException {
Preconditions.checkNotNull(rawModules, "IE02043: rawModules argument can not be null");
PostgreSQLDatabaseFunctions.checkArguments(provider, debuggerManager);
final List<CModule> modules = new ArrayList<>();
final CConnection connection = provider.getConnection();
if (!PostgreSQLHelpers.hasTable(connection, CTableNames.MODULES_TABLE)) {
return new ArrayList<INaviModule>(modules);
}
final String query = "SELECT id, raw_module_id, " + CTableNames.MODULES_TABLE + ".name, " + " md5, sha1, description, import_time, modification_date, file_base, image_base, stared, " + " initialization_state, debugger_id, " + " (SELECT count(*) FROM " + CTableNames.FUNCTIONS_TABLE + " " + " WHERE id = " + CTableNames.FUNCTIONS_TABLE + ".module_id) " + " AS function_count, " + " (SELECT count(*) FROM " + CTableNames.MODULE_VIEWS_TABLE + " JOIN " + CTableNames.VIEWS_TABLE + " ON view_id = id " + " WHERE type = 'non-native' and module_id = " + CTableNames.MODULES_TABLE + ".id) " + " AS view_count FROM " + CTableNames.MODULES_TABLE + " " + " WHERE raw_module_id IS NOT NULL ORDER BY id";
try (ResultSet resultSet = connection.executeQuery(query, true)) {
while (resultSet.next()) {
final int moduleId = resultSet.getInt("id");
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 timestamp = resultSet.getTimestamp("import_time");
final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
int functionCount = resultSet.getInt("function_count");
final int viewCount = resultSet.getInt("view_count");
final IAddress imageBase = PostgreSQLHelpers.loadAddress(resultSet, "image_base");
final IAddress fileBase = PostgreSQLHelpers.loadAddress(resultSet, "file_base");
final int debuggerId = resultSet.getInt("debugger_id");
final boolean isStared = resultSet.getBoolean("stared");
final int initializationState = resultSet.getInt("initialization_state");
final DebuggerTemplate description = debuggerManager.findDebugger(debuggerId);
final int rawModuleId = resultSet.getInt("raw_module_id");
final INaviRawModule rawModule = PostgreSQLDatabaseFunctions.findRawModule(rawModuleId, rawModules);
if ((functionCount == 0) && (rawModule != null)) {
functionCount = rawModule.getFunctionCount();
}
modules.add(new CModule(moduleId, name, comment, timestamp, modificationDate, md5, sha1, functionCount, viewCount, fileBase, imageBase, description, rawModule, initializationState, isStared, provider));
}
} catch (final SQLException e) {
throw new CouldntLoadDataException(e);
}
return new ArrayList<INaviModule>(modules);
}
use of com.google.security.zynamics.binnavi.disassembly.INaviRawModule in project binnavi by google.
the class PostgreSQLDatabaseFunctions method loadRawModules.
/**
* Loads the raw modules of a database.
*
* @param provider The SQL provider that provides the connection.
*
* @return A list of raw modules that contains the raw modules stored in the database.
*
* @throws CouldntLoadDataException Thrown if the raw modules could not be loaded from the
* database.
*/
public static final List<INaviRawModule> loadRawModules(final AbstractSQLProvider provider) throws CouldntLoadDataException {
Preconditions.checkNotNull(provider, "IE00416: Provider argument can not be null");
final CConnection connection = provider.getConnection();
final List<INaviRawModule> modules = new ArrayList<INaviRawModule>();
if (!PostgreSQLHelpers.hasTable(connection, CTableNames.RAW_MODULES_TABLE)) {
return modules;
}
final String query = "SELECT id, name FROM " + CTableNames.RAW_MODULES_TABLE + " ORDER BY id";
try (ResultSet resultSet = connection.executeQuery(query, true)) {
while (resultSet.next()) {
final int rawModuleId = resultSet.getInt("id");
final String name = PostgreSQLHelpers.readString(resultSet, "name");
final boolean isComplete = PostgreSQLDatabaseFunctions.checkRawModulesTables(provider.getConnection(), PostgreSQLHelpers.getDatabaseName(provider.getConnection()), rawModuleId);
final int functionCount = isComplete ? PostgreSQLDatabaseFunctions.getRawModuleFunctionCount(connection, rawModuleId) : 0;
final CRawModule module = new CRawModule(rawModuleId, name, functionCount, isComplete, provider);
modules.add(module);
}
} catch (final SQLException e) {
throw new CouldntLoadDataException(e);
}
return modules;
}
Aggregations