Search in sources :

Example 1 with DebuggerClosedUnexpectedlyReply

use of com.google.security.zynamics.binnavi.debug.connection.packets.replies.DebuggerClosedUnexpectedlyReply in project binnavi by google.

the class CHistoryStringBuilderTest method testComplete2.

@SuppressWarnings("unchecked")
@Test
public void testComplete2() throws DebugExceptionWrapper {
    final CHistoryStringBuilder builder = new CHistoryStringBuilder();
    builder.setDebugger(m_debugger);
    m_debugger.connect();
    m_synchronizer.receivedEvent(DebuggerMessageBuilder.buildProcessStartReply(mockMemoryModule));
    m_debugger.getProcessManager().addThread(new TargetProcessThread(1, ThreadState.RUNNING));
    m_synchronizer.receivedEvent(new BreakpointConditionSetReply(0, 0));
    m_synchronizer.receivedEvent(new BreakpointConditionSetReply(0, 1));
    try {
        m_synchronizer.receivedEvent(new BreakpointHitReply(0, 0, 1, new RegisterValues(Lists.<ThreadRegisters>newArrayList(new ThreadRegisters(1, Lists.newArrayList(new RegisterValue("eip", BigInteger.ONE, new byte[0], false, false)))))));
        fail();
    } catch (final IllegalStateException e) {
    }
    m_synchronizer.receivedEvent(new BreakpointHitReply(0, 0, 1, new RegisterValues(Lists.<ThreadRegisters>newArrayList(new ThreadRegisters(1, Lists.newArrayList(new RegisterValue("eip", BigInteger.ONE, new byte[0], true, false)))))));
    m_breakpointManager.addBreakpoints(BreakpointType.REGULAR, BREAKPOINT_ADDRESS);
    m_synchronizer.receivedEvent(new BreakpointSetReply(0, 0, Lists.newArrayList(new Pair<RelocatedAddress, Integer>(BREAKPOINT_ADDRESS_RELOC, 0))));
    m_synchronizer.receivedEvent(new BreakpointSetReply(0, 0, Lists.newArrayList(new Pair<RelocatedAddress, Integer>(BREAKPOINT_ADDRESS_RELOC, 1))));
    m_synchronizer.receivedEvent(new BreakpointsRemovedReply(0, 0, Lists.newArrayList(new Pair<RelocatedAddress, Integer>(BREAKPOINT_ADDRESS_RELOC, 0))));
    m_synchronizer.receivedEvent(new BreakpointsRemovedReply(0, 0, Lists.newArrayList(new Pair<RelocatedAddress, Integer>(BREAKPOINT_ADDRESS_RELOC, 1))));
    m_breakpointManager.removeBreakpoints(BreakpointType.REGULAR, BREAKPOINT_ADDRESS);
    m_synchronizer.receivedEvent(new DebuggerClosedUnexpectedlyReply());
    m_synchronizer.receivedEvent(new DetachReply(0, 0));
    m_synchronizer.receivedEvent(new DetachReply(0, 1));
}
Also used : StepBreakpointSetReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.StepBreakpointSetReply) BreakpointSetReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.BreakpointSetReply) EchoBreakpointSetReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.EchoBreakpointSetReply) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) BreakpointConditionSetReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.BreakpointConditionSetReply) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) StepBreakpointHitReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.StepBreakpointHitReply) EchoBreakpointHitReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.EchoBreakpointHitReply) BreakpointHitReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.BreakpointHitReply) RegisterValues(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValues) BigInteger(java.math.BigInteger) RegisterValue(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValue) DetachReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.DetachReply) EchoBreakpointsRemovedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.EchoBreakpointsRemovedReply) BreakpointsRemovedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.BreakpointsRemovedReply) StepBreakpointsRemovedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.StepBreakpointsRemovedReply) ThreadRegisters(com.google.security.zynamics.binnavi.debug.models.targetinformation.ThreadRegisters) DebuggerClosedUnexpectedlyReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.DebuggerClosedUnexpectedlyReply) Test(org.junit.Test)

Example 2 with DebuggerClosedUnexpectedlyReply

use of com.google.security.zynamics.binnavi.debug.connection.packets.replies.DebuggerClosedUnexpectedlyReply in project binnavi by google.

