Search in sources :

Example 16 with ProcessManager

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

the class ReplySynchronizer method setRegisterValues.

/**
   * Updates the thread the register data belongs to with the new values.
   *
   * @param registerValues The new register values.
   */
protected void setRegisterValues(final RegisterValues registerValues) {
    Preconditions.checkNotNull(registerValues, "IE01046: Register values argument can not be null");
    final ProcessManager processManager = debugger.getProcessManager();
    for (final ThreadRegisters threadRegister : registerValues) {
        for (final TargetProcessThread thread : processManager.getThreads()) {
            if (thread.getThreadId() == threadRegister.getTid()) {
                // Update the thread with the new register values.
                thread.setRegisterValues(threadRegister.getRegisters());
                for (final RegisterValue registerValue : threadRegister.getRegisters()) {
                    if (registerValue.isPc()) {
                        thread.setCurrentAddress(new RelocatedAddress(new CAddress(registerValue.getValue())));
                    }
                }
            }
        }
    }
}
Also used : RegisterValue(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValue) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) ThreadRegisters(com.google.security.zynamics.binnavi.debug.models.targetinformation.ThreadRegisters) ProcessManager(com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessManager) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 17 with ProcessManager

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

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

the class ThreadClosedSynchronizer method handleSuccess.

@Override
protected void handleSuccess(final ThreadClosedReply reply) {
    final ProcessManager processManager = getDebugger().getProcessManager();
    final long tid = reply.getThreadId();
    try {
        processManager.removeThread(processManager.getThread(tid));
    } catch (final MaybeNullException e) {
        CUtilityFunctions.logException(e);
    }
}
Also used : MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) ProcessManager(com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessManager)

Example 19 with ProcessManager

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

the class ProcessTest method testLifeCycle.

@Test
public void testLifeCycle() {
    final MockProcessListener listener = new MockProcessListener();
    final ProcessManager manager = new ProcessManager();
    final Process process = new Process(manager);
    process.addListener(listener);
    manager.setAttached(true);
    assertEquals("attached;", listener.events);
    process.removeListener(listener);
    manager.setTargetInformation(new com.google.security.zynamics.binnavi.debug.models.targetinformation.TargetInformation(5, new FilledList<RegisterDescription>(), new DebuggerOptions(false, false, false, false, false, false, false, false, false, false, 12, 0, new ArrayList<DebuggerException>(), false, false, false)));
    manager.addThread(new TargetProcessThread(0, ThreadState.RUNNING));
    manager.addModule(new MemoryModule("Hannes", "C:\\Hannes.dll", new RelocatedAddress(new CAddress(0x100)), 0x100));
    manager.setMemoryMap(new com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryMap(Lists.newArrayList(new com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection(new CAddress(0), new CAddress(0x100)))));
    manager.getMemory().store(0, new byte[] { 0, 1, 2, 3 });
    process.addListener(listener);
    manager.setTargetInformation(new com.google.security.zynamics.binnavi.debug.models.targetinformation.TargetInformation(5, new FilledList<RegisterDescription>(), new DebuggerOptions(false, false, false, false, false, false, false, false, false, false, 12, 0, new ArrayList<DebuggerException>(), false, false, false)));
    assertEquals(0, process.getThreads().size());
    assertEquals(0, process.getModules().size());
    assertEquals(0, process.getMemoryMap().getSections().size());
    assertEquals(false, process.getMemory().hasData(0, 4));
    manager.setAttached(false);
    assertEquals("attached;changedTargetInformation;detached;", listener.events);
    assertEquals(0, process.getThreads().size());
    assertEquals(0, process.getModules().size());
    assertEquals(null, process.getTargetInformation());
    assertEquals(0, process.getMemoryMap().getSections().size());
    assertEquals(false, process.getMemory().hasData(0, 4));
    process.removeListener(listener);
}
Also used : TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) FilledList(com.google.security.zynamics.zylib.types.lists.FilledList) DebuggerException(com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerException) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) DebuggerOptions(com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerOptions) MemoryModule(com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) ProcessManager(com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessManager) Test(org.junit.Test)

Example 20 with ProcessManager

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

the class ProcessTest method testGetMemoryMap.

@Test
public void testGetMemoryMap() {
    final MockProcessListener listener = new MockProcessListener();
    final ProcessManager manager = new ProcessManager();
    final Process process = new Process(manager);
    process.addListener(listener);
    assertEquals(0, process.getMemoryMap().getSections().size());
    manager.setMemoryMap(new com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryMap(Lists.newArrayList(new com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection(new CAddress(0), new CAddress(0x100)))));
    assertEquals("changedMemoryMap;", listener.events);
    assertEquals(1, process.getMemoryMap().getSections().size());
    final MemoryMap m1 = process.getMemoryMap();
    final MemoryMap m2 = process.getMemoryMap();
    assertEquals(m1, m2);
    process.removeListener(listener);
}
Also used : ProcessManager(com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessManager) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Aggregations

ProcessManager (com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessManager)21 TargetProcessThread (com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread)12 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)7 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)6 Test (org.junit.Test)6 RelocatedAddress (com.google.security.zynamics.binnavi.disassembly.RelocatedAddress)5 MemoryModule (com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule)4 BreakpointManager (com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointManager)3 DebuggerException (com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerException)3 RegisterValue (com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValue)3 ThreadRegisters (com.google.security.zynamics.binnavi.debug.models.targetinformation.ThreadRegisters)3 FilledList (com.google.security.zynamics.zylib.types.lists.FilledList)3 DebugExceptionWrapper (com.google.security.zynamics.binnavi.debug.debugger.DebugExceptionWrapper)2 IDebugger (com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger)2 MemoryMap (com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryMap)2 DebuggerOptions (com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerOptions)2 RegisterValues (com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValues)2 ArrayList (java.util.ArrayList)2 Breakpoint (com.google.security.zynamics.binnavi.debug.models.breakpoints.Breakpoint)1 MemorySection (com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection)1