Search in sources :

Example 36 with TargetProcessThread

use of com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread in project binnavi by google.

the class CDebuggerFunctions method stepEnd.

/**
   * Lets the debugger step to the end of the function.
   *
   * @param parent Parent window used for dialogs.
   * @param debugger The debugger that steps to the end of the function.
   * @param graph The graph where the step operation happens.
   */
public static void stepEnd(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 Set<BreakpointAddress> relocatedBlockAddresses = CStepEndHelper.getEndAddresses(graph);
    if (relocatedBlockAddresses.isEmpty()) {
        CMessageBox.showError(parent, "Couldn't step to the end of the function");
        return;
    } else {
        debugger.getProcessManager().setActiveThread(null);
        debugger.getBreakpointManager().addBreakpoints(BreakpointType.STEP, relocatedBlockAddresses);
        try {
            debugger.resume();
        } catch (final DebugExceptionWrapper e) {
            debugger.getBreakpointManager().removeBreakpoints(BreakpointType.STEP, relocatedBlockAddresses);
            debugger.getProcessManager().setActiveThread(activeThread);
            CUtilityFunctions.logException(e);
            final String innerMessage = "E00086: " + "Could not send step end command to the debug client";
            final String innerDescription = CUtilityFunctions.createDescription("BinNavi could not send the step end 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) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress)

Example 37 with TargetProcessThread

use of com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread in project binnavi by google.

the class CStepIntoHotkeyAction method actionPerformed.

@Override
public void actionPerformed(final ActionEvent event) {
    final IDebugger debugger = m_debugPerspectiveModel.getCurrentSelectedDebugger();
    final TargetProcessThread currentThread = debugger == null ? null : debugger.getProcessManager().getActiveThread();
    if (currentThread != null && debugger != null) {
        CDebuggerFunctions.stepInto(m_parent, debugger);
    }
}
Also used : TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) IDebugger(com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger)

Example 38 with TargetProcessThread

use of com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread in project binnavi by google.

the class CMemoryRefreshButtonSynchronizerTest method testSwitchDebugger.

@Test
public void testSwitchDebugger() throws DebugExceptionWrapper {
    final TargetProcessThread thread = new TargetProcessThread(0x666, ThreadState.RUNNING);
    final MemoryModule module = new MemoryModule("narf.exe", "C:\\zort\\narf.exe", new RelocatedAddress(new CAddress(0x1000)), 123345);
    final MockDebugger debugger = new MockDebugger(new ModuleTargetSettings(CommonTestObjects.MODULE));
    debugger.connect();
    debugger.connection.m_synchronizer.receivedEvent(new TargetInformationReply(0, 0, new TargetInformation(32, new FilledList<RegisterDescription>(), new DebuggerOptions(false, false, false, false, false, true, false, false, false, false, 1, 0, new ArrayList<DebuggerException>(), false, false, false))));
    debugger.connection.m_synchronizer.receivedEvent(new ProcessStartReply(0, 0, new ProcessStart(thread, module)));
    final MockDebugger debugger2 = new MockDebugger(new ModuleTargetSettings(CommonTestObjects.MODULE));
    debugger2.connect();
    debugger2.connection.m_synchronizer.receivedEvent(new TargetInformationReply(0, 0, new TargetInformation(32, new FilledList<RegisterDescription>(), new DebuggerOptions(false, false, false, false, false, false, false, false, false, false, 1, 0, new ArrayList<DebuggerException>(), false, false, false))));
    debugger2.connection.m_synchronizer.receivedEvent(new ProcessStartReply(0, 0, new ProcessStart(thread, module)));
    m_model.setActiveDebugger(debugger);
    debugger.getProcessManager().setActiveThread(thread);
    assertTrue(m_refreshButton.isEnabled());
    assertEquals(m_defaultAction, m_refreshButton.getAction());
    m_model.setActiveDebugger(debugger2);
    debugger2.getProcessManager().setActiveThread(thread);
    assertTrue(m_refreshButton.isEnabled());
    assertEquals(m_askAction, m_refreshButton.getAction());
    m_synchronizer.dispose();
    debugger.close();
    debugger2.close();
}
Also used : ProcessStart(com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessStart) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) ArrayList(java.util.ArrayList) DebuggerOptions(com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerOptions) ProcessStartReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.ProcessStartReply) ModuleTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings) MemoryModule(com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) RegisterDescription(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription) TargetInformation(com.google.security.zynamics.binnavi.debug.models.targetinformation.TargetInformation) TargetInformationReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.TargetInformationReply) Test(org.junit.Test)

