// File: /workspace/github_c_makefile_star2_O3/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 $0x78, %rsp
movl %esi, %ebx
movq %rdi, %r15
leaq 0xb0(%rsp), %r12
testq %rdx, %rdx
je 0x256d
xorl %eax, %eax
movb (%rdx,%rax), %cl
testb %cl, %cl
je 0x2564
movb %cl, 0x40(%rsp,%rax)
incq %rax
cmpq $0x29, %rax
jne 0x254b
movl $0x29, %eax
movl %eax, %eax
movb $0x0, 0x40(%rsp,%rax)
jmp 0x2580
leaq 0x261f(%rip), %rdi      # 0x4b93
leaq 0x40(%rsp), %rsi
xorl %eax, %eax
callq 0x1120
movq 0x10(%r12), %rax
movq %rax, 0x10(%rsp)
movups (%r12), %xmm0
movups %xmm0, (%rsp)
leaq 0x40(%rsp), %r14
movq %r14, %rdi
callq 0x23b4
cmpl $-0x1, %eax
je 0x269c
movl %eax, %ebp
movq %r15, 0x38(%rsp)
movq %r12, %r14
movq (%r12), %r13
cltq
leaq (%rax,%rax,4), %rax
movq %rax, 0x28(%rsp)
movl 0x14(%r13,%rax,8), %r12d
movq %r12, %rdi
callq 0x10d0
testq %rax, %rax
je 0x2728
movq %rax, %r15
testl %r12d, %r12d
je 0x26d2
movq %r15, 0x30(%rsp)
movl %ebx, 0x24(%rsp)
movq 0x28(%rsp), %rax
leaq 0x14(,%rax,8), %rbx
addq %r13, %rbx
leaq 0x2648(%rip), %rdi      # 0x4c4c
xorl %r12d, %r12d
leaq 0x40(%rsp), %rsi
xorl %eax, %eax
callq 0x1090
movslq 0x10(%r14), %rax
testq %rax, %rax
jle 0x264b
shlq $0x3, %rax
leaq (%rax,%rax,4), %r15
xorl %r14d, %r14d
cmpl %ebp, 0x1c(%r13,%r14)
jne 0x2642
cmpl $0x9, 0x4(%r13,%r14)
jne 0x2642
leaq 0x2642(%rip), %rdi      # 0x4c7f
callq 0x1060
addq $0x28, %r14
cmpq %r14, %r15
jne 0x2627
movq 0x28(%rsp), %rax
movl 0x10(%r13,%rax,8), %esi
movq 0x38(%rsp), %r13
movq %r13, %rdi
xorl %edx, %edx
callq 0x10e0
cmpl $0x0, (%rbx)
movq 0x30(%rsp), %r15
je 0x2688
xorl %r14d, %r14d
movq %r13, %rdi
callq 0x10a0
movb %al, (%r15,%r14)
incq %r14
movl (%rbx), %r12d
cmpq %r12, %r14
jb 0x2671
movq %r15, %rdi
movl %r12d, %esi
callq 0x22ae
cmpl $0x0, 0x24(%rsp)
jne 0x26f4
jmp 0x26e9
movb (%r14), %al
leal -0x3a(%rax), %ecx
incq %r14
cmpb $-0xb, %cl
ja 0x269c
testb %al, %al
jne 0x2706
leaq 0x40(%rsp), %rdi
callq 0x1110
cmpl 0x10(%r12), %eax
je 0x26f1
movq 0x4932(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x24c6(%rip), %rsi      # 0x4b96
jmp 0x2717
leaq 0x254f(%rip), %rdi      # 0x4c28
leaq 0x40(%rsp), %rsi
xorl %eax, %eax
callq 0x1090
testl %ebx, %ebx
jne 0x26f4
movq %r15, %rdi
callq 0x1030
xorl %r15d, %r15d
movq %r15, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x48eb(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x24c7(%rip), %rsi      # 0x4bde
xorl %r15d, %r15d
leaq 0x40(%rsp), %rdx
xorl %eax, %eax
callq 0x10c0
jmp 0x26f4
callq 0x1160