Search in sources :

Example 81 with BreakpointAddress

use of com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress in project binnavi by google.

the class MockDebugger method setBreakPoints.

@Override
public void setBreakPoints(final Set<BreakpointAddress> breakpoints, final BreakpointType type) throws DebugExceptionWrapper {
    requests += "SET_BREAKPOINTS/";
    for (final BreakpointAddress breakpointAddress : breakpoints) {
        requests += breakpointAddress.getAddress().getAddress().toHexString();
        requests += "/";
        requests += type;
    }
    requests += ";";
    processCounter();
}
Also used : BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress)

Example 82 with BreakpointAddress

use of com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress in project binnavi by google.

the class CDebuggerFunctions method stepBlock.

/**
   * Lets the debugger step to the next block.
   *
   * @param parent Parent window used for dialogs.
   * @param debugger The debugger that steps to the next block.
   * @param graph The graph where the step operation happens.
   */
public static void stepBlock(final JFrame parent, final IDebugger debugger, final ZyGraph graph) {
    checkArguments(parent, debugger, graph);
    if (!debugger.isConnected()) {
        return;
    }
    final TargetProcessThread activeThread = debugger.getProcessManager().getActiveThread();
    if (activeThread == null) {
        return;
    }
    final RelocatedAddress currentAddress = activeThread.getCurrentAddress();
    if (currentAddress == null) {
        CMessageBox.showError(parent, "Could not step because the selected thread is not suspended");
        return;
    }
    final UnrelocatedAddress oldAddress = debugger.memoryToFile(currentAddress);
    final Set<BreakpointAddress> relocatedBlockAddresses = CStepBlockHelper.getNextBlocks(graph, oldAddress);
    if (relocatedBlockAddresses.isEmpty()) {
        CMessageBox.showError(parent, "Couldn't step to the next block");
        return;
    } else {
        debugger.getProcessManager().setActiveThread(null);
        final Set<BreakpointAddress> setBreakpoints = new HashSet<BreakpointAddress>();
        debugger.getBreakpointManager().addBreakpoints(BreakpointType.STEP, relocatedBlockAddresses);
        setBreakpoints.addAll(relocatedBlockAddresses);
        try {
            debugger.resume();
        } catch (final DebugExceptionWrapper e) {
            // TODO: Step breakpoints should be removed at this point
            debugger.getProcessManager().setActiveThread(activeThread);
            CUtilityFunctions.logException(e);
            final String innerMessage = "E00045: " + "Could not send step block command to the debug client";
            final String innerDescription = CUtilityFunctions.createDescription("BinNavi could not send the step block command to the debug client.", new String[] { "There was a problem with the connection to the debug client." }, new String[] { "The state of the debugged process remains unchanged." });
            NaviErrorDialog.show(parent, innerMessage, innerDescription, e);
        }
    }
}
Also used : TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) DebugExceptionWrapper(com.google.security.zynamics.binnavi.debug.debugger.DebugExceptionWrapper) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) HashSet(java.util.HashSet)

Example 83 with BreakpointAddress

use of com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress in project binnavi by google.

the class CDebuggerFunctions method stepOver.

/**
   * Lets the debugger step over the next instruction.
   *
   * @param parent Parent window used for dialogs.
   * @param debugger The debugger that steps over the next instruction.
   * @param graph The graph where the step operation happens.
   */
public static void stepOver(final JFrame parent, final IDebugger debugger, final ZyGraph graph) {
    checkArguments(parent, debugger, graph);
    if (!debugger.isConnected()) {
        return;
    }
    final TargetProcessThread activeThread = debugger.getProcessManager().getActiveThread();
    if (activeThread == null) {
        return;
    }
    final RelocatedAddress currentAddress = activeThread.getCurrentAddress();
    if (currentAddress == null) {
        CMessageBox.showError(parent, "Could not step because the selected thread is not suspended");
        return;
    }
    final UnrelocatedAddress oldAddress = debugger.memoryToFile(currentAddress);
    final Set<BreakpointAddress> relocatedAddresses = CStepOverHelper.getNextInstructions(graph, oldAddress);
    if (relocatedAddresses.isEmpty()) {
        CMessageBox.showError(parent, "Couldn't step over the current instruction");
        return;
    } else {
        debugger.getProcessManager().setActiveThread(null);
        debugger.getBreakpointManager().addBreakpoints(BreakpointType.STEP, relocatedAddresses);
        try {
            debugger.resume();
        } catch (final DebugExceptionWrapper e) {
            // TODO: Step breakpoints should be removed at this point
            debugger.getProcessManager().setActiveThread(activeThread);
            CUtilityFunctions.logException(e);
            final String innerMessage = "E00087: " + "Could not send step over command to the debug client";
            final String innerDescription = CUtilityFunctions.createDescription("BinNavi could not send the step over command to the debug client.", new String[] { "There was a problem with the connection to the debug client." }, new String[] { "The state of the debugged process remains unchanged." });
            NaviErrorDialog.show(parent, innerMessage, innerDescription, e);
        }
    }
}
Also used : TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) DebugExceptionWrapper(com.google.security.zynamics.binnavi.debug.debugger.DebugExceptionWrapper) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress)

