Search in sources :

Example 71 with CouldntSaveDataException

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

the class CGraphSaver method saveAs.

/**
   * Prompts the user for a new graph description and stores a copy of the graph in the database.
   *
   * @param parent Parent window used to display dialogs.
   * @param graph Graph to be written to the database.
   * @param container View container the graph is written to.
   *
   * @return Information about the save progress.
   */
public static CSaveProgress saveAs(final Window parent, final ZyGraph graph, final IViewContainer container) {
    Preconditions.checkNotNull(parent, "IE01754: Parent argument can not be null");
    Preconditions.checkNotNull(graph, "IE01755: Graph argument can not be null");
    final INaviView view = graph.getRawView();
    final CViewCommentDialog dlg = new CViewCommentDialog(parent, "Save", view.getName(), view.getConfiguration().getDescription());
    dlg.setVisible(true);
    if (dlg.wasCancelled()) {
        return new CSaveProgress(true);
    }
    final String newName = dlg.getName();
    final String newDescription = dlg.getComment();
    final CSaveProgress progress = new CSaveProgress(false);
    new Thread() {

        @Override
        public void run() {
            final CViewSaverOperation operation = new CViewSaverOperation(String.format("Saving view '%s'", newName));
            try {
                if (graph.saveAs(container, newName, newDescription) == null) {
                    throw new CouldntSaveDataException("Failure saving the view.");
                }
            } catch (final CouldntSaveDataException e) {
                CUtilityFunctions.logException(e);
                final String innerMessage = "E00121: " + "Could not save graph";
                final String innerDescription = CUtilityFunctions.createDescription(String.format("The view '%s' could not be saved.", newName), new String[] { "There was a problem with the database connection." }, new String[] { "The new view was not created." });
                NaviErrorDialog.show(parent, innerMessage, innerDescription, e);
            } finally {
                operation.stop();
                progress.setDone();
            }
        }
    }.start();
    return progress;
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CViewCommentDialog(com.google.security.zynamics.binnavi.Gui.GraphWindows.CViewCommentDialog) CEndlessHelperThread(com.google.security.zynamics.zylib.gui.ProgressDialogs.CEndlessHelperThread)

Example 72 with CouldntSaveDataException

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

the class CReilConverter method showReilGraph.

/**
   * Turns a view into REIL code and shows a graph that contains that REIL code.
   * 
   * @param parent Window in which the REIL graph is shown.
   * @param viewContainer Context in which the REIL view is generated.
   * @param module Module where the view is created.
   * @param view View to be converted to REIL code.
   */
public static void showReilGraph(final CGraphWindow parent, final IViewContainer viewContainer, final INaviModule module, final INaviView view) {
    final ReilCreationThread thread = new ReilCreationThread(module, view);
    CProgressDialog.showEndless(parent, "Creating REIL graph" + " ...", thread);
    final Exception exception = thread.getException();
    if (exception != null) {
        if (exception instanceof CouldntSaveDataException) {
            CUtilityFunctions.logException(exception);
        // This can never happen because name changes in unsaved views do not throw
        } else {
            CUtilityFunctions.logException(exception);
            final String innerMessage = "E00111: Could not translate view to REIL";
            final String innerDescription = CUtilityFunctions.createDescription(String.format("BinNavi could not create the REIL code of view '%s'.", view.getName()), new String[] { "An error occurred in the REIL translator code." }, new String[] { "This is an internal error which you can not fix yourself. " + "Please report the bug to the zynamics support team." });
            NaviErrorDialog.show(parent, innerMessage, innerDescription);
        }
        return;
    }
    CViewOpener.showView(parent, viewContainer, thread.getReilView(), parent);
}
Also used : CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)

Example 73 with CouldntSaveDataException

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

the class CGraphGrouper method groupNodes.

/**
   * Creates a new group node from a list of nodes.
   * 
   * @param graph The graph where the group node is created.
   * @param nodes The nodes to be grouped.
   */
private static void groupNodes(final ZyGraph graph, final List<NaviNode> nodes) {
    final StringBuilder stringBuilder = new StringBuilder();
    final List<INaviViewNode> rawNodes = new ArrayList<INaviViewNode>();
    // ATTENTION: DO NOT MOVE THIS LINE BELOW THE REMOVEELEMENT LINE
    final INaviGroupNode commonParent = getCommonParent(nodes);
    for (final NaviNode node : nodes) {
        if (node.getRawNode().getParentGroup() != null) {
            node.getRawNode().getParentGroup().removeElement(node.getRawNode());
        }
        rawNodes.add(node.getRawNode());
        stringBuilder.append(determineNodeText(node));
        stringBuilder.append('\n');
    }
    final CGroupNode groupNode = graph.getRawView().getContent().createGroupNode(rawNodes);
    if (commonParent != null) {
        commonParent.addElement(groupNode);
    }
    try {
        groupNode.appendComment(stringBuilder.toString());
    } 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) ArrayList(java.util.ArrayList) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode)

