Search in sources :

Example 31 with CouldntLoadDataException

use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException in project binnavi by google.

the class PostgreSQLViewLoader method loadView.

/**
   * Loads the graph of a view from the database.
   * 
   * @param provider The SQL provider that provides the connection.
   * @param view The view to load.
   * @param list A list of all modules that are part of the database.
   * @param nodeTagManager Node tag manager of the database.
   * 
   * @return The graph of the view.
   * 
   * @throws CouldntLoadDataException Thrown if the graph of view could not be loaded.
   * @throws CPartialLoadException Thrown if the graph could not be loaded because not all required
   *         modules are loaded.
   */
public static MutableDirectedGraph<INaviViewNode, INaviEdge> loadView(final AbstractSQLProvider provider, final INaviView view, final List<INaviModule> list, final CTagManager nodeTagManager) throws CouldntLoadDataException, CPartialLoadException {
    checkArguments(provider, view, list, nodeTagManager);
    try {
        final List<INaviViewNode> nodes = PostgreSQLNodeLoader.loadNodes(provider, view, list, nodeTagManager);
        NodeCache.get(provider).addNodes(nodes);
        final List<INaviEdge> edges = PostgreSQLEdgeLoader.loadEdges(provider, view, nodes);
        EdgeCache.get(provider).addEdges(edges);
        return new MutableDirectedGraph<INaviViewNode, INaviEdge>(nodes, edges);
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException(exception);
    }
}
Also used : SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) MutableDirectedGraph(com.google.security.zynamics.zylib.types.graphs.MutableDirectedGraph)

Example 32 with CouldntLoadDataException

use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException in project binnavi by google.

the class PostgreSQLCommentNotificationParser method parse.

@Override
public Collection<CommentNotification> parse(final Collection<PGNotification> commentNotifications, final SQLProvider provider) {
    Preconditions.checkNotNull(commentNotifications, "Error: commentNotifications argument can not be null");
    Preconditions.checkNotNull(provider, "IE02524: provider argument can not be null");
    for (final PGNotification notification : commentNotifications) {
        final String notificationParameter = notification.getParameter();
        final String tableName = notificationParameter.split("\\s")[0];
        try {
            switch(tableName) {
                case CTableNames.CODENODE_INSTRUCTIONS_TABLE:
                    informNotification(processNodeLocalInstructionCommentNotification(notification, provider), provider);
                    break;
                case CTableNames.INSTRUCTIONS_TABLE:
                    informNotification(processInstructionGlobalCommentNotification(notification, provider), provider);
                    break;
                case CTableNames.CODE_NODES_TABLE:
                    informNotification(processNodeLocalNodeCommentNotification(notification, provider), provider);
                    break;
                case CTableNames.GLOBAL_NODE_COMMENTS_TABLE:
                    informNotification(processNodeGlobalCommentNotification(notification, provider), provider);
                    break;
                case CTableNames.EDGES_TABLE:
                    informNotification(processEdgeLocalCommentNotification(notification, provider), provider);
                    break;
                case CTableNames.GLOBAL_EDGE_COMMENTS_TABLE:
                    informNotification(processEdgeGlobalCommentNotification(notification, provider), provider);
                    break;
                case CTableNames.FUNCTION_NODES_TABLE:
                    informNotification(processFunctionNodeCommentNotification(notification, provider), provider);
                    break;
                case CTableNames.FUNCTIONS_TABLE:
                    informNotification(processFunctionCommentNotification(notification, provider), provider);
                    break;
                case CTableNames.TEXT_NODES_TABLE:
                    informNotification(processTextNodeCommentNotification(notification, provider), provider);
                    break;
                case CTableNames.GROUP_NODES_TABLE:
                    informNotification(processGroupNodeCommentNotification(notification, provider), provider);
                    break;
                case CTableNames.TYPE_INSTANCE_TABLE:
                    informNotification(processTypeInstanceCommentNotification(notification, provider), provider);
                    break;
                case CTableNames.COMMENTS_TABLE:
                    informNotification(processCommentNotification(notification, provider), provider);
                    break;
                default:
                    NaviLogger.warning("Table name %s not known", tableName);
            }
        } catch (CouldntLoadDataException exception) {
            NaviLogger.severe("Error: Could not successfully parse the database comment notification: %s", notification.toString());
        }
    }
    // TODO(timkornau): change the interface to not return anything here.
    return new ArrayList<>();
}
Also used : CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ArrayList(java.util.ArrayList) PGNotification(org.postgresql.PGNotification)

Example 33 with CouldntLoadDataException

use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException in project binnavi by google.

the class PostgreSQLHelpers method getTableCount.

/**
   * Determines the number of tables known to the database. The given list of table names is used as
   * query information source.
   *
   * @param connection The {@link CConnection} to access the database.
   * @param tableNames The List of table names which are queried for in the database.
   * @return The number of tables in the database
   * @throws CouldntLoadDataException if the query execution failed.
   */
public static int getTableCount(final CConnection connection, final List<String> tableNames) throws CouldntLoadDataException {
    Preconditions.checkNotNull(connection, "Error: connection argument can not be null");
    final StringBuilder builder = new StringBuilder("SELECT count(*) FROM pg_class WHERE relname in (");
    for (String tableName : tableNames) {
        builder.append("'" + tableName + "',");
    }
    builder.deleteCharAt(builder.length() - 1);
    builder.append(")");
    try (ResultSet result = connection.executeQuery(builder.toString(), true)) {
        while (result.next()) {
            return result.getInt("count");
        }
    } catch (final SQLException e) {
        throw new CouldntLoadDataException(e);
    }
    throw new IllegalStateException("Error: Could not retrieve table count from server");
}
Also used : SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ResultSet(java.sql.ResultSet)

Example 34 with CouldntLoadDataException

use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException in project binnavi by google.

the class RenameTypeInstanceAction method actionPerformed.

@Override
public void actionPerformed(final ActionEvent e) {
    final EditVariableDialog dialog = EditVariableDialog.CreateEditVariableDialog(parent, typeInstance.getName());
    dialog.setVisible(true);
    if (dialog.wasOkClicked()) {
        try {
            instanceContainer.setInstanceName(typeInstance, dialog.getVariableName());
        } catch (CouldntSaveDataException | CouldntLoadDataException exception) {
            CUtilityFunctions.logException(exception);
        }
    }
}
Also used : CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) EditVariableDialog(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.EditVariableDialog)

Example 35 with CouldntLoadDataException

use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException 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)

Aggregations

CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)85 SQLException (java.sql.SQLException)53 ResultSet (java.sql.ResultSet)47 ArrayList (java.util.ArrayList)30 PreparedStatement (java.sql.PreparedStatement)27 CConnection (com.google.security.zynamics.binnavi.Database.CConnection)20 LoadCancelledException (com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException)17 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)16 HashMap (java.util.HashMap)12 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)10 BigInteger (java.math.BigInteger)9 CPartialLoadException (com.google.security.zynamics.binnavi.Database.Exceptions.CPartialLoadException)8 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)8 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)8 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)8 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)7 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)6 Set (java.util.Set)6 CouldntDeleteException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)5 CDefaultProgressOperation (com.google.security.zynamics.binnavi.Gui.Progress.CDefaultProgressOperation)5