Search in sources :

Example 11 with DebugExceptionWrapper

use of com.google.security.zynamics.binnavi.debug.debugger.DebugExceptionWrapper 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 12 with DebugExceptionWrapper

use of com.google.security.zynamics.binnavi.debug.debugger.DebugExceptionWrapper in project binnavi by google.

the class CDebuggerFunctions method stepInto.

/**
 * Lets the debugger execute a single step.
 *
 * @param parent Parent window used for dialogs.
 * @param debugger The debugger that executes the single step.
 */
public static void stepInto(final JFrame parent, final IDebugger debugger) {
    checkArguments(parent, debugger);
    if (!debugger.isConnected()) {
        return;
    }
    final TargetProcessThread activeThread = debugger.getProcessManager().getActiveThread();
    try {
        debugger.getProcessManager().setActiveThread(null);
        debugger.singleStep();
    } catch (final DebugExceptionWrapper e) {
        CUtilityFunctions.logException(e);
        debugger.getProcessManager().setActiveThread(activeThread);
        final String innerMessage = "E00192: " + "Could not send single step command to the debug client";
        final String innerDescription = CUtilityFunctions.createDescription("BinNavi could not send the single step 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) DebugExceptionWrapper(com.google.security.zynamics.binnavi.debug.debugger.DebugExceptionWrapper)

Example 13 with DebugExceptionWrapper

use of com.google.security.zynamics.binnavi.debug.debugger.DebugExceptionWrapper in project binnavi by google.

the class Debugger method writeRegister.

// ! Writes a register value.
/**
 * Changes the value of a register in the given thread.
 *
 * @param tid Thread ID of the thread whose register value is changed.
 * @param register Name of the register to change.
 * @param value The new value of the register.
 *
 * @throws DebugException Thrown if the message could not be sent to the debug client.
 */
public void writeRegister(final long tid, final String register, final long value) throws DebugException {
    Preconditions.checkNotNull(register, "Error: Register argument can not be null");
    Preconditions.checkNotNull(m_debugger.getProcessManager().getTargetInformation(), "Error: Target information string has not yet been received");
    final List<RegisterDescription> registers = m_debugger.getProcessManager().getTargetInformation().getRegisters();
    int index = 0;
    for (final RegisterDescription description : registers) {
        if (description.getName().equalsIgnoreCase(register)) {
            if (!description.isEditable()) {
                throw new IllegalArgumentException("Error: Selected register can not be edited");
            }
            break;
        }
        index++;
    }
    if (index == registers.size()) {
        throw new IllegalArgumentException("Error: Unknown register name");
    }
    try {
        m_debugger.setRegister(tid, index, BigInteger.valueOf(value));
    } catch (final DebugExceptionWrapper e) {
        throw new DebugException(e);
    }
}
Also used : RegisterDescription(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription) DebugExceptionWrapper(com.google.security.zynamics.binnavi.debug.debugger.DebugExceptionWrapper)

Aggregations

DebugExceptionWrapper (com.google.security.zynamics.binnavi.debug.debugger.DebugExceptionWrapper)13 TargetProcessThread (com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread)5 BreakpointAddress (com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress)3 RelocatedAddress (com.google.security.zynamics.binnavi.disassembly.RelocatedAddress)3 MemoryModule (com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule)2 ProcessManager (com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessManager)2 TargetInformation (com.google.security.zynamics.binnavi.debug.models.targetinformation.TargetInformation)2 UnrelocatedAddress (com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress)2 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)2 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)1 CRemoteSelectionDialog (com.google.security.zynamics.binnavi.Gui.Debug.RemoteBrowser.CRemoteSelectionDialog)1 IDebugger (com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger)1 ProcessDescription (com.google.security.zynamics.binnavi.debug.models.processlist.ProcessDescription)1 DebuggerEventSettingsStorage (com.google.security.zynamics.binnavi.debug.models.storage.DebuggerEventSettingsStorage)1 RegisterDescription (com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription)1 File (java.io.File)1 HashSet (java.util.HashSet)1