Example 74 with CouldntSaveDataException

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

the class CAddressSpaceContent method setImageBase.

/**
   * Sets the image base of a module inside the address space.
   * 
   * @param module The module in question.
   * @param imageBase The new image base of the module.
   * 
   * @throws CouldntSaveDataException Thrown if the new image base could not be stored to the
   *         database.
   */
public void setImageBase(final INaviModule module, final IAddress imageBase) throws CouldntSaveDataException {
    Preconditions.checkNotNull(module, "IE00045: Module argument can not be null");
    Preconditions.checkNotNull(imageBase, "IE00046: Address argument can not be null");
    Preconditions.checkArgument(m_modules.contains(module), "IE00048: Module is not part of the address space");
    if (imageBase.equals(m_imageBases.get(module))) {
        return;
    }
    m_provider.setImageBase(m_addressSpace, module, imageBase);
    m_imageBases.put(module, imageBase);
    final IDebugger debugger = m_addressSpace.getConfiguration().getDebugger();
    if (debugger != null) {
        debugger.setAddressTranslator(module, module.getConfiguration().getFileBase(), getImageBase(module));
    }
    for (final IAddressSpaceContentListener listener : m_listeners) {
        try {
            listener.changedImageBase(m_addressSpace, module, imageBase);
        } catch (final Exception exception) {
            CUtilityFunctions.logException(exception);
        }
    }
    m_addressSpace.getConfiguration().updateModificationDate();
}
Also used : IDebugger(com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)

Example 75 with CouldntSaveDataException

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

the class CInliningHelper method inlineCodeNode.

/**
   * Inlines the basic blocks of a function into a code node.
   * 
   * @param view The view where the inlining operation takes place.
   * @param originalNode The node where the inlining operation takes place.
   * @param inlineInstruction The function call instruction after which the function is inlined.
   * @param functionToInline The function to be inlined.
   * 
   * @return Contains information about the inlining result.
   */
