Search in sources :

Example 41 with TargetProcessThread

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

the class CDebuggerSynchronizerTest method testRegisterValues_Wellformed.

@Test
public void testRegisterValues_Wellformed() throws MessageParserException, MaybeNullException {
    mockDebugger.getProcessManager().addThread(new TargetProcessThread(123, ThreadState.RUNNING));
    debuggerSynchronizer.receivedEvent(new RegistersReply(0, 0, RegisterValuesParser.parse(("<Registers><Thread id=\"123\"><Register name=\"EAX\" " + "value=\"123\" memory=\"\" /><Register name=\"EBX\" value=\"456\" memory=\"\" " + "/><Register name=\"EIP\" value=\"999\" memory=\"\" pc=\"true\" /></Thread>" + "</Registers>").getBytes())));
    assertEquals(0, listener.exception);
    assertEquals(0x456, mockDebugger.getProcessManager().getThread(123).getRegisterValues().get(1).getValue().longValue());
    assertEquals(0x999, mockDebugger.getProcessManager().getThread(123).getCurrentAddress().getAddress().toLong());
}
Also used : TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) RegistersReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.RegistersReply) Test(org.junit.Test)

Example 42 with TargetProcessThread

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

the class CDebuggerSynchronizerTest method testThreadLifecycle.

/**
   * This test is used to test the thread lifecycle of suspending and resuming threads.
   *
   * @throws DebugExceptionWrapper Thrown if something goes wrong.
   */
@Test
public void testThreadLifecycle() throws DebugExceptionWrapper {
    mockDebugger.connect();
    final TargetProcessThread thread = new TargetProcessThread(123, ThreadState.RUNNING);
    mockDebugger.getProcessManager().addThread(thread);
    debuggerSynchronizer.receivedEvent(new SuspendThreadReply(0, 0, 123));
    assertEquals(ThreadState.SUSPENDED, thread.getState());
    debuggerSynchronizer.receivedEvent(new ResumeThreadReply(0, 0, 123));
    assertEquals(ThreadState.RUNNING, thread.getState());
}
Also used : TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) ResumeThreadReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.ResumeThreadReply) SuspendThreadReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.SuspendThreadReply) Test(org.junit.Test)

Example 43 with TargetProcessThread

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

the class CDebuggerSynchronizerTest method testHitEchoBreakpoint_Wellformed.

@Test
public void testHitEchoBreakpoint_Wellformed() throws DebugExceptionWrapper, MessageParserException {
    mockDebugger.connect();
    breakpointManager.addBreakpoints(BreakpointType.ECHO, CommonTestObjects.BP_ADDRESS_456_SET);
    breakpointManager.setBreakpointStatus(CommonTestObjects.BP_ADDRESS_456_SET, BreakpointType.ECHO, BreakpointStatus.BREAKPOINT_ACTIVE);
    mockDebugger.getProcessManager().addThread(new TargetProcessThread(123, ThreadState.SUSPENDED));
    assertEquals(1, breakpointManager.getNumberOfBreakpoints(BreakpointType.ECHO));
    assertEquals(BreakpointStatus.BREAKPOINT_ACTIVE, breakpointManager.getBreakpointStatus(CommonTestObjects.BP_ADDRESS_456, BreakpointType.ECHO));
    debuggerSynchronizer.receivedEvent(DebuggerMessageBuilder.buildEchoBreakpointHit(CommonTestObjects.BP_ADDRESS_456_RELOC));
    assertEquals(0, listener.exception);
    assertEquals(1, breakpointManager.getNumberOfBreakpoints(BreakpointType.ECHO));
    debuggerSynchronizer.receivedEvent(DebuggerMessageBuilder.buildEchoBreakpointRemoveSucc(CommonTestObjects.BP_ADDRESS_456_RELOC));
    assertEquals(0, breakpointManager.getNumberOfBreakpoints(BreakpointType.ECHO));
}
Also used : TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) Test(org.junit.Test)

Example 44 with TargetProcessThread

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

the class ThreadCreatedSynchronizer method handleSuccess.

@Override
protected void handleSuccess(final ThreadCreatedReply reply) {
    final ProcessManager processManager = getDebugger().getProcessManager();
    final TargetProcessThread thread = new TargetProcessThread(reply.getThreadId(), reply.getThreadState());
    processManager.addThread(thread);
}
Also used : TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) ProcessManager(com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessManager)

Example 45 with TargetProcessThread

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

the class MemoryModuleParser method parseThreadId.

/**
   * Parses the thread id from the data contents of the CModuleReply message.
   *
   * @param data The raw data of the CModuleReply message.
   *
   * @return The parsed thread id.
   *
   * @throws MessageParserException Thrown if parsing of the message failed.
   */
public static TargetProcessThread parseThreadId(final byte[] data) throws MessageParserException {
    Preconditions.checkNotNull(data, "IE00057: Data argument can not be null");
    final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    try {
        final DocumentBuilder builder = factory.newDocumentBuilder();
        final Document document = builder.parse(new ByteArrayInputStream(data, 0, data.length));
        final Node node = document.getFirstChild();
        final long threadId = Long.valueOf(getAttribute(node, "threadid"));
        return new TargetProcessThread(threadId, ThreadState.SUSPENDED);
    } catch (final Exception exception) {
        throw new MessageParserException(exception.getLocalizedMessage());
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document)

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