Example 84 with BreakpointAddress

use of com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress in project binnavi by google.

the class CStepEndHelper method getEndAddresses.

/**
   * Returns the addresses of all final instructions of a graph.
   *
   * @param graph The graph whose final addresses are returned.
   *
   * @return The final addresses of the graph.
   */
public static Set<BreakpointAddress> getEndAddresses(final ZyGraph graph) {
    final Set<BreakpointAddress> instructions = new HashSet<BreakpointAddress>();
    graph.iterate(new INodeCallback<NaviNode>() {

        @Override
        public IterationMode next(final NaviNode node) {
            if ((node.getRawNode() instanceof INaviCodeNode) && node.getChildren().isEmpty()) {
                final INaviCodeNode cnode = (INaviCodeNode) node.getRawNode();
                final INaviInstruction lastInstruction = Iterables.getLast(cnode.getInstructions());
                instructions.add(new BreakpointAddress(lastInstruction.getModule(), new UnrelocatedAddress(lastInstruction.getAddress())));
            }
            return IterationMode.CONTINUE;
        }
    });
    return instructions;
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) IterationMode(com.google.security.zynamics.zylib.types.common.IterationMode) HashSet(java.util.HashSet) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 85 with BreakpointAddress

use of com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress in project binnavi by google.

the class CStepOverHelper method stepInCodeNode.

/**
   * Adds the addresses of a instructions that follow another instruction to a list when
   * single-stepping in a code node.
   * 
   * @param node The code node where the step over operation happens.
   * @param address The address in question.
   * @param instructions List to extend with the successor instructions.
   */
private static void stepInCodeNode(final INaviCodeNode node, final UnrelocatedAddress address, final Set<BreakpointAddress> instructions) {
    final int instructionIndex = CCodeNodeHelpers.getInstruction(node, address.getAddress());
    if (instructionIndex != -1) {
        if (instructionIndex < node.instructionCount() - 1) {
            // ... and the basic block is large enough that the following
            // instruction is also part of the basic block.
            final INaviInstruction instruction = Iterables.get(node.getInstructions(), instructionIndex + 1);
            instructions.add(new BreakpointAddress(instruction.getModule(), new UnrelocatedAddress(instruction.getAddress())));
        } else {
            // ... but the instruction is the last instruction of the basic block,
            // so we have to look into the child nodes of the basic block.
            instructions.addAll(CSteppingHelper.getSuccessors(node));
        }
    }
}
Also used : UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Aggregations

BreakpointAddress (com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress)87 UnrelocatedAddress (com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress)60 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)49 Test (org.junit.Test)39 HashSet (java.util.HashSet)24 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)22 MockDebugger (com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger)15 ModuleTargetSettings (com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings)15 Breakpoint (com.google.security.zynamics.binnavi.debug.models.breakpoints.Breakpoint)15 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)13 Address (com.google.security.zynamics.binnavi.API.disassembly.Address)11 BreakpointManager (com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointManager)11 TraceList (com.google.security.zynamics.binnavi.debug.models.trace.TraceList)11 ArrayList (java.util.ArrayList)9 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)8 DebugTargetSettings (com.google.security.zynamics.binnavi.debug.debugger.DebugTargetSettings)8 DebuggerProvider (com.google.security.zynamics.binnavi.debug.debugger.DebuggerProvider)8 CBreakpointTableModel (com.google.security.zynamics.binnavi.Gui.Debug.BreakpointTable.CBreakpointTableModel)7 TraceLogger (com.google.security.zynamics.binnavi.debug.models.trace.TraceLogger)7 ITraceEvent (com.google.security.zynamics.binnavi.debug.models.trace.interfaces.ITraceEvent)7