Search in sources :

Example 1 with CPartialLoadException

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

the class CProjectContent method createView.

/**
   * Creates a new empty view with the given name and description in the project. The new view is
   * not stored in the database until INaviView::save is called.
   * 
   * @param name The name of the new view.
   * @param description The description of the new view.
   * 
   * @return The new view that was created in the project.
   */
public INaviView createView(final String name, final String description) {
    final Date date = new Date();
    final CProjectViewGenerator generator = new CProjectViewGenerator(m_provider, m_project);
    final CView view = generator.generate(-1, name, description, ViewType.NonNative, GraphType.MIXED_GRAPH, date, date, 0, 0, new HashSet<CTag>(), new HashSet<CTag>(), false);
    try {
        view.load();
    } catch (CouldntLoadDataException | CPartialLoadException | LoadCancelledException e) {
        // This can not happen; new views with ID -1 do not access the database
        // when they are loaded.
        CUtilityFunctions.logException(e);
    }
    addView(view);
    return view;
}
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) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) LoadCancelledException(com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException) CProjectViewGenerator(com.google.security.zynamics.binnavi.Database.CProjectViewGenerator) Date(java.util.Date)

Example 2 with CPartialLoadException

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

the class CViewContainer method createView.

/**
   * Creates a new empty view in the module.
   *
   * @param name The name of the new view.
   * @param description The description of the new view.
   *
   * @return The new view.
   */
public CView createView(final String name, final String description) {
    Preconditions.checkNotNull(name, "IE00164: Name argument can not be null");
    Preconditions.checkNotNull(description, "IE00165: Name description can not be null");
    final Date date = new Date();
    final CModuleViewGenerator generator = new CModuleViewGenerator(m_provider, m_module);
    final CView view = generator.generate(-1, name, description, ViewType.NonNative, GraphType.MIXED_GRAPH, date, date, 0, 0, new HashSet<CTag>(), new HashSet<CTag>(), false);
    try {
        view.load();
    } catch (CouldntLoadDataException | CPartialLoadException | LoadCancelledException e) {
        CUtilityFunctions.logException(e);
    }
    addView(view);
    return view;
}
Also used : CView(com.google.security.zynamics.binnavi.disassembly.views.CView) CModuleViewGenerator(com.google.security.zynamics.binnavi.Database.CModuleViewGenerator) CPartialLoadException(com.google.security.zynamics.binnavi.Database.Exceptions.CPartialLoadException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) LoadCancelledException(com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException) Date(java.util.Date)

Example 3 with CPartialLoadException

use of com.google.security.zynamics.binnavi.Database.Exceptions.CPartialLoadException 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 4 with CPartialLoadException

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

the class CCodeNodeParser method parse.

/**
   * Takes the information from the components passed into the constructor and creates a list of
   * nodes from that information.
   *
   * @return The list of nodes created by the parser.
   *
   * @throws ParserException Thrown if the instruction data could not be loaded.
   * @throws CPartialLoadException Thrown if not all necessary modules are loaded.
   */
public List<CCodeNode> parse() throws ParserException, CPartialLoadException {
    // it to point to the proper data.
    if (!dataProvider.next()) {
        return new ArrayList<CCodeNode>();
    }
    // Generate the nodes from the raw data.
    while (true) {
        if (dataProvider.isAfterLast()) {
            if (currentNode != null) {
                nodes.add(currentNode);
            }
            break;
        }
        nodes.add(extractNode(dataProvider));
    }
    final HashSet<Integer> allComments = Sets.newHashSet();
    allComments.addAll(localCommentIdToCodeNode.keySet());
    allComments.addAll(globalCommentIdToCodeNode.keySet());
    allComments.addAll(globalCommentIdToInstruction.keySet());
    allComments.addAll(localCommentIdToInstruction.keySet());
    try {
        final HashMap<Integer, ArrayList<IComment>> commentIdToComments = sqlProvider.loadMultipleCommentsById(allComments);
        for (final Entry<Integer, ArrayList<IComment>> commentIdToComment : commentIdToComments.entrySet()) {
            if (localCommentIdToCodeNode.containsKey(commentIdToComment.getKey())) {
                localCommentIdToCodeNode.get(commentIdToComment.getKey()).getComments().initializeLocalCodeNodeComment(commentIdToComment.getValue());
            }
            if (globalCommentIdToCodeNode.containsKey(commentIdToComment.getKey())) {
                globalCommentIdToCodeNode.get(commentIdToComment.getKey()).getComments().initializeGlobalCodeNodeComment(commentIdToComment.getValue());
            }
            if (localCommentIdToInstruction.containsKey(commentIdToComment.getKey())) {
                final Pair<INaviInstruction, INaviCodeNode> instructionToCodeNode = localCommentIdToInstruction.get(commentIdToComment.getKey());
                instructionToCodeNode.second().getComments().initializeLocalInstructionComment(instructionToCodeNode.first(), commentIdToComment.getValue());
            }
            if (globalCommentIdToInstruction.containsKey(commentIdToComment.getKey())) {
                globalCommentIdToInstruction.get(commentIdToComment.getKey()).initializeGlobalComment(commentIdToComment.getValue());
            }
        }
    } catch (final CouldntLoadDataException exception) {
        throw new CPartialLoadException("Error: Comments could not be loaded.", null);
    }
    return nodes;
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) CPartialLoadException(com.google.security.zynamics.binnavi.Database.Exceptions.CPartialLoadException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ArrayList(java.util.ArrayList) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 5 with CPartialLoadException

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

the class CViewLoader method load.

/**
   * Loads a view and shows an error message if the view can not be loaded.
   *
   * @param parent Parent window used for error dialogs.
   * @param container Context in which the view is loaded.
   * @param view View to be loaded.
   */
public static void load(final JFrame parent, final IViewContainer container, final INaviView view) {
    Preconditions.checkNotNull(parent, "IE00011: Parent argument can not be null");
    Preconditions.checkNotNull(container, "IE00012: Container argument can not be null");
    Preconditions.checkNotNull(view, "IE00013: View argument can not be null");
    if (view.isLoaded()) {
        return;
    }
    final ViewLoaderThread thread = new ViewLoaderThread(view);
    CProgressDialog.showEndless(parent, String.format("Loading view '%s'", view.getName()), thread);
    final Exception exception = thread.getException();
    if (exception != null) {
        if (exception instanceof CouldntLoadDataException) {
            CUtilityFunctions.logException(exception);
            final String message = "E00050: Could not load view";
            final String description = CUtilityFunctions.createDescription(String.format("The view '%s' could not be loaded.", view.getName()), new String[] { "There were problems with the database connection.", "Malformed data was found in the database." }, new String[] { "The view was not loaded." });
            NaviErrorDialog.show(parent, message, description, exception);
        } else if (exception instanceof CPartialLoadException) {
            CUtilityFunctions.logException(exception);
            final String moduleName = ((CPartialLoadException) exception).getModule().getConfiguration().getName();
            final String message = "E00051: Could not load view";
            final String description = CUtilityFunctions.createDescription(String.format("The view '%s' could not be loaded because it " + "depends on the unloaded module '%s'.", view.getName(), moduleName), new String[] { String.format("Module '%s' is not loaded.", moduleName) }, new String[] { String.format("The view can not be loaded before the module '%s' is loaded.", moduleName) });
            NaviErrorDialog.show(parent, message, description, exception);
        }
    }
}
Also used : CPartialLoadException(com.google.security.zynamics.binnavi.Database.Exceptions.CPartialLoadException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) CPartialLoadException(com.google.security.zynamics.binnavi.Database.Exceptions.CPartialLoadException)

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