// File: /workspace/github_c_makefile_star2_O2/Astor-Bizard[P]ProjetS5_Groupe2/src/afficher_section.c
// Function: afficher_section
unsigned char *afficher_section(FILE *f, SectionsHeadersList shList, int renvoi, char* strOverride) {
	char str[42];
	int num_sh=0,i;
	unsigned char *section;
	section=NULL;

	// Si on a une entrée, on l'utilise au lieu de demander au clavier
	if(strOverride==NULL)
	{
		scanf("%s",str);
	}
	else
	{
		i = 0;
		while (i<41 && strOverride[i]!='\0')
		{
			str[i] = strOverride[i];
			i++;
		}
		str[i] = '\0';
	}

	// On traduit la demande (string) en index dans la table
	num_sh=index_Shdr(str,shList);
	if(num_sh==-1){
		if(is_number(str)){
			if(atoi(str)!=shList.size) fprintf(stderr,"readelf: Warning: Section %s was not dumped because it does not exist!\n",str);
		}
		else fprintf(stderr,"readelf: Warning: Section '%s' was not dumped because it does not exist!\n",str);
		return NULL;
	}
	else{
		section=malloc(sizeof(unsigned char)*shList.headers[num_sh].sh_size);
		if(section != NULL){
			// On affiche le contenu de la section
			if(shList.headers[num_sh].sh_size==0){
				printf("\nSection '%s' has no data to dump.\n",str);
				if(!renvoi){
					free(section);
					section=NULL;
				}
				return section;
			}
			else{
				// Initialisation de l'affichage, récupération du nom de la section
				printf("\nHex dump of section '%s':\n",str);
				for(i=0; i<shList.size; i++){
					if(shList.headers[i].sh_info==num_sh && shList.headers[i].sh_type==SHT_REL)
						printf(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n");
				}

				// On se place
				fseek(f,shList.headers[num_sh].sh_offset,0);

				// On affiche le contenu de la section
				for(i=0;i<shList.headers[num_sh].sh_size;i++){
					section[i]=fgetc(f);
				}
			}
			afficher_string(section,shList.headers[num_sh].sh_size);
			if(!renvoi){
				free(section);
				section=NULL;
			}
		}
		else{
			fprintf(stderr,"Erreur d'allocation !\n");
			exit(42);
		}
	}
	return section;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %esi, %ebx
movq %rdi, %r14
leaq 0xa0(%rsp), %r15
testq %rdx, %rdx
je 0x2457
xorl %eax, %eax
cmpq $0x29, %rax
je 0x2450
movb (%rdx,%rax), %cl
testb %cl, %cl
je 0x2450
movb %cl, 0x30(%rsp,%rax)
incq %rax
jmp 0x243a
movb $0x0, 0x30(%rsp,%rax)
jmp 0x246a
leaq 0x2721(%rip), %rdi      # 0x4b7f
leaq 0x30(%rsp), %rsi
xorl %eax, %eax
callq 0x1120
movq 0x10(%r15), %rax
movq %rax, 0x10(%rsp)
movups (%r15), %xmm0
movups %xmm0, (%rsp)
leaq 0x30(%rsp), %rdi
callq 0x22bf
cmpl $-0x1, %eax
je 0x2565
movl %eax, %ebp
movq %r14, 0x28(%rsp)
movq (%r15), %r13
cltq
imulq $0x28, %rax, %rax
movq %rax, 0x20(%rsp)
movl 0x14(%r13,%rax), %r12d
movq %r12, %rdi
callq 0x10d0
testq %rax, %rax
je 0x25ec
movq %rax, %r14
testl %r12d, %r12d
je 0x2596
movl %ebx, 0x1c(%rsp)
movq 0x20(%rsp), %rax
leaq (%rax,%r13), %rbx
addq $0x14, %rbx
leaq 0x275b(%rip), %rdi      # 0x4c38
xorl %r12d, %r12d
leaq 0x30(%rsp), %rsi
xorl %eax, %eax
callq 0x1090
movl 0x10(%r15), %eax
testl %eax, %eax
cmovlel %r12d, %eax
imulq $0x28, %rax, %r15
cmpq %r12, %r15
je 0x2520
cmpl %ebp, 0x1c(%r13,%r12)
jne 0x251a
cmpl $0x9, 0x4(%r13,%r12)
jne 0x251a
leaq 0x2756(%rip), %rdi      # 0x4c6b
callq 0x1060
addq $0x28, %r12
jmp 0x24fa
movq 0x20(%rsp), %rax
movl 0x10(%r13,%rax), %esi
xorl %r15d, %r15d
movq 0x28(%rsp), %r12
movq %r12, %rdi
xorl %edx, %edx
callq 0x10e0
movl (%rbx), %esi
cmpq %rsi, %r15
jae 0x2554
movq %r12, %rdi
callq 0x10a0
movb %al, (%r14,%r15)
incq %r15
jmp 0x253c
movq %r14, %rdi
callq 0x21aa
cmpl $0x0, 0x1c(%rsp)
jne 0x25b8
jmp 0x25ad
leaq 0x30(%rsp), %rdi
callq 0x2196
testl %eax, %eax
je 0x25ca
leaq 0x30(%rsp), %rdi
callq 0x1110
cmpl 0x10(%r15), %eax
je 0x25b5
movq 0x4a6e(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x25ee(%rip), %rsi      # 0x4b82
jmp 0x25db
leaq 0x2677(%rip), %rdi      # 0x4c14
leaq 0x30(%rsp), %rsi
xorl %eax, %eax
callq 0x1090
testl %ebx, %ebx
jne 0x25b8
movq %r14, %rdi
callq 0x1030
xorl %r14d, %r14d
movq %r14, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4a27(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x25ef(%rip), %rsi      # 0x4bca
xorl %r14d, %r14d
leaq 0x30(%rsp), %rdx
xorl %eax, %eax
callq 0x10c0
jmp 0x25b8
movq 0x4a05(%rip), %rax      # 0x6ff8
movq (%rax), %rcx
leaq 0x2657(%rip), %rdi      # 0x4c54
pushq $0x16
popq %rsi
pushq $0x1
popq %rdx
callq 0x1140
pushq $0x2a
popq %rdi
callq 0x1130