Search in sources :

Example 1 with AuthenticationFailedReply

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

the class CDebuggerSynchronizerTest method testAuthenticationFailed.

/**
   * This test makes sure that authentication failure replies are handled correctly.
   *
   *  This message is sent if the client can not authenticate itself as a BinNavi debug client. In
   * that case BinNavi has to close the connection to the debug client and reset the internal state
   * of the process.
   *
   * @throws DebugExceptionWrapper Thrown if something goes wrong.
   */
@Test
public void testAuthenticationFailed() throws DebugExceptionWrapper {
    mockDebugger.connect();
    assertTrue(mockDebugger.isConnected());
    debuggerSynchronizer.receivedEvent(new AuthenticationFailedReply());
    assertFalse(mockDebugger.isConnected());
}
Also used : AuthenticationFailedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.AuthenticationFailedReply) Test(org.junit.Test)

Example 2 with AuthenticationFailedReply

use of com.google.security.zynamics.binnavi.debug.connection.packets.replies.AuthenticationFailedReply 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)

Example 3 with AuthenticationFailedReply

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

the class DebuggerTest method testListeners1.

@Test
public void testListeners1() 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 AttachReply(0, 0));
    mockDebugger.connection.m_synchronizer.receivedEvent(new AttachReply(0, 1));
    mockDebugger.connection.m_synchronizer.receivedEvent(new AuthenticationFailedReply());
}
Also used : TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) AttachReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.AttachReply) AuthenticationFailedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.AuthenticationFailedReply) Test(org.junit.Test)

Example 4 with AuthenticationFailedReply

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

the class CHistoryStringBuilderTest method testComplete.

/**
   * This test tries to achieve complete code coverage to make sure all string formatters are
   * working as expected.
   *
   * @throws DebugExceptionWrapper
   * @throws IOException
   * @throws SAXException
   * @throws ParserConfigurationException
   * @throws MessageParserException
   * @throws MaybeNullException
   */
@Test
public void testComplete() throws DebugExceptionWrapper, ParserConfigurationException, SAXException, IOException, MessageParserException, MaybeNullException {
    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 AttachReply(0, 0));
    m_synchronizer.receivedEvent(new AttachReply(0, 1));
    m_synchronizer.receivedEvent(new AuthenticationFailedReply());
}
Also used : TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) AttachReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.AttachReply) AuthenticationFailedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.AuthenticationFailedReply) Test(org.junit.Test)

Aggregations

AuthenticationFailedReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.AuthenticationFailedReply)4 Test (org.junit.Test)3 AttachReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.AttachReply)2 TargetProcessThread (com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread)2 DebuggerClosedUnexpectedlyReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.DebuggerClosedUnexpectedlyReply)1 DebuggerReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.DebuggerReply)1 IOException (java.io.IOException)1