Search in sources :

Example 21 with TargetProcessThread

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

the class ReplySynchronizer method resetTargetProcess.

/**
   * Resets information about the target process.
   */
protected void resetTargetProcess() {
    final BreakpointManager manager = debugger.getBreakpointManager();
    final ProcessManager processManager = debugger.getProcessManager();
    debugger.setTerminated();
    manager.clearBreakpointsPassive(BreakpointType.ECHO);
    manager.clearBreakpointsPassive(BreakpointType.STEP);
    deactivateBreakpoints();
    processManager.getMemory().clear();
    processManager.setMemoryMap(new MemoryMap(new ArrayList<MemorySection>()));
    final Collection<TargetProcessThread> threads = processManager.getThreads();
    for (final TargetProcessThread thread : threads) {
        processManager.removeThread(thread);
    }
    for (final MemoryModule module : processManager.getModules()) {
        processManager.removeModule(module);
    }
    processManager.setAttached(false);
    processManager.setActiveThread(null);
}
Also used : MemoryMap(com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryMap) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) ArrayList(java.util.ArrayList) BreakpointManager(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointManager) ProcessManager(com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessManager) MemoryModule(com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule)

Example 22 with TargetProcessThread

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

the class StepBreakpointHitSynchronizer method handleSuccess.

@Override
protected void handleSuccess(final StepBreakpointHitReply reply) {
    final BreakpointManager manager = getDebugger().getBreakpointManager();
    final ProcessManager processManager = getDebugger().getProcessManager();
    RelocatedAddress breakpointAddress = 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()) {
                    breakpointAddress = new RelocatedAddress(new CAddress(registerValue.getValue()));
                    break;
                }
            }
        }
    }
    manager.clearBreakpointsPassive(BreakpointType.STEP);
    try {
        final TargetProcessThread thread = processManager.getThread(tid);
        for (final ThreadRegisters threadRegisters : registerValues) {
            if (tid == threadRegisters.getTid()) {
                // Update the thread with the new register values.
                thread.setRegisterValues(threadRegisters.getRegisters());
            }
        }
        processManager.setActiveThread(thread);
        thread.setCurrentAddress(breakpointAddress);
    } catch (final MaybeNullException exception) {
        // Apparently there is no thread with the specified TID.
        // This is not necessarily an error because the thread might have
        // been closed while this handler was active.
        // Nevertheless this should be logged.
        NaviLogger.info("Error: Process manager could not get thread. Exception %s", exception);
        return;
    }
}
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) BreakpointManager(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointManager) 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 23 with TargetProcessThread

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

the class SuspendThreadSynchronizer method handleError.

@Override
protected void handleError(final SuspendThreadReply reply) {
    try {
        final TargetProcessThread thread = getDebugger().getProcessManager().getThread(reply.getThreadId());
        // TODO: In case we can not suspend the thread, we assume that it is really running.
        // This is not correct, however. What really needs to happen is that the debug client
        // sends the real state of the thread in the error message.
        thread.setState(ThreadState.RUNNING);
    } catch (final MaybeNullException exception) {
        // Note: This is not necessary an error situation. Imagine the following
        //
        // 1. Send SuspendThread to the debug client
        // 2. While the command is sent, the thread is closed
        // 3. Debug client can not suspend the thread
        // 4. We land here
        NaviLogger.severe("Error: Tried to suspend 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)

Example 24 with TargetProcessThread

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

the class ProcessTest method testThreads.

@Test
public void testThreads() {
    final MockProcessListener listener = new MockProcessListener();
    final ProcessManager manager = new ProcessManager();
    manager.addThread(new TargetProcessThread(0, ThreadState.RUNNING));
    final Process process = new Process(manager);
    process.addListener(listener);
    final Thread thread1 = process.getThreads().get(0);
    assertEquals(0, thread1.getThreadId());
    final TargetProcessThread thread = new TargetProcessThread(1, ThreadState.RUNNING);
    manager.addThread(thread);
    assertEquals("addedThread/1;", listener.events);
    assertEquals(2, process.getThreads().size());
    manager.removeThread(thread);
    assertEquals("addedThread/1;removedThread/1;", listener.events);
    assertEquals(1, process.getThreads().size());
    process.removeListener(listener);
}
Also used : TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) ProcessManager(com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessManager) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) Test(org.junit.Test)

Example 25 with TargetProcessThread

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

the class CDebugEventNotifier method stop.

/**
   * Stops the event notifier.
   */
public void stop() {
    m_debugger.removeListener(m_debuglistener);
    final ProcessManager processManager = m_debugger.getProcessManager();
    processManager.removeListener(m_processListener);
    for (final TargetProcessThread thread : processManager.getThreads()) {
        thread.removeListener(m_threadEventListener);
    }
}
Also used : TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) ProcessManager(com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessManager)

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