the class CDebuggerSynchronizerTest method testErrorConnectionClosed.

@Test
public void testErrorConnectionClosed() throws DebugExceptionWrapper {
    mockDebugger.connect();
    debuggerSynchronizer.receivedEvent(new DebuggerClosedUnexpectedlyReply());
    assertFalse(mockDebugger.isConnected());
    assertEquals("DEBUGGER_CLOSED/0;", listener.events);
}
Also used : DebuggerClosedUnexpectedlyReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.DebuggerClosedUnexpectedlyReply) Test(org.junit.Test)

Example 3 with DebuggerClosedUnexpectedlyReply

use of com.google.security.zynamics.binnavi.debug.connection.packets.replies.DebuggerClosedUnexpectedlyReply in project binnavi by google.

the class DebuggerTest method testListeners2.

@SuppressWarnings("unchecked")
@Test
public void testListeners2() throws DebugExceptionWrapper {
    final DebuggerListener listener = new DebuggerListener();
    debugger.addListener(listener);
    mockDebugger.connect();
    mockDebugger.getProcessManager().addThread(new TargetProcessThread(1, ThreadState.RUNNING));
    mockDebugger.connection.m_synchronizer.receivedEvent(new BreakpointConditionSetReply(0, 0));
    mockDebugger.connection.m_synchronizer.receivedEvent(new BreakpointConditionSetReply(0, 1));
    mockDebugger.connection.m_synchronizer.receivedEvent(new BreakpointHitReply(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.REGULAR, CommonTestObjects.BP_ADDRESS_123_SET);
    mockDebugger.connection.m_synchronizer.receivedEvent(new BreakpointSetReply(0, 0, Lists.newArrayList(new Pair<RelocatedAddress, Integer>(CommonTestObjects.BP_ADDRESS_123_RELOC, 0))));
    mockDebugger.connection.m_synchronizer.receivedEvent(new BreakpointSetReply(0, 0, Lists.newArrayList(new Pair<RelocatedAddress, Integer>(CommonTestObjects.BP_ADDRESS_123_RELOC, 1))));
    mockDebugger.connection.m_synchronizer.receivedEvent(new BreakpointsRemovedReply(0, 0, Lists.newArrayList(new Pair<RelocatedAddress, Integer>(CommonTestObjects.BP_ADDRESS_123_RELOC, 0))));
    mockDebugger.connection.m_synchronizer.receivedEvent(new BreakpointsRemovedReply(0, 0, Lists.newArrayList(new Pair<RelocatedAddress, Integer>(CommonTestObjects.BP_ADDRESS_123_RELOC, 1))));
    mockDebugger.getBreakpointManager().removeBreakpoints(BreakpointType.REGULAR, CommonTestObjects.BP_ADDRESS_123_SET);
    mockDebugger.connection.m_synchronizer.receivedEvent(new DebuggerClosedUnexpectedlyReply());
    mockDebugger.connection.m_synchronizer.receivedEvent(new DetachReply(0, 0));
    mockDebugger.connection.m_synchronizer.receivedEvent(new DetachReply(0, 1));
    mockDebugger.connection.m_synchronizer.receivedEvent(new EchoBreakpointHitReply(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 EchoBreakpointHitReply(0, 0, 1, new RegisterValues(Lists.<ThreadRegisters>newArrayList(new ThreadRegisters(1, Lists.newArrayList(new RegisterValue("eip", BigInteger.ONE, new byte[0], true, false)))))));
    debugger.removeListener(listener);
}
Also used : StepBreakpointSetReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.StepBreakpointSetReply) BreakpointSetReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.BreakpointSetReply) EchoBreakpointSetReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.EchoBreakpointSetReply) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) BreakpointConditionSetReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.BreakpointConditionSetReply) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) StepBreakpointHitReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.StepBreakpointHitReply) EchoBreakpointHitReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.EchoBreakpointHitReply) BreakpointHitReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.BreakpointHitReply) RegisterValues(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValues) BigInteger(java.math.BigInteger) RegisterValue(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValue) DetachReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.DetachReply) EchoBreakpointsRemovedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.EchoBreakpointsRemovedReply) BreakpointsRemovedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.BreakpointsRemovedReply) StepBreakpointsRemovedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.StepBreakpointsRemovedReply) EchoBreakpointHitReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.EchoBreakpointHitReply) ThreadRegisters(com.google.security.zynamics.binnavi.debug.models.targetinformation.ThreadRegisters) DebuggerClosedUnexpectedlyReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.DebuggerClosedUnexpectedlyReply) Test(org.junit.Test)

