Search in sources :

Example 26 with MaybeNullException

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

the class CMenuBuilder method addSelectionMenus.

/**
 * Adds menus related to node selection to a given node context menu.
 *
 * @param menu The node context menu to extend.
 * @param graph The graph the clicked node belongs to.
 * @param node The clicked node.
 */
public static void addSelectionMenus(final JPopupMenu menu, final ZyGraph graph, final NaviNode node) {
    Preconditions.checkNotNull(menu, "IE02144: Menu argument can not be null");
    Preconditions.checkNotNull(graph, "IE02145: Graph argument can not be null");
    Preconditions.checkNotNull(node, "IE02146: Node argument can not be null");
    final JMenu selectionMenu = new JMenu("Selection");
    selectionMenu.add(CActionProxy.proxy(new CActionSelectNodePredecessors(graph, node)));
    selectionMenu.add(CActionProxy.proxy(new CActionSelectNodeSuccessors(graph, node)));
    if (graph.getSelectedNodes().size() > 0) {
        selectionMenu.add(CActionProxy.proxy(new CGroupAction(graph)));
    }
    if (node.getRawNode() instanceof INaviCodeNode) {
        try {
            final INaviFunction parentFunction = ((INaviCodeNode) node.getRawNode()).getParentFunction();
            selectionMenu.add(CActionProxy.proxy(new CActionSelectSameParentFunction(graph, parentFunction)));
        } catch (final MaybeNullException exception) {
        // Obviously we can not select nodes of the same parent function if there
        // is no parent function.
        }
    } else if (node.getRawNode() instanceof INaviFunctionNode) {
        final INaviFunction function = ((INaviFunctionNode) node.getRawNode()).getFunction();
        selectionMenu.add(CActionProxy.proxy(new CActionSelectSameFunctionType(graph, function.getType())));
    }
    menu.add(selectionMenu);
    menu.addSeparator();
}
Also used : CActionSelectNodeSuccessors(com.google.security.zynamics.binnavi.ZyGraph.Menus.Actions.CActionSelectNodeSuccessors) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) CActionSelectSameParentFunction(com.google.security.zynamics.binnavi.ZyGraph.Menus.Actions.CActionSelectSameParentFunction) CGroupAction(com.google.security.zynamics.binnavi.Gui.GraphWindows.Actions.CGroupAction) CActionSelectSameFunctionType(com.google.security.zynamics.binnavi.ZyGraph.Menus.Actions.CActionSelectSameFunctionType) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) JMenu(javax.swing.JMenu) CActionSelectNodePredecessors(com.google.security.zynamics.binnavi.ZyGraph.Menus.Actions.CActionSelectNodePredecessors)

Example 27 with MaybeNullException

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

the class CCodeNodeMenu method addRegisterOperandMenu.

private void addRegisterOperandMenu(final CGraphModel model, final COperandTreeNode treeNode, final INaviInstruction instruction, final List<ICodeNodeExtension> extensions, final INaviCodeNode codeNode) {
    try {
        add(new COperandsMenu(codeNode, instruction, extensions));
    } catch (final InternalTranslationException | MaybeNullException exception) {
        CUtilityFunctions.logException(exception);
    }
    final TypeManager typeManager = model.getViewContainer().getModules().get(0).getTypeManager();
    if (treeNode.getTypeSubstitution() == null) {
        add(TypeSubstitutionAction.instantiateCreateTypeSubstitution(model.getParent(), typeManager, getStackFrame(model), treeNode));
    } else {
        add(new DeleteTypeSubstitutionMenuAction(typeManager, treeNode));
        add(TypeSubstitutionAction.instantiateEditTypeSubstitution(model.getParent(), typeManager, getStackFrame(model), treeNode));
    }
    addSeparator();
}
Also used : MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) TypeManager(com.google.security.zynamics.binnavi.disassembly.types.TypeManager) InternalTranslationException(com.google.security.zynamics.reil.translators.InternalTranslationException)

Example 28 with MaybeNullException

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

the class CNodeFunctions method splitAfter.

/**
 * Splits a node.
 *
 * @param view View the node belongs to.
 * @param originalNode Node to split.
 * @param instruction Instruction after which the node is split.
 */
