// File: luigix25[P]SSLP/server_files/server.cpp
// Function: cmd_list()
bool cmd_list(){
	vector <string> files;
	files = get_file_list(SERVER_PATH);
	int number;

	number = (int)files.size();

	string concatenated = files[0];

	for(uint16_t i =1;i<number;i++){
		concatenated += " "+files[i];
	}

	const char *str = concatenated.c_str();
	int len = concatenated.size()+1;

	EncryptManager em;
	Chunk c;
	c.setPlainText((char*)str,false);		//i don't need to free memory
	c.size = len;

	EncryptedChunk ec;

	if(!em.EncryptUpdate(ec,c)) return false;
	if(!em.EncryptFinal(ec))	return false;


	//delete[] c.plaintext;

	//cout << "lista che invio da server: \n" << ec.ciphertext<<endl;
	if(!sendDataHMAC(client_socket,ec.getCipherText(),ec.size))
		return false;
	return true;
	

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
leaq -0x20(%rbp), %rdi
callq 0x8620
leaq 0x8cda(%rip), %rsi      # 0xf025
leaq -0x38(%rbp), %rdi
callq 0x94e0
jmp 0x6356
leaq -0x20(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
leaq -0x38(%rbp), %rsi
movq %rsi, -0xf0(%rbp)
callq 0x8640
movq -0xf0(%rbp), %rdi
callq 0x8670
movq -0xe8(%rbp), %rdi
callq 0x86d0
movq -0xe8(%rbp), %rdi
movl %eax, -0x48(%rbp)
xorl %eax, %eax
movl %eax, %esi
callq 0x86f0
movq %rax, %rsi
leaq -0x68(%rbp), %rdi
callq 0x5250
jmp 0x63aa
movw $0x1, -0x6a(%rbp)
movzwl -0x6a(%rbp), %eax
cmpl -0x48(%rbp), %eax
jge 0x644f
movzwl -0x6a(%rbp), %eax
movl %eax, %esi
leaq -0x20(%rbp), %rdi
callq 0x86f0
movq %rax, %rdx
leaq 0x9202(%rip), %rsi      # 0xf5d8
leaq -0x90(%rbp), %rdi
callq 0x8710
jmp 0x63e4
leaq -0x68(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x5710
jmp 0x63f6
leaq -0x90(%rbp), %rdi
callq 0x5330
movw -0x6a(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x6a(%rbp)
jmp 0x63b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x6643
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x663a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x5330
jmp 0x663a
leaq -0x68(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x5240
movq -0xf8(%rbp), %rdi
movq %rax, -0x98(%rbp)
callq 0x53c0
incl %eax
movl %eax, -0x9c(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0xb690
jmp 0x6488
leaq -0xc0(%rbp), %rdi
callq 0xea40
jmp 0x6496
movq -0x98(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
xorl %edx, %edx
callq 0xeb30
jmp 0x64ad
movl -0x9c(%rbp), %eax
movl %eax, -0xb0(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0xebf0
jmp 0x64c7
leaq -0xa8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
leaq -0xc0(%rbp), %rdx
callq 0xb820
movb %al, -0xf9(%rbp)
jmp 0x64e9
movb -0xf9(%rbp), %al
testb $0x1, %al
jne 0x6547
jmp 0x64f5
movb $0x0, -0x1(%rbp)
movl $0x1, -0xdc(%rbp)
jmp 0x65de
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x662e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x6622
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0xec10
jmp 0x6622
leaq -0xa8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0xb8e0
movb %al, -0xfa(%rbp)
jmp 0x6562
movb -0xfa(%rbp), %al
testb $0x1, %al
jne 0x657e
jmp 0x656e
movb $0x0, -0x1(%rbp)
movl $0x1, -0xdc(%rbp)
jmp 0x65de
leaq -0xd8(%rbp), %rdi
callq 0xed00
movq %rax, -0x108(%rbp)
jmp 0x6593
movq -0x108(%rbp), %rsi
movl -0xc8(%rbp), %edx
leaq 0xe0a9(%rip), %rdi      # 0x14650
callq 0x9b10
movb %al, -0x109(%rbp)
jmp 0x65b4
movb -0x109(%rbp), %al
testb $0x1, %al
jne 0x65d0
jmp 0x65c0
movb $0x0, -0x1(%rbp)
movl $0x1, -0xdc(%rbp)
jmp 0x65de
movb $0x1, -0x1(%rbp)
movl $0x1, -0xdc(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0xec10
leaq -0xc0(%rbp), %rdi
callq 0xea60
leaq -0xa8(%rbp), %rdi
callq 0xb760
leaq -0x68(%rbp), %rdi
callq 0x5330
leaq -0x20(%rbp), %rdi
callq 0x8670
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
leaq -0xc0(%rbp), %rdi
callq 0xea60
leaq -0xa8(%rbp), %rdi
callq 0xb760
leaq -0x68(%rbp), %rdi
callq 0x5330
leaq -0x20(%rbp), %rdi
callq 0x8670
movq -0x40(%rbp), %rdi
callq 0x5980
nopw %cs:(%rax,%rax)