Example 4 with DebuggerClosedUnexpectedlyReply

use of com.google.security.zynamics.binnavi.debug.connection.packets.replies.DebuggerClosedUnexpectedlyReply in project binnavi by google.

the class ReceiveWorker method run.

/**
 * Starts the worker thread.
 */
@Override
public void run() {
    try {
        while (!shutDown) {
            int messageType = 0;
            int messageId = 0;
            try {
                // Read the type and the ID of the next message
                messageType = (int) DebugProtocolHelper.readDWord(workerInputStream);
                if (waitingForAuthentication) {
                    // The first message expected from the debug client is a simple 'NAVI'.
                    waitingForAuthentication = false;
                    if (// == NAVI ;)
                    messageType == 0x4E415649) {
                        continue;
                    } else {
                        eventQueue.put(new AuthenticationFailedReply());
                        break;
                    }
                }
                messageId = (int) DebugProtocolHelper.readDWord(workerInputStream);
                if (messageType != DebugCommandType.RESP_READ_MEMORY_SUCCESS) {
                    NaviLogger.info(String.format("Debug message of type %d %s arrived", messageType, DebugCommandType.getMessageName(messageType)));
                }
            } catch (final IOException ex) {
                if (!peacefulShutdown) {
                    eventQueue.put(new DebuggerClosedUnexpectedlyReply());
                }
                break;
            }
            final AbstractReplyParser<? extends DebuggerReply> parser = parserFactory.getParser(messageType);
            final DebuggerReply message = parser.parse(messageType, messageId);
            eventQueue.add(message);
            if (isPeacefulShutdownEvent(message)) {
                peacefulShutdown = true;
            }
        }
    } catch (final IOException e) {
        NaviLogger.severe("Shutting down receive worker because of an IO exception");
        try {
            eventQueue.put(new DebuggerClosedUnexpectedlyReply());
        } catch (final InterruptedException e1) {
            // restore the interrupted status of the thread.
            // http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html
            java.lang.Thread.currentThread().interrupt();
        }
    } catch (final InterruptedException e) {
        NaviLogger.severe("Shutting down receive worker because of an interrupted exception");
        try {
            eventQueue.put(new DebuggerClosedUnexpectedlyReply());
        } catch (final InterruptedException e1) {
            CUtilityFunctions.logException(e1);
            // restore the interrupted status of the thread.
            // http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html
            java.lang.Thread.currentThread().interrupt();
        }
    }
}
Also used : AuthenticationFailedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.AuthenticationFailedReply) DebuggerReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.DebuggerReply) IOException(java.io.IOException) DebuggerClosedUnexpectedlyReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.DebuggerClosedUnexpectedlyReply)

Aggregations

DebuggerClosedUnexpectedlyReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.DebuggerClosedUnexpectedlyReply)4 Test (org.junit.Test)3 BreakpointConditionSetReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.BreakpointConditionSetReply)2 BreakpointHitReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.BreakpointHitReply)2 BreakpointSetReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.BreakpointSetReply)2 BreakpointsRemovedReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.BreakpointsRemovedReply)2 DetachReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.DetachReply)2 EchoBreakpointHitReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.EchoBreakpointHitReply)2 EchoBreakpointSetReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.EchoBreakpointSetReply)2 EchoBreakpointsRemovedReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.EchoBreakpointsRemovedReply)2 StepBreakpointHitReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.StepBreakpointHitReply)2 StepBreakpointSetReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.StepBreakpointSetReply)2 StepBreakpointsRemovedReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.StepBreakpointsRemovedReply)2 TargetProcessThread (com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread)2 RegisterValue (com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValue)2 RegisterValues (com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValues)2 ThreadRegisters (com.google.security.zynamics.binnavi.debug.models.targetinformation.ThreadRegisters)2 RelocatedAddress (com.google.security.zynamics.binnavi.disassembly.RelocatedAddress)2 BigInteger (java.math.BigInteger)2 AuthenticationFailedReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.AuthenticationFailedReply)1