Search in sources :

Example 41 with CouldntLoadDataException

use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException 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();
    }
}
Also used : InvalidDatabaseVersionException(com.google.security.zynamics.binnavi.Database.Exceptions.InvalidDatabaseVersionException) CouldntUpdateDatabaseException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntUpdateDatabaseException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) CouldntInitializeDatabaseException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntInitializeDatabaseException) InvalidExporterDatabaseFormatException(com.google.security.zynamics.binnavi.Database.Exceptions.InvalidExporterDatabaseFormatException) CouldntLoadDriverException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDriverException) CDefaultProgressOperation(com.google.security.zynamics.binnavi.Gui.Progress.CDefaultProgressOperation) InvalidDatabaseException(com.google.security.zynamics.binnavi.Database.Exceptions.InvalidDatabaseException) CouldntConnectException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntConnectException) LoadCancelledException(com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException)

Example 42 with CouldntLoadDataException

use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException 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;
}
Also used : CPartialLoadException(com.google.security.zynamics.binnavi.Database.Exceptions.CPartialLoadException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) Color(java.awt.Color) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) LoadCancelledException(com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction)

Example 43 with CouldntLoadDataException

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

the class GenericCommentsTableModel method keyPressedOrTyped.

@Override
public /**
   * Please read the comment in the base class regarding this method - it is somewhat counter-
   * intuitive for people used to the Swing keyboard handling model.
   */
void keyPressedOrTyped(CodeDisplayCoordinate coordinate, KeyEvent event) {
    int commentRow = coordinate.getRow();
    IComment comment = null;
    if (commentRow < cachedComments.size()) {
        comment = cachedComments.get(commentRow);
    }
    if (!isEditable(coordinate)) {
        return;
    }
    switch(event.getKeyCode()) {
        // VK_UNDEFINED implies that this was a KEY_TYPED event.
        case KeyEvent.VK_UNDEFINED:
            if (commentRow >= cachedComments.size()) {
                // Create a new comment.
                try {
                    commentAccessor.appendComment(String.format("%c", event.getKeyChar()));
                    coordinate.setFieldIndex(1);
                } catch (CouldntSaveDataException | CouldntLoadDataException e) {
                    CUtilityFunctions.logException(e);
                }
                resetCachedComments();
                // the handling code below.
                break;
            }
            switch(event.getKeyChar()) {
                case KeyEvent.VK_ENTER:
                    comment = handleRegularKeyInComment(comment, coordinate, event);
                    coordinate.setLine(coordinate.getLine() < (comment.getNumberOfCommentLines() - 1) ? coordinate.getLine() + 1 : comment.getNumberOfCommentLines() - 1);
                    coordinate.setFieldIndex(0);
                    break;
                case KeyEvent.VK_BACK_SPACE:
                    comment = handleBackspaceKeyInComment(comment, coordinate);
                    break;
                case KeyEvent.VK_DELETE:
                    comment = handleDeleteKeyInComment(comment, coordinate);
                    break;
                default:
                    comment = handleRegularKeyInComment(comment, coordinate, event);
                    coordinate.setFieldIndex(coordinate.getFieldIndex() + 1);
                    break;
            }
            break;
        case KeyEvent.VK_HOME:
            coordinate.setFieldIndex(0);
            break;
        case KeyEvent.VK_END:
            coordinate.setFieldIndex(columns[coordinate.getColumn()].getWidth());
            break;
        default:
            throw new IllegalArgumentException();
    }
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)

Example 44 with CouldntLoadDataException

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

the class CDebuggerFunctions method sendDebuggerEventSettings.

public static void sendDebuggerEventSettings(final JFrame parent, final IDebugger debugger, final DebugTargetSettings debugTarget) {
    try {
        final DebuggerEventSettingsStorage eventSettingsStorage = new DebuggerEventSettingsStorage(debugger, debugTarget);
        debugger.setDebuggerEventSettings(eventSettingsStorage.deserialize());
    } catch (final DebugExceptionWrapper exception) {
        CUtilityFunctions.logException(exception);
        final String message = "Debugger event settings could not be sent to the debugger.";
        final String description = CUtilityFunctions.createDescription(String.format("BinNavi could not send the debugger event settings to the debug client."), new String[] {}, new String[] { "The default debugger event settings will be used during this session." });
        NaviErrorDialog.show(parent, message, description, exception);
    } catch (final CouldntLoadDataException exception) {
        CUtilityFunctions.logException(exception);
        final String message = "Debugger event settings could not be retrieved from the database.";
        final String description = CUtilityFunctions.createDescription(String.format("BinNavi could not send the debugger event settings to the debug client."), new String[] {}, new String[] { "The default debugger event settings will be used during this session." });
        NaviErrorDialog.show(parent, message, description, exception);
    }
}
Also used : DebuggerEventSettingsStorage(com.google.security.zynamics.binnavi.debug.models.storage.DebuggerEventSettingsStorage) DebugExceptionWrapper(com.google.security.zynamics.binnavi.debug.debugger.DebugExceptionWrapper) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)

