Search in sources :

Example 6 with CPartialLoadException

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

the class CModuleFunctions method copyView.

/**
   * Copies a view into a module view.
   * 
   * @param parent Parent window used for dialogs.
   * @param module Module where the copied view is stored.
   * @param view The view to copy.
   */
public static void copyView(final JFrame parent, final INaviModule module, final INaviView view) {
    Preconditions.checkNotNull(parent, "IE01832: Parent argument can not be null");
    Preconditions.checkNotNull(module, "IE01833: Module argument can not be null");
    Preconditions.checkNotNull(view, "IE01834: View argument can not be null");
    if (module.getContent().getViewContainer().hasView(view)) {
        if (!view.isLoaded()) {
            try {
                view.load();
            } catch (final CouldntLoadDataException e) {
                CUtilityFunctions.logException(e);
                final String innerMessage = "E00133: View could not be copied";
                final String innerDescription = CUtilityFunctions.createDescription(String.format("The view '%s' could not be copied because it could not be loaded.", view.getName()), new String[] { "There was a problem with the database connection." }, new String[] { "The new view was not created." });
                NaviErrorDialog.show(parent, innerMessage, innerDescription, e);
                return;
            } catch (CPartialLoadException | LoadCancelledException e) {
                CUtilityFunctions.logException(e);
                return;
            }
        }
        final CView newView = module.getContent().getViewContainer().createView(String.format("Copy of %s", view.getName()), null);
        CViewInserter.insertView(view, newView);
    }
}
Also used : CView(com.google.security.zynamics.binnavi.disassembly.views.CView) CPartialLoadException(com.google.security.zynamics.binnavi.Database.Exceptions.CPartialLoadException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) LoadCancelledException(com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException)

Example 7 with CPartialLoadException

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

the class PostgreSQLFunctionNodeLoader method load.

/**
   * Loads the function nodes of a view.
   * 
   * @param provider The connection to the database.
   * @param view The view whose function nodes are loaded.
   * @param nodes The loaded nodes are stored here.
   * 
   * @throws CPartialLoadException Thrown if loading the nodes failed because a necessary module was
   *         not loaded.
   * @throws CouldntLoadDataException
   */
public static void load(final AbstractSQLProvider provider, final INaviView view, final List<INaviViewNode> nodes) throws CPartialLoadException, CouldntLoadDataException {
    Preconditions.checkNotNull(provider, "IE02510: provider argument can not be null");
    Preconditions.checkNotNull(view, "IE02511: view argument can not be null");
    Preconditions.checkNotNull(nodes, "IE02512: nodes argument can not be null");
    // TODO (timkornau): query needs to go into the database.
    final String query = "SELECT nodes.view_id, nodes.id, functions.module_id, " + " function, fnodes.comment_id as local_comment, x, y, width, height, " + " color, selected, visible FROM " + CTableNames.NODES_TABLE + " AS nodes JOIN " + CTableNames.FUNCTION_NODES_TABLE + " AS fnodes " + " ON nodes.id = fnodes.node_id JOIN " + CTableNames.FUNCTIONS_TABLE + " AS functions ON functions.address = fnodes.function " + " AND functions.module_id = fnodes.module_id  WHERE view_id = ?";
    final Map<Integer, INaviFunctionNode> commentIdToFunctionNode = new HashMap<Integer, INaviFunctionNode>();
    try {
        final PreparedStatement statement = provider.getConnection().getConnection().prepareStatement(query);
        statement.setInt(1, view.getConfiguration().getId());
        final ResultSet resultSet = statement.executeQuery();
        try {
            while (resultSet.next()) {
                final int moduleId = resultSet.getInt("module_id");
                final INaviModule module = provider.findModule(moduleId);
                if (!module.isLoaded()) {
                    try {
                        module.load();
                    } catch (final CouldntLoadDataException e) {
                        throw new CPartialLoadException("E00064: The view could not be loaded because not all modules that form the view are loaded", module);
                    } catch (final LoadCancelledException e) {
                        throw new CPartialLoadException("E00065: The view could not be loaded because not all modules that form the view are loaded", module);
                    }
                }
                final IAddress address = PostgreSQLHelpers.loadAddress(resultSet, "function");
                final INaviFunction function = module.getContent().getFunctionContainer().getFunction(address);
                final int nodeId = resultSet.getInt("id");
                Integer commentId = resultSet.getInt("local_comment");
                if (resultSet.wasNull()) {
                    commentId = null;
                }
                final double posX = resultSet.getDouble("x");
                final double posY = resultSet.getDouble("y");
                final double width = resultSet.getDouble("width");
                final double height = resultSet.getDouble("height");
                final Color color = new Color(resultSet.getInt("color"));
                final boolean selected = resultSet.getBoolean("selected");
                final boolean visible = resultSet.getBoolean("visible");
                final INaviFunctionNode functionNode = new CFunctionNode(nodeId, function, posX, posY, width, height, color, selected, visible, null, new HashSet<CTag>(), provider);
                nodes.add(functionNode);
                if (commentId != null) {
                    commentIdToFunctionNode.put(commentId, functionNode);
                }
            }
        } finally {
            resultSet.close();
        }
        if (!commentIdToFunctionNode.isEmpty()) {
            final HashMap<Integer, ArrayList<IComment>> commentIdsToComments = PostgreSQLCommentFunctions.loadMultipleCommentsById(provider, commentIdToFunctionNode.keySet());
            for (final Entry<Integer, ArrayList<IComment>> commentIdToComment : commentIdsToComments.entrySet()) {
                commentIdToFunctionNode.get(commentIdToComment.getKey()).initializeLocalFunctionComment(commentIdToComment.getValue());
            }
        }
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException(exception);
    }
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) CPartialLoadException(com.google.security.zynamics.binnavi.Database.Exceptions.CPartialLoadException) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) Color(java.awt.Color) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) ResultSet(java.sql.ResultSet) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) LoadCancelledException(com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction)

Aggregations

CPartialLoadException (com.google.security.zynamics.binnavi.Database.Exceptions.CPartialLoadException)7 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)7 LoadCancelledException (com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException)5 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)4 CView (com.google.security.zynamics.binnavi.disassembly.views.CView)3 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)2 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)2 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)2 Color (java.awt.Color)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 CModuleViewGenerator (com.google.security.zynamics.binnavi.Database.CModuleViewGenerator)1 CProjectViewGenerator (com.google.security.zynamics.binnavi.Database.CProjectViewGenerator)1 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)1 CFunctionNode (com.google.security.zynamics.binnavi.disassembly.CFunctionNode)1 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)1 INaviFunctionNode (com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode)1 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1