Search in sources :

Example 81 with TargetProcessThread

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

the class CDebuggerSynchronizerTest method testHitBreakpoint_Wellformed.

@Test
public void testHitBreakpoint_Wellformed() throws MessageParserException {
    breakpointManager.addBreakpoints(BreakpointType.REGULAR, CommonTestObjects.BP_ADDRESS_456_SET);
    breakpointManager.setBreakpointStatus(CommonTestObjects.BP_ADDRESS_456_SET, BreakpointType.REGULAR, BreakpointStatus.BREAKPOINT_ACTIVE);
    mockDebugger.getProcessManager().addThread(new TargetProcessThread(CommonTestObjects.THREAD_ID, ThreadState.SUSPENDED));
    debuggerSynchronizer.receivedEvent(DebuggerMessageBuilder.buildRegularBreakpointHit(CommonTestObjects.BP_ADDRESS_456_RELOC));
    assertEquals(0, listener.exception);
    assertEquals(BreakpointStatus.BREAKPOINT_HIT, breakpointManager.getBreakpointStatus(CommonTestObjects.BP_ADDRESS_456, BreakpointType.REGULAR));
}
Also used : TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) Test(org.junit.Test)

Example 82 with TargetProcessThread

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

the class CDebuggerSynchronizerTest method testModuleLifecycle.

/**
   * This test makes sure that the memory module lifecycle (Module Loaded -> Module Unloaded) is
   * working and that the process manager of the debugger is updated correctly.
   *
   * @throws DebugExceptionWrapper
   */
@Test
public void testModuleLifecycle() throws DebugExceptionWrapper {
    assertTrue(mockDebugger.getProcessManager().getModules().isEmpty());
    mockDebugger.connect();
    mockDebugger.getProcessManager().getThreads().clear();
    debuggerSynchronizer.receivedEvent(new ThreadCreatedReply(0, 0, 1000, ThreadState.RUNNING));
    final MemoryModule module = new MemoryModule("hannes.dll", "C:\\hannes.dll", new RelocatedAddress(new CAddress(0x1000000)), 1000);
    debuggerSynchronizer.receivedEvent(new ModuleLoadedReply(0, 0, module, new TargetProcessThread(1000, ThreadState.RUNNING)));
    mockDebugger.getProcessManager().setTargetInformation(new TargetInformation(5, Lists.newArrayList(new RegisterDescription("eax", 4, true), new RegisterDescription("ebx", 4, false)), new DebuggerOptions(false, false, false, false, false, false, false, false, false, false, 12, 0, new ArrayList<DebuggerException>(), false, false, false)));
    assertTrue(mockDebugger.getProcessManager().getModules().size() == 1);
    assertTrue(mockDebugger.getProcessManager().getModules().get(0) == module);
    debuggerSynchronizer.receivedEvent(new ModuleUnloadedReply(0, 0, module));
    assertTrue(mockDebugger.getProcessManager().getModules().isEmpty());
}
Also used : ModuleUnloadedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.ModuleUnloadedReply) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) RegisterDescription(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) DebuggerException(com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerException) TargetInformation(com.google.security.zynamics.binnavi.debug.models.targetinformation.TargetInformation) DebuggerOptions(com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerOptions) ThreadCreatedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.ThreadCreatedReply) ModuleLoadedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.ModuleLoadedReply) MemoryModule(com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 83 with TargetProcessThread

use of com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread 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 84 with TargetProcessThread

use of com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread 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 85 with TargetProcessThread

use of com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread 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)

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