public static CInliningResult inlineCodeNode(final INaviView view, final INaviCodeNode originalNode, final INaviInstruction inlineInstruction, final INaviFunction functionToInline) {
    Preconditions.checkNotNull(view, "IE00108: View argument can not be null");
    Preconditions.checkNotNull(originalNode, "IE00109: Node argument can not be null");
    Preconditions.checkNotNull(inlineInstruction, "IE00110: Instruction argument can not be null");
    Preconditions.checkArgument(originalNode.hasInstruction(inlineInstruction), "IE00111: Instruction is not part of the code node");
    Preconditions.checkNotNull(functionToInline, "IE00112: Function argument can not be null");
    Preconditions.checkArgument(view.isLoaded(), "IE00113: View must be loaded before it can be inlined");
    Preconditions.checkArgument(view.getGraph().getNodes().contains(originalNode), "IE00114: Code node does not belong to the view");
    Preconditions.checkArgument(functionToInline.isLoaded(), "IE00115: Function must be loaded before it can be inlined");
    Preconditions.checkArgument(functionToInline.getBasicBlockCount() != 0, "IE00116: Functions with 0 blocks can not be inlined");
    final INaviGroupNode parentGroup = originalNode.getParentGroup();
    GroupHelpers.expandParents(originalNode);
    final List<INaviEdge> oldIncomingEdges = originalNode.getIncomingEdges();
    final List<INaviEdge> oldOutgoingEdges = originalNode.getOutgoingEdges();
    // At first we find out which instructions will be part of the new first block
    // and which instructions will be part of the new second block.
    final List<INaviInstruction> upperInstructions = new ArrayList<INaviInstruction>();
    final List<INaviInstruction> lowerInstructions = new ArrayList<INaviInstruction>();
    List<INaviInstruction> currentBlock = upperInstructions;
    for (final INaviInstruction currentInstruction : originalNode.getInstructions()) {
        currentBlock.add(currentInstruction);
        if (currentInstruction == inlineInstruction) {
            currentBlock = lowerInstructions;
        }
    }
    // Now we create the new nodes from the instructions blocks
    INaviCodeNode firstNode;
    final List<INaviViewNode> continueNodes = new ArrayList<INaviViewNode>();
    final boolean keepOriginalBlock = lowerInstructions.isEmpty();
    CCodeNode returnNode = null;
    if (keepOriginalBlock) {
        // There are no instructions in the second block => therefore the call instruction
        // is the last instruction of the block => therefore no splitting is necessary =>
        // therefore we can just reuse the original block.
        firstNode = originalNode;
        for (final INaviEdge edge : originalNode.getOutgoingEdges()) {
            continueNodes.add(edge.getTarget());
            view.getContent().deleteEdge(edge);
        }
    } else {
        // The second block is not empty => the call instruction is somewhere in the middle =>
        // the block must be split => the original block becomes useless and must be replaced by
        // two new blocks.
        final boolean recolor = (originalNode.getIncomingEdges().size() == 1) && (originalNode.getIncomingEdges().get(0).getType() == EdgeType.ENTER_INLINED_FUNCTION) && (originalNode.getOutgoingEdges().size() == 1) && (originalNode.getOutgoingEdges().get(0).getType() == EdgeType.LEAVE_INLINED_FUNCTION);
        view.getContent().deleteNode(originalNode);
        try {
            firstNode = view.getContent().createCodeNode(originalNode.getParentFunction(), upperInstructions);
        } catch (final MaybeNullException exception) {
            firstNode = view.getContent().createCodeNode(null, upperInstructions);
        }
        firstNode.setColor(originalNode.getColor());
        firstNode.setBorderColor(originalNode.getBorderColor());
        try {
            returnNode = view.getContent().createCodeNode(originalNode.getParentFunction(), lowerInstructions);
        } catch (final MaybeNullException e1) {
            returnNode = view.getContent().createCodeNode(null, lowerInstructions);
        }
        returnNode.setColor(originalNode.getColor());
        if (recolor) {
            firstNode.setBorderColor(new Color(-16736256));
            returnNode.setBorderColor(new Color(-6291456));
        }
        if (parentGroup != null) {
            parentGroup.addElement(firstNode);
            parentGroup.addElement(returnNode);
        }
        // Copy the tags of the original node too
        final Iterator<CTag> it = originalNode.getTagsIterator();
        while (it.hasNext()) {
            final CTag tag = it.next();
            try {
                firstNode.tagNode(tag);
                returnNode.tagNode(tag);
            } catch (final CouldntSaveDataException e) {
                CUtilityFunctions.logException(e);
            }
        }
        continueNodes.add(returnNode);
    }
    // Insert the nodes and edges from the loaded function
    final Triple<CCodeNode, List<CCodeNode>, ArrayList<CCodeNode>> nodes = insertNodes(view, functionToInline, parentGroup);
    final INaviCodeNode entryNode = nodes.first();
    final List<CCodeNode> exitNodes = nodes.second();
    if (!keepOriginalBlock) {
        for (final INaviEdge incomingEdge : oldIncomingEdges) {
            if (incomingEdge.getSource() == originalNode) {
                final EdgeType edgeType = incomingEdge.getType();
                view.getContent().createEdge(returnNode, firstNode, edgeType);
            } else {
                final EdgeType edgeType = incomingEdge.getType();
                view.getContent().createEdge(incomingEdge.getSource(), firstNode, edgeType);
            }
        }
    }
    // Create an edge from the upper part of the split block to the entry node
    // of the inlined function.
    view.getContent().createEdge(firstNode, entryNode, EdgeType.ENTER_INLINED_FUNCTION);
    // of the original function where control flow continues.
    for (final INaviCodeNode exitNode : exitNodes) {
        for (final INaviViewNode continueNode : continueNodes) {
            view.getContent().createEdge(exitNode, continueNode, EdgeType.LEAVE_INLINED_FUNCTION);
        }
    }
    if (!keepOriginalBlock) {
        for (final INaviEdge oldChild : oldOutgoingEdges) {
            for (final INaviViewNode continueNode : continueNodes) {
                if (oldChild.getTarget() != originalNode) {
                    view.getContent().createEdge(continueNode, oldChild.getTarget(), oldChild.getType());
                }
            }
        }
    }
    return new CInliningResult(firstNode, returnNode);
}
Also used : MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) Color(java.awt.Color) ArrayList(java.util.ArrayList) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) EdgeType(com.google.security.zynamics.zylib.gui.zygraph.edges.EdgeType) ArrayList(java.util.ArrayList) List(java.util.List) CInliningResult(com.google.security.zynamics.binnavi.disassembly.algorithms.CInliningResult)

Aggregations

CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)133 SQLException (java.sql.SQLException)71 PreparedStatement (java.sql.PreparedStatement)38 CConnection (com.google.security.zynamics.binnavi.Database.CConnection)35 CallableStatement (java.sql.CallableStatement)20 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)17 CouldntDeleteException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)13 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)10 CDefaultProgressOperation (com.google.security.zynamics.binnavi.Gui.Progress.CDefaultProgressOperation)10 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)9 ArrayList (java.util.ArrayList)9 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)8 CComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment)8 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)8 BigInteger (java.math.BigInteger)8 Connection (java.sql.Connection)8 ResultSet (java.sql.ResultSet)8 TraceList (com.google.security.zynamics.binnavi.debug.models.trace.TraceList)7 LoadCancelledException (com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException)6 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)5