Search in sources :

Example 51 with TargetProcessThread

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

the class ResumeThreadSynchronizer method handleSuccess.

@Override
protected void handleSuccess(final ResumeThreadReply reply) {
    try {
        final TargetProcessThread thread = getDebugger().getProcessManager().getThread(reply.getThreadId());
        thread.setState(ThreadState.RUNNING);
    } catch (final MaybeNullException exception) {
        // Unlike in the error case, this is really a bug.
        NaviLogger.severe("Error: Tried to resume 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 52 with TargetProcessThread

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

the class ResumeThreadSynchronizer method handleError.

@Override
protected void handleError(final ResumeThreadReply reply) {
    try {
        final TargetProcessThread thread = getDebugger().getProcessManager().getThread(reply.getThreadId());
        // TODO: In case we can not resume the thread, we assume that it is really suspended.
        // 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.SUSPENDED);
    } catch (final MaybeNullException exception) {
        // Note: This is not necessary an error situation. Imagine the following
        //
        // 1. Send ResumeThread to the debug client
        // 2. While the command is sent, the thread is closed
        // 3. Debug client can not resume the thread
        // 4. We land here
        NaviLogger.severe("Error: Tried to resume 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 53 with TargetProcessThread

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

the class SingleStepSynchronizer method handleSuccess.

@Override
protected void handleSuccess(final SingleStepReply reply) {
    final ProcessManager processManager = getDebugger().getProcessManager();
    final long tid = reply.getThreadId();
    try {
        // Find the thread object with the specified TID
        final TargetProcessThread thread = processManager.getThread(tid);
        // At the end of a single step event, a thread is automatically suspended.
        processManager.setActiveThread(thread);
        // Update the thread object with the values from the event.
        setRegisterValues(reply.getRegisterValues());
        updateHitBreakpoints(DebuggerHelpers.getBreakpointAddress(getDebugger(), thread.getCurrentAddress()));
    } catch (final MaybeNullException e) {
        // 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.
        NaviLogger.info("Error: Process manager could not get thread. Exception %s", e);
    }
}
Also used : TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) ProcessManager(com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessManager)

Example 54 with TargetProcessThread

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

the class SuspendThreadSynchronizer method handleSuccess.

@Override
protected void handleSuccess(final SuspendThreadReply reply) {
    try {
        final TargetProcessThread thread = getDebugger().getProcessManager().getThread(reply.getThreadId());
        thread.setState(ThreadState.SUSPENDED);
    } catch (final MaybeNullException exception) {
        // Unlike in the error case, this is really a bug.
        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 55 with TargetProcessThread

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

the class DebuggerTest method testListeners3.

@SuppressWarnings("unchecked")
@Test
public void testListeners3() throws MessageParserException, DebugExceptionWrapper, MaybeNullException {
    mockDebugger.connect();
    mockDebugger.getProcessManager().addThread(new TargetProcessThread(0, ThreadState.RUNNING));
    mockDebugger.getProcessManager().getThread(0).setCurrentAddress(new RelocatedAddress(new CAddress(0)));
    mockDebugger.connection.m_synchronizer.receivedEvent(new ResumeThreadReply(0, 0, 0));
    mockDebugger.connection.m_synchronizer.receivedEvent(new ResumeThreadReply(0, 1, 0));
    mockDebugger.connection.m_synchronizer.receivedEvent(new SearchReply(0, 0, new CAddress(0)));
    mockDebugger.connection.m_synchronizer.receivedEvent(new SearchReply(0, 1, null));
    mockDebugger.connection.m_synchronizer.receivedEvent(new SelectFileReply(0, 0));
    mockDebugger.connection.m_synchronizer.receivedEvent(new SelectFileReply(0, 1));
    mockDebugger.getProcessManager().addThread(new TargetProcessThread(0, ThreadState.RUNNING));
    mockDebugger.getProcessManager().getThread(0).setCurrentAddress(new RelocatedAddress(new CAddress(0)));
    mockDebugger.connection.m_synchronizer.receivedEvent(new SetRegisterReply(0, 0, 0, 0));
    mockDebugger.connection.m_synchronizer.receivedEvent(new SetRegisterReply(0, 1, 0, 0));
    mockDebugger.connection.m_synchronizer.receivedEvent(new SingleStepReply(0, 0, 0, new RelocatedAddress(new CAddress(0)), new RegisterValues(new FilledList<ThreadRegisters>())));
    mockDebugger.connection.m_synchronizer.receivedEvent(new SingleStepReply(0, 1, 0, new RelocatedAddress(new CAddress(0)), new RegisterValues(new FilledList<ThreadRegisters>())));
    mockDebugger.connection.m_synchronizer.receivedEvent(new StepBreakpointHitReply(0, 0, 1, new RegisterValues(Lists.<ThreadRegisters>newArrayList(new ThreadRegisters(1, Lists.newArrayList(new RegisterValue("eip", BigInteger.ONE, new byte[0], false, false)))))));
    mockDebugger.connection.m_synchronizer.receivedEvent(new StepBreakpointHitReply(0, 0, 1, new RegisterValues(Lists.<ThreadRegisters>newArrayList(new ThreadRegisters(1, Lists.newArrayList(new RegisterValue("eip", BigInteger.ONE, new byte[0], true, false)))))));
    mockDebugger.getBreakpointManager().addBreakpoints(BreakpointType.STEP, CommonTestObjects.BP_ADDRESS_123_SET);
    mockDebugger.connection.m_synchronizer.receivedEvent(new StepBreakpointSetReply(0, 0, Lists.newArrayList(new Pair<RelocatedAddress, Integer>(CommonTestObjects.BP_ADDRESS_123_RELOC, 0))));
    mockDebugger.connection.m_synchronizer.receivedEvent(new StepBreakpointSetReply(0, 1, Lists.newArrayList(new Pair<RelocatedAddress, Integer>(CommonTestObjects.BP_ADDRESS_123_RELOC, 1))));
    mockDebugger.connection.m_synchronizer.receivedEvent(new StepBreakpointsRemovedReply(0, 0, Lists.newArrayList(new Pair<RelocatedAddress, Integer>(CommonTestObjects.BP_ADDRESS_123_RELOC, 0))));
    mockDebugger.connection.m_synchronizer.receivedEvent(new StepBreakpointsRemovedReply(0, 1, Lists.newArrayList(new Pair<RelocatedAddress, Integer>(CommonTestObjects.BP_ADDRESS_123_RELOC, 1))));
    mockDebugger.connection.m_synchronizer.receivedEvent(new SuspendThreadReply(0, 0, 0));
    mockDebugger.connection.m_synchronizer.receivedEvent(new SuspendThreadReply(0, 1, 0));
    mockDebugger.connection.m_synchronizer.receivedEvent(new TargetInformationReply(0, 0, TargetInformationParser.parse("<foo><size>32</size><registers></registers><options></options></foo>".getBytes())));
    mockDebugger.connection.m_synchronizer.receivedEvent(new TargetInformationReply(0, 1, null));
    mockDebugger.getProcessManager().addThread(new TargetProcessThread(0, ThreadState.RUNNING));
    mockDebugger.connection.m_synchronizer.receivedEvent(new ThreadClosedReply(0, 0, 0));
    mockDebugger.connection.m_synchronizer.receivedEvent(new ThreadClosedReply(0, 1, 0));
    mockDebugger.connection.m_synchronizer.receivedEvent(new ThreadCreatedReply(0, 0, 0, ThreadState.RUNNING));
    mockDebugger.connection.m_synchronizer.receivedEvent(new ThreadCreatedReply(0, 1, 0, null));
    mockDebugger.connection.m_synchronizer.receivedEvent(new ValidateMemoryReply(0, 0, new CAddress(0), new CAddress(0)));
    mockDebugger.connection.m_synchronizer.receivedEvent(new ValidateMemoryReply(0, 1, null, null));
    mockDebugger.connection.m_synchronizer.receivedEvent(new WriteMemoryReply(0, 0));
    mockDebugger.connection.m_synchronizer.receivedEvent(new WriteMemoryReply(0, 1));
    mockDebugger.connection.m_synchronizer.receivedEvent(new TerminateReply(0, 0));
    mockDebugger.connection.m_synchronizer.receivedEvent(new TerminateReply(0, 1));
}
Also used : SingleStepReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.SingleStepReply) SetRegisterReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.SetRegisterReply) ThreadClosedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.ThreadClosedReply) ValidateMemoryReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.ValidateMemoryReply) StepBreakpointSetReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.StepBreakpointSetReply) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) SearchReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.SearchReply) TerminateReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.TerminateReply) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) StepBreakpointHitReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.StepBreakpointHitReply) SelectFileReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.SelectFileReply) SuspendThreadReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.SuspendThreadReply) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) RegisterValues(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValues) BigInteger(java.math.BigInteger) RegisterValue(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValue) StepBreakpointsRemovedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.StepBreakpointsRemovedReply) ResumeThreadReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.ResumeThreadReply) WriteMemoryReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.WriteMemoryReply) TargetInformationReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.TargetInformationReply) ThreadRegisters(com.google.security.zynamics.binnavi.debug.models.targetinformation.ThreadRegisters) ThreadCreatedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.ThreadCreatedReply) 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