Example 39 with TargetProcessThread

use of com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread in project binnavi by google.

the class CDebuggerSynchronizerTest method testRegisterValues_UnknownTID.

@Test
public void testRegisterValues_UnknownTID() throws MessageParserException {
    mockDebugger.getProcessManager().addThread(new TargetProcessThread(123, ThreadState.SUSPENDED));
    debuggerSynchronizer.receivedEvent(new RegistersReply(0, 0, RegisterValuesParser.parse(("<Registers><Thread id=\"123\"><Register name=\"EAX\" " + "value=\"123\" memory=\"\" /><Register name=\"EBX\" value=\"456\" memory=\"\" " + "/><Register name=\"EIP\" value=\"999\" memory=\"\" pc=\"true\" /></Thread>" + "</Registers>").getBytes())));
    assertEquals(0, listener.exception);
}
Also used : TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) RegistersReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.RegistersReply) Test(org.junit.Test)

Example 40 with TargetProcessThread

use of com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread in project binnavi by google.

the class CDebuggerSynchronizerTest method testSingleStep_Valid.

@Test
public void testSingleStep_Valid() throws MessageParserException, MaybeNullException {
    breakpointManager.addBreakpoints(BreakpointType.REGULAR, CommonTestObjects.BP_ADDRESS_333_SET);
    breakpointManager.setBreakpointStatus(CommonTestObjects.BP_ADDRESS_333_SET, BreakpointType.REGULAR, BreakpointStatus.BREAKPOINT_HIT);
    mockDebugger.getProcessManager().addThread(new TargetProcessThread(123, ThreadState.SUSPENDED));
    debuggerSynchronizer.receivedEvent(new SingleStepReply(0, 0, 123, new RelocatedAddress(new CAddress(0x999)), RegisterValuesParser.parse(("<Registers><Thread id=\"123\">" + "<Register name=\"EAX\" value=\"123\" memory=\"\" />" + "<Register name=\"EBX\" value=\"456\" memory=\"\" />" + "<Register name=\"EIP\" value=\"999\" memory=\"\" pc=\"true\" />" + "</Thread></Registers>").getBytes())));
    assertEquals(ThreadState.SUSPENDED, mockDebugger.getProcessManager().getThread(123).getState());
    assertEquals(0x999, mockDebugger.getProcessManager().getThread(123).getCurrentAddress().getAddress().toLong());
    assertEquals(0x456, mockDebugger.getProcessManager().getThread(123).getRegisterValues().get(1).getValue().longValue());
    assertEquals(BreakpointStatus.BREAKPOINT_ACTIVE, breakpointManager.getBreakpointStatus(CommonTestObjects.BP_ADDRESS_333, BreakpointType.REGULAR));
}
Also used : SingleStepReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.SingleStepReply) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Aggregations

TargetProcessThread (com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread)91 Test (org.junit.Test)50 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)27 RelocatedAddress (com.google.security.zynamics.binnavi.disassembly.RelocatedAddress)22 TargetInformation (com.google.security.zynamics.binnavi.debug.models.targetinformation.TargetInformation)21 MockDebugger (com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger)20 ModuleTargetSettings (com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings)20 DebuggerOptions (com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerOptions)20 MemoryMap (com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryMap)19 MemorySection (com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection)18 RegisterDescription (com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription)17 IDebugger (com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger)16 TargetInformationReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.TargetInformationReply)15 ArrayList (java.util.ArrayList)15 MemoryMapReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.MemoryMapReply)14 RegisterValue (com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValue)14 MemoryModule (com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule)12 ProcessManager (com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessManager)12 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)10 ThreadRegisters (com.google.security.zynamics.binnavi.debug.models.targetinformation.ThreadRegisters)9