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);
}
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;
}
}
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());
}
}
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);
}
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);
}
}
Aggregations