use of com.google.security.zynamics.binnavi.debug.connection.packets.replies.DebuggerReply 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();
}
}
}
Aggregations