// File: Neuromancer2701[P]OpenTool/src/OpenTool.cpp
// Function: OpenTool::MIDOutputAction(Header*)
Error OpenTool::MIDOutputAction(Header* message)
{
	 Error result = Error::UNKNOWN;
	 string data("");

	 switch(message->Number)
	 {
		 case MID_Number::CommunicationStart:
			  try{
				  Mid_0001* mid0001 = dynamic_cast<Mid_0001*>(message);
				  mid0001->Packup();
				  data = mid0001->GetRawOutputString();
			  }
			  catch(exception& my_ex)
			  {
				  Log << "Exception: " << my_ex.what();
			  }
			  break;
		 case MID_Number::CommunicationStartAcknowledge:
			  try{
				  Mid_0002* mid0002 = dynamic_cast<Mid_0002*>(message);
				  mid0002->Packup();
				  data = mid0002->GetRawOutputString();
			  }
			  catch(exception& my_ex)
			  {
				  Log << "Exception: " << my_ex.what();
			  }
			  break;
		 case MID_Number::CommunicationStop:
			  try{
				  Mid_0003* mid0003 = dynamic_cast<Mid_0003*>(message);
				  mid0003->Packup();
				  data = mid0003->GetRawOutputString();
			  }
			  catch(exception& my_ex)
			  {
				  Log << "Exception: " << my_ex.what();
			  }
			  break;
		 case MID_Number::CommandError:
			  try{
				  Mid_0004* mid0004 = dynamic_cast<Mid_0004*>(message);
				  mid0004->Packup();
				  data = mid0004->GetRawOutputString();
			  }
			  catch(exception& my_ex)
			  {
				  Log << "Exception: " << my_ex.what();
			  }
			  break;
		 case MID_Number::CommandAccepted:
			  try{
				  Mid_0005* mid0005 = dynamic_cast<Mid_0005*>(message);
				  mid0005->Packup();
				  data = mid0005->GetRawOutputString();
			  }
			  catch(exception& my_ex)
			  {
				  Log << "Exception: " << my_ex.what();
			  }
			  break;
		 case MID_Number::KeepAliveMessage:
			  try{
				  Mid_9999* mid9999 = dynamic_cast<Mid_9999*>(message);
				  mid9999->Packup();
				  data = mid9999->GetRawOutputString();
			  }
			  catch(exception& my_ex)
			  {
				  Log << "Exception: " << my_ex.what();
			  }
			  break;

		 default:
			  break;
	 }

	 if(data.length() >= Header::HeaderTotalLength )
	 {
		 result = Send(data);
	 }
	 else
	 {
		 Log << "Opps data shorter than default header.";
	 }

	 return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x240, %rsp            # imm = 0x240
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x1a0(%rbp)
movl $0x0, -0x14(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x198(%rbp)
callq 0xaea0
movq -0x198(%rbp), %rdx
leaq 0x78ba(%rip), %rsi      # 0x132ad
leaq -0x38(%rbp), %rdi
callq 0xab20
jmp 0xb9fe
leaq -0x39(%rbp), %rdi
callq 0xa920
movq -0x10(%rbp), %rax
movl 0x31c(%rax), %eax
movl %eax, -0x1a4(%rbp)
subl $0x1, %eax
je 0xba92
jmp 0xba1e
movl -0x1a4(%rbp), %eax
subl $0x2, %eax
je 0xbbb4
jmp 0xba2f
movl -0x1a4(%rbp), %eax
subl $0x3, %eax
je 0xbcdd
jmp 0xba40
movl -0x1a4(%rbp), %eax
subl $0x4, %eax
je 0xbe06
jmp 0xba51
movl -0x1a4(%rbp), %eax
subl $0x5, %eax
je 0xbf2f
jmp 0xba62
movl -0x1a4(%rbp), %eax
subl $0x270f, %eax           # imm = 0x270F
je 0xc058
jmp 0xc17e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x39(%rbp), %rdi
callq 0xa920
jmp 0xc232
movq -0x10(%rbp), %rax
movq %rax, -0x1b0(%rbp)
cmpq $0x0, %rax
je 0xbaca
movq -0x1b0(%rbp), %rdi
movq 0xc537(%rip), %rsi      # 0x17fe8
movq 0xc4f0(%rip), %rdx      # 0x17fa8
xorl %eax, %eax
movl %eax, %ecx
callq 0xa960
movq %rax, -0x1b8(%rbp)
jmp 0xbad5
xorl %eax, %eax
movq %rax, -0x1b8(%rbp)
jmp 0xbad5
movq -0x1b8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
jmp 0xbaef
movq -0x58(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0xadb0
jmp 0xbafe
leaq -0x38(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0xa9c0
leaq -0x78(%rbp), %rdi
callq 0xa540
jmp 0xbb86
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0xc229
movq -0x48(%rbp), %rdi
callq 0xa330
movq %rax, -0x80(%rbp)
movq 0xc3da(%rip), %rdi      # 0x17f20
addq $0x10, %rdi
leaq 0x74b7(%rip), %rsi      # 0x13008
callq 0xa890
movq %rax, -0x1c0(%rbp)
jmp 0xbb5f
movq -0x80(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq -0x1c0(%rbp), %rdi
movq %rax, %rsi
callq 0xa890
jmp 0xbb7d
callq 0xad60
jmp 0xbb84
jmp 0xbb86
jmp 0xc180
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0xad60
jmp 0xbbaf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xc229
jmp 0xc229
movq -0x10(%rbp), %rax
movq %rax, -0x1c8(%rbp)
cmpq $0x0, %rax
je 0xbbec
movq -0x1c8(%rbp), %rdi
movq 0xc415(%rip), %rsi      # 0x17fe8
movq 0xc41e(%rip), %rdx      # 0x17ff8
xorl %eax, %eax
movl %eax, %ecx
callq 0xa960
movq %rax, -0x1d0(%rbp)
jmp 0xbbf7
xorl %eax, %eax
movq %rax, -0x1d0(%rbp)
jmp 0xbbf7
movq -0x1d0(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
jmp 0xbc17
movq -0x88(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
callq 0xadb0
jmp 0xbc2c
leaq -0x38(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0xa9c0
leaq -0xa8(%rbp), %rdi
callq 0xa540
jmp 0xbcc0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0xc229
movq -0x48(%rbp), %rdi
callq 0xa330
movq %rax, -0xb0(%rbp)
movq 0xc2a3(%rip), %rdi      # 0x17f20
addq $0x10, %rdi
leaq 0x7380(%rip), %rsi      # 0x13008
callq 0xa890
movq %rax, -0x1d8(%rbp)
jmp 0xbc96
movq -0xb0(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq -0x1d8(%rbp), %rdi
movq %rax, %rsi
callq 0xa890
jmp 0xbcb7
callq 0xad60
jmp 0xbcbe
jmp 0xbcc0
jmp 0xc180
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0xad60
jmp 0xbcd8
jmp 0xc229
movq -0x10(%rbp), %rax
movq %rax, -0x1e0(%rbp)
cmpq $0x0, %rax
je 0xbd15
movq -0x1e0(%rbp), %rdi
movq 0xc2ec(%rip), %rsi      # 0x17fe8
movq 0xc225(%rip), %rdx      # 0x17f28
xorl %eax, %eax
movl %eax, %ecx
callq 0xa960
movq %rax, -0x1e8(%rbp)
jmp 0xbd20
xorl %eax, %eax
movq %rax, -0x1e8(%rbp)
jmp 0xbd20
movq -0x1e8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
jmp 0xbd40
movq -0xb8(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0xadb0
jmp 0xbd55
leaq -0x38(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0xa9c0
leaq -0xd8(%rbp), %rdi
callq 0xa540
jmp 0xbde9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0xc229
movq -0x48(%rbp), %rdi
callq 0xa330
movq %rax, -0xe0(%rbp)
movq 0xc17a(%rip), %rdi      # 0x17f20
addq $0x10, %rdi
leaq 0x7257(%rip), %rsi      # 0x13008
callq 0xa890
movq %rax, -0x1f0(%rbp)
jmp 0xbdbf
movq -0xe0(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq -0x1f0(%rbp), %rdi
movq %rax, %rsi
callq 0xa890
jmp 0xbde0
callq 0xad60
jmp 0xbde7
jmp 0xbde9
jmp 0xc180
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0xad60
jmp 0xbe01
jmp 0xc229
movq -0x10(%rbp), %rax
movq %rax, -0x1f8(%rbp)
cmpq $0x0, %rax
je 0xbe3e
movq -0x1f8(%rbp), %rdi
movq 0xc1c3(%rip), %rsi      # 0x17fe8
movq 0xc11c(%rip), %rdx      # 0x17f48
xorl %eax, %eax
movl %eax, %ecx
callq 0xa960
movq %rax, -0x200(%rbp)
jmp 0xbe49
xorl %eax, %eax
movq %rax, -0x200(%rbp)
jmp 0xbe49
movq -0x200(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0xe8(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
jmp 0xbe69
movq -0xe8(%rbp), %rsi
leaq -0x108(%rbp), %rdi
callq 0xadb0
jmp 0xbe7e
leaq -0x38(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0xa9c0
leaq -0x108(%rbp), %rdi
callq 0xa540
jmp 0xbf12
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0xc229
movq -0x48(%rbp), %rdi
callq 0xa330
movq %rax, -0x110(%rbp)
movq 0xc051(%rip), %rdi      # 0x17f20
addq $0x10, %rdi
leaq 0x712e(%rip), %rsi      # 0x13008
callq 0xa890
movq %rax, -0x208(%rbp)
jmp 0xbee8
movq -0x110(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq -0x208(%rbp), %rdi
movq %rax, %rsi
callq 0xa890
jmp 0xbf09
callq 0xad60
jmp 0xbf10
jmp 0xbf12
jmp 0xc180
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0xad60
jmp 0xbf2a
jmp 0xc229
movq -0x10(%rbp), %rax
movq %rax, -0x210(%rbp)
cmpq $0x0, %rax
je 0xbf67
movq -0x210(%rbp), %rdi
movq 0xc09a(%rip), %rsi      # 0x17fe8
movq 0xc013(%rip), %rdx      # 0x17f68
xorl %eax, %eax
movl %eax, %ecx
callq 0xa960
movq %rax, -0x218(%rbp)
jmp 0xbf72
xorl %eax, %eax
movq %rax, -0x218(%rbp)
jmp 0xbf72
movq -0x218(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x118(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
jmp 0xbf92
movq -0x118(%rbp), %rsi
leaq -0x138(%rbp), %rdi
callq 0xadb0
jmp 0xbfa7
leaq -0x38(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0xa9c0
leaq -0x138(%rbp), %rdi
callq 0xa540
jmp 0xc03b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0xc229
movq -0x48(%rbp), %rdi
callq 0xa330
movq %rax, -0x140(%rbp)
movq 0xbf28(%rip), %rdi      # 0x17f20
addq $0x10, %rdi
leaq 0x7005(%rip), %rsi      # 0x13008
callq 0xa890
movq %rax, -0x220(%rbp)
jmp 0xc011
movq -0x140(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq -0x220(%rbp), %rdi
movq %rax, %rsi
callq 0xa890
jmp 0xc032
callq 0xad60
jmp 0xc039
jmp 0xc03b
jmp 0xc180
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0xad60
jmp 0xc053
jmp 0xc229
movq -0x10(%rbp), %rax
movq %rax, -0x228(%rbp)
cmpq $0x0, %rax
je 0xc090
movq -0x228(%rbp), %rdi
movq 0xbf71(%rip), %rsi      # 0x17fe8
movq 0xbed2(%rip), %rdx      # 0x17f50
xorl %eax, %eax
movl %eax, %ecx
callq 0xa960
movq %rax, -0x230(%rbp)
jmp 0xc09b
xorl %eax, %eax
movq %rax, -0x230(%rbp)
jmp 0xc09b
movq -0x230(%rbp), %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
jmp 0xc0bb
movq -0x148(%rbp), %rsi
leaq -0x168(%rbp), %rdi
callq 0xadb0
jmp 0xc0d0
leaq -0x38(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0xa9c0
leaq -0x168(%rbp), %rdi
callq 0xa540
jmp 0xc164
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0xc229
movq -0x48(%rbp), %rdi
callq 0xa330
movq %rax, -0x170(%rbp)
movq 0xbdff(%rip), %rdi      # 0x17f20
addq $0x10, %rdi
leaq 0x6edc(%rip), %rsi      # 0x13008
callq 0xa890
movq %rax, -0x238(%rbp)
jmp 0xc13a
movq -0x170(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq -0x238(%rbp), %rdi
movq %rax, %rsi
callq 0xa890
jmp 0xc15b
callq 0xad60
jmp 0xc162
jmp 0xc164
jmp 0xc180
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0xad60
jmp 0xc179
jmp 0xc229
jmp 0xc180
leaq -0x38(%rbp), %rdi
callq 0xac40
cmpq $0x14, %rax
jb 0xc1ed
leaq -0x190(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0xa380
jmp 0xc1a1
movq -0x1a0(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0xa270
movl %eax, -0x23c(%rbp)
jmp 0xc1bc
movl -0x23c(%rbp), %eax
movl %eax, -0x14(%rbp)
leaq -0x190(%rbp), %rdi
callq 0xa540
jmp 0xc208
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x190(%rbp), %rdi
callq 0xa540
jmp 0xc229
movq 0xbd2c(%rip), %rdi      # 0x17f20
addq $0x10, %rdi
leaq 0x6e15(%rip), %rsi      # 0x13014
callq 0xa890
jmp 0xc206
jmp 0xc208
movl -0x14(%rbp), %eax
movl %eax, -0x240(%rbp)
leaq -0x38(%rbp), %rdi
callq 0xa540
movl -0x240(%rbp), %eax
addq $0x240, %rsp            # imm = 0x240
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0xa540
movq -0x48(%rbp), %rdi
callq 0xae90
movq %rax, %rdi
callq 0xd050
nopw %cs:(%rax,%rax)