public static void splitAfter(final INaviView view, final INaviCodeNode originalNode, final INaviInstruction instruction) {
    final Iterable<INaviInstruction> oldInstructions = originalNode.getInstructions();
    if (instruction == Iterables.getLast(oldInstructions)) {
        return;
    }
    // Step I: Find out what instructions belong to the new upper block and what
    // instructions belong to the new lower block.
    final List<INaviInstruction> upperInstructions = new ArrayList<INaviInstruction>();
    final List<INaviInstruction> lowerInstructions = new ArrayList<INaviInstruction>();
    List<INaviInstruction> currentInstructions = upperInstructions;
    for (final INaviInstruction oldInstruction : oldInstructions) {
        currentInstructions.add(oldInstruction);
        if (oldInstruction == instruction) {
            currentInstructions = lowerInstructions;
        }
    }
    // Step II: Create the two new code nodes.
    INaviFunction parentFunction = null;
    try {
        parentFunction = originalNode.getParentFunction();
    } catch (final MaybeNullException e) {
    // No parent function
    }
    final INaviCodeNode newNode1 = view.getContent().createCodeNode(parentFunction, upperInstructions);
    final INaviCodeNode newNode2 = view.getContent().createCodeNode(parentFunction, lowerInstructions);
    newNode1.setColor(originalNode.getColor());
    newNode1.setBorderColor(originalNode.getBorderColor());
    newNode2.setColor(originalNode.getColor());
    // Step III: Transfer node comments and instruction comments from the old node
    // to the new nodes.
    transferLocalCodeNodeComments(originalNode, newNode1, newNode2);
    // Step IV: Connect the two new nodes.
    view.getContent().createEdge(newNode1, newNode2, EdgeType.JUMP_UNCONDITIONAL);
    for (final INaviEdge incomingEdge : originalNode.getIncomingEdges()) {
        view.getContent().createEdge(incomingEdge.getSource(), newNode1, incomingEdge.getType());
    }
    for (final INaviEdge outgoingEdge : originalNode.getOutgoingEdges()) {
        view.getContent().createEdge(newNode2, outgoingEdge.getTarget(), outgoingEdge.getType());
    }
    // Step VI: Get rid of the old node.
    view.getContent().deleteNode(originalNode);
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) ArrayList(java.util.ArrayList) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 29 with MaybeNullException

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

the class BreakpointHitSynchronizer method handleSuccess.

/**
 * Handles incoming Breakpoint Hit replies.
 *
 * @param reply The incoming Breakpoint Hit reply to handle.
 */
@Override
protected void handleSuccess(final BreakpointHitReply reply) {
    final ProcessManager processManager = getDebugger().getProcessManager();
    // When the debug client notifies BinNavi that a
    // breakpoint was hit, it is necessary to mark the
    // breakpoint as hit.
    // TODO: Check for success
    RelocatedAddress eventAddress = null;
    final RegisterValues registerValues = reply.getRegisterValues();
    final long tid = reply.getThreadId();
    for (final ThreadRegisters threadRegisters : registerValues) {
        if (tid == threadRegisters.getTid()) {
            for (final RegisterValue registerValue : threadRegisters) {
                if (registerValue.isPc()) {
                    eventAddress = new RelocatedAddress(new CAddress(registerValue.getValue()));
                }
            }
        }
    }
    if (eventAddress != null) {
        updateHitBreakpoints(DebuggerHelpers.getBreakpointAddress(getDebugger(), eventAddress));
    } else {
        throw new IllegalStateException("IE00173: register reply did not include program counter");
    }
    try {
        final TargetProcessThread thread = processManager.getThread(reply.getThreadId());
        // Update the thread with the new register values.
        for (final ThreadRegisters threadRegisters : registerValues) {
            if (tid == threadRegisters.getTid()) {
                thread.setRegisterValues(threadRegisters.getRegisters());
                break;
            }
        }
        processManager.setActiveThread(thread);
        thread.setCurrentAddress(eventAddress);
    } catch (final MaybeNullException exception) {
        NaviLogger.info("Error: there is no thread with the specified thread id %d Exception: %s", reply.getThreadId(), exception);
    }
}
Also used : RegisterValue(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValue) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) ThreadRegisters(com.google.security.zynamics.binnavi.debug.models.targetinformation.ThreadRegisters) ProcessManager(com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessManager) RegisterValues(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValues) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 30 with MaybeNullException

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

the class ExceptionOccurredSynchronizer method handleSuccess.

@Override
protected void handleSuccess(final ExceptionOccurredReply reply) {
    final ProcessManager processManager = getDebugger().getProcessManager();
    try {
        final TargetProcessThread thread = processManager.getThread(reply.getThreadId());
        processManager.setActiveThread(thread);
        thread.setCurrentAddress(reply.getAddress());
        processManager.addExceptionEvent(new DebuggerException(reply.getExceptionName(), reply.getExceptionCode(), DebuggerExceptionHandlingAction.Continue));
        refreshRegisters();
    } catch (final MaybeNullException exception) {
        NaviLogger.severe("Exception occured in unknown thread %d", reply.getThreadId());
    }
}
Also used : TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) DebuggerException(com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerException) ProcessManager(com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessManager)

Aggregations

MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)42 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)11 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)11 TargetProcessThread (com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread)10 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)8 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)7 SQLException (java.sql.SQLException)7 ProcessManager (com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessManager)6 CallableStatement (java.sql.CallableStatement)6 ArrayList (java.util.ArrayList)5 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)4 INaviFunctionNode (com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode)4 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)4 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)4 CouldntDeleteException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)3 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)3 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)3 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)3 CConnection (com.google.security.zynamics.binnavi.Database.CConnection)2 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)2