Example 45 with CouldntLoadDataException

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

the class PostgreSQLEdgeLoader method loadEdges.

/**
   * Loads the edges of a view.
   *
   * @param provider The connection to the database.
   * @param view The view whose edges are loaded.
   * @param nodeLookup Maps between node IDs and their corresponding node objects.
   * @param edgeToGlobalCommentMap Maps between edge IDs and their associated comments.
   *
   * @return The loaded edges.
   *
   * @throws CouldntLoadDataException
   */
private static List<INaviEdge> loadEdges(final AbstractSQLProvider provider, final INaviView view, final Map<Integer, INaviViewNode> nodeLookup, final Map<Integer, ArrayList<IComment>> edgeToGlobalCommentMap) throws CouldntLoadDataException {
    final String query = "SELECT * FROM load_view_edges(" + view.getConfiguration().getId() + ")";
    List<CBend> currentPaths = new ArrayList<CBend>();
    final Map<Integer, INaviEdge> commentIdToEdge = new HashMap<Integer, INaviEdge>();
    final Map<Integer, INaviEdge> edgeIdToEdge = new HashMap<Integer, INaviEdge>();
    try {
        final CConnection connection = provider.getConnection();
        final PreparedStatement statement = connection.getConnection().prepareStatement(query);
        final ResultSet resultSet = statement.executeQuery();
        try {
            while (resultSet.next()) {
                final int edgeId = resultSet.getInt("id");
                if (edgeIdToEdge.containsKey(edgeId)) {
                    final INaviEdge edge = edgeIdToEdge.get(edgeId);
                    final double pathX = resultSet.getDouble("x");
                    final double pathY = resultSet.getDouble("y");
                    if (!resultSet.wasNull()) {
                        edge.addBend(pathX, pathY);
                    }
                    continue;
                }
                final int sourceNode = resultSet.getInt("source_node_id");
                final int targetNode = resultSet.getInt("target_node_id");
                Integer localCommentId = resultSet.getInt("comment_id");
                if (resultSet.wasNull()) {
                    localCommentId = null;
                }
                final double x1 = resultSet.getDouble("x1");
                final double y1 = resultSet.getDouble("y1");
                final double x2 = resultSet.getDouble("x2");
                final double y2 = resultSet.getDouble("y2");
                final EdgeType type = EdgeType.valueOf(resultSet.getString("type").toUpperCase());
                final Color color = new Color(resultSet.getInt("color"));
                final boolean visible = resultSet.getBoolean("visible");
                final boolean selected = resultSet.getBoolean("selected");
                final INaviViewNode source = nodeLookup.get(sourceNode);
                final INaviViewNode target = nodeLookup.get(targetNode);
                final double pathX = resultSet.getDouble("x");
                final double pathY = resultSet.getDouble("y");
                if (!resultSet.wasNull()) {
                    currentPaths.add(new CBend(pathX, pathY));
                }
                final CNaviViewEdge edge = new CNaviViewEdge(edgeId, source, target, type, x1, y1, x2, y2, color, selected, visible, null, currentPaths, provider);
                if (localCommentId != null) {
                    commentIdToEdge.put(localCommentId, edge);
                }
                final ArrayList<IComment> globalComments = edgeToGlobalCommentMap.containsKey(edgeId) ? edgeToGlobalCommentMap.get(edgeId) : null;
                if ((globalComments != null) && (globalComments.size() != 0)) {
                    initializeGlobalComment(edge, globalComments, provider);
                }
                source.addOutgoingEdge(edge);
                target.addIncomingEdge(edge);
                edgeIdToEdge.put(edge.getId(), edge);
                currentPaths = new ArrayList<CBend>();
            }
            if (!commentIdToEdge.isEmpty()) {
                final HashMap<Integer, ArrayList<IComment>> commentIdToComments = PostgreSQLCommentFunctions.loadMultipleCommentsById(provider, commentIdToEdge.keySet());
                for (final Entry<Integer, ArrayList<IComment>> commentIdToComment : commentIdToComments.entrySet()) {
                    commentIdToEdge.get(commentIdToComment.getKey()).initializeLocalComment(commentIdToComment.getValue());
                }
            }
        } finally {
            resultSet.close();
        }
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException("Error: Loading of view edges failed");
    }
    return Lists.newArrayList(edgeIdToEdge.values());
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ArrayList(java.util.ArrayList) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) CBend(com.google.security.zynamics.zylib.gui.zygraph.edges.CBend) ResultSet(java.sql.ResultSet) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) Color(java.awt.Color) PreparedStatement(java.sql.PreparedStatement) EdgeType(com.google.security.zynamics.zylib.gui.zygraph.edges.EdgeType) CConnection(com.google.security.zynamics.binnavi.Database.CConnection) CNaviViewEdge(com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge)

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