Search in sources :

Example 1 with FileReadException

use of com.google.security.zynamics.binnavi.config.FileReadException in project binnavi by google.

the class StandAlone method getPluginInterface.

// ! Returns the BinNavi plugin interface.
/**
 * Returns the plugin interface that can be used from stand-alone scripts.
 *
 * @return The plugin interface that can be used from stand-alone scripts.
 */
public static synchronized PluginInterface getPluginInterface() {
    try {
        ConfigManager.instance().read();
    } catch (final FileReadException exception) {
        NaviLogger.severe("Error: could not read config file.");
    }
    final CDatabaseManager manager = CDatabaseManager.instance();
    final PluginRegistry registry = new PluginRegistry();
    if (pluginInterface == null) {
        pluginInterface = PluginInterface.instance("", /* start path */
        manager, registry);
    }
    return pluginInterface;
}
Also used : PluginRegistry(com.google.security.zynamics.binnavi.Plugins.PluginRegistry) CDatabaseManager(com.google.security.zynamics.binnavi.Database.CDatabaseManager) FileReadException(com.google.security.zynamics.binnavi.config.FileReadException)

Example 2 with FileReadException

use of com.google.security.zynamics.binnavi.config.FileReadException in project binnavi by google.

the class PostgreSQLTypeInstanceFunctionsTests method setUp.

@Before
public void setUp() throws IOException, CouldntLoadDriverException, CouldntConnectException, IllegalStateException, CouldntLoadDataException, InvalidDatabaseException, CouldntInitializeDatabaseException, CouldntSaveDataException, InvalidExporterDatabaseFormatException, InvalidDatabaseVersionException, LoadCancelledException, FileReadException {
    final String[] parts = CConfigLoader.loadPostgreSQL();
    database = new CDatabase("None", CJdbcDriverNames.jdbcPostgreSQLDriverName, parts[0], "test_disassembly", parts[1], parts[2], parts[3], false, false);
    database.connect();
    database.load();
    try {
        final Field privateProviderField = CDatabase.class.getDeclaredField("provider");
        privateProviderField.setAccessible(true);
        provider = (SQLProvider) privateProviderField.get(database);
    } catch (final Exception exception) {
        throw new RuntimeException(exception);
    }
    provider.createDebuggerTemplate("Test Debugger", "localhost", 2222);
    final CProject project = provider.createProject("Test Project");
    provider.createAddressSpace(project, "Test Address Space");
    ConfigManager.instance().read();
    module = database.getContent().getModules().get(0);
}
Also used : Field(java.lang.reflect.Field) CProject(com.google.security.zynamics.binnavi.disassembly.CProject) CDatabase(com.google.security.zynamics.binnavi.Database.CDatabase) LoadCancelledException(com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException) CouldntInitializeDatabaseException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntInitializeDatabaseException) CouldntLoadDriverException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDriverException) InvalidExporterDatabaseFormatException(com.google.security.zynamics.binnavi.Database.Exceptions.InvalidExporterDatabaseFormatException) FileReadException(com.google.security.zynamics.binnavi.config.FileReadException) InvalidDatabaseException(com.google.security.zynamics.binnavi.Database.Exceptions.InvalidDatabaseException) CouldntConnectException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntConnectException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) IOException(java.io.IOException) InvalidDatabaseVersionException(com.google.security.zynamics.binnavi.Database.Exceptions.InvalidDatabaseVersionException) CPartialLoadException(com.google.security.zynamics.binnavi.Database.Exceptions.CPartialLoadException) CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException) Before(org.junit.Before)

Example 3 with FileReadException

use of com.google.security.zynamics.binnavi.config.FileReadException in project binnavi by google.

the class CConfigurationFileCreator method setupConfigurationFile.

/**
 * Loads and initializes the configuration file.
 *
 * @return False, if the configuration file already existed. True, if it was created.
 */
public static boolean setupConfigurationFile() {
    try {
        final FileHandler fileHandler = new FileHandler(NAVI_LOG_FILE, MAX_LOG_FILE_SIZE, LOG_ROTATE_COUNT);
        fileHandler.setFormatter(new NaviLogFormatter());
        NaviLogger.addHandler(fileHandler);
    } catch (final IOException exception) {
        CUtilityFunctions.logException(exception);
        final String message = "E00002: " + "Could not create the log file";
        final String description = CUtilityFunctions.createDescription(String.format("BinNavi could not create the log file '%s'.", NAVI_LOG_FILE), new String[] { "Some kind of IO problem occurred. Please check the stack trace " + "for more details" }, new String[] { "The error log file can not be stored" });
        NaviErrorDialog.show(null, message, description, exception);
    }
    NaviLogger.info("Loading configuration file");
    try {
        return ConfigManager.instance().read();
    } catch (final FileReadException exception) {
        CUtilityFunctions.logException(exception);
        final String configFileName = ConfigHelper.getConfigFileName(Constants.COMPANY_NAME, Constants.PROJECT_NAME, Constants.CONFIG_FILE_NAME);
        final String message = "E00003: " + "Malformed configuration file";
        final String description = CUtilityFunctions.createDescription(String.format("The configuration file '%s' could not be read because it contains " + "malformed XML.", configFileName), new String[] { "You edited the configuration file manually and made a mistake", "The configuration file was corrupted randomly" }, new String[] { "After closing this dialog you will be asked if you want to run " + "BinNavi with default settings or if you want to repair the configuration " + "file manually." });
        NaviErrorDialog.show(null, message, description, exception);
        if (JOptionPane.YES_OPTION != CMessageBox.showYesNoQuestion(null, "Do you want to run BinNavi with default settings? If you choose 'No', " + "BinNavi will exit so you can repair the configuration file manually.")) {
            // Before running BinNavi, the problem with the configuration file should be fixed.
            System.exit(0);
        }
        final File file = new File(configFileName);
        if (!file.delete()) {
            final String innerMessage = "E00004: " + "Could not delete malformed configuration file";
            final String innerDescription = CUtilityFunctions.createDescription(String.format("The malformed configuration file '%s' could not be deleted.", configFileName), new String[] { "The configuration file is in use by another program", "Some kind of IO problem occurred" }, new String[] { "BinNavi will exit after you close this error dialog and you " + "will have to delete or fix the malformed configuration file manually." });
            NaviErrorDialog.show(null, innerMessage, innerDescription);
            System.exit(0);
        }
        try {
            // the configuration file again, the configuration file should be newly created.
            return ConfigManager.instance().read();
        } catch (final FileReadException e) {
            // This should actually never happen.
            final String innerMessage = "E00005: " + "Could not create configuration file";
            final String innerDescription = CUtilityFunctions.createDescription(String.format("BinNavi could not create the new configuration file '%s'.", configFileName), new String[] { "Some kind of IO problem occurred" }, new String[] { "BinNavi will exit after you close this error dialog. Try to " + "find out why the configuration file could not be created. " + "You may also want to contact the BinNavi support at this point." });
            NaviErrorDialog.show(null, innerMessage, innerDescription);
            System.exit(0);
        }
        return false;
    }
}
Also used : NaviLogFormatter(com.google.security.zynamics.binnavi.Log.NaviLogFormatter) IOException(java.io.IOException) FileReadException(com.google.security.zynamics.binnavi.config.FileReadException) File(java.io.File) FileHandler(java.util.logging.FileHandler)

Aggregations

FileReadException (com.google.security.zynamics.binnavi.config.FileReadException)3 IOException (java.io.IOException)2 CDatabase (com.google.security.zynamics.binnavi.Database.CDatabase)1 CDatabaseManager (com.google.security.zynamics.binnavi.Database.CDatabaseManager)1 CPartialLoadException (com.google.security.zynamics.binnavi.Database.Exceptions.CPartialLoadException)1 CouldntConnectException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntConnectException)1 CouldntDeleteException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)1 CouldntInitializeDatabaseException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntInitializeDatabaseException)1 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)1 CouldntLoadDriverException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDriverException)1 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)1 InvalidDatabaseException (com.google.security.zynamics.binnavi.Database.Exceptions.InvalidDatabaseException)1 InvalidDatabaseVersionException (com.google.security.zynamics.binnavi.Database.Exceptions.InvalidDatabaseVersionException)1 InvalidExporterDatabaseFormatException (com.google.security.zynamics.binnavi.Database.Exceptions.InvalidExporterDatabaseFormatException)1 LoadCancelledException (com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException)1 NaviLogFormatter (com.google.security.zynamics.binnavi.Log.NaviLogFormatter)1 PluginRegistry (com.google.security.zynamics.binnavi.Plugins.PluginRegistry)1 CProject (com.google.security.zynamics.binnavi.disassembly.CProject)1 File (java.io.File)1 Field (java.lang.reflect.Field)1