// File: /workspace/github_c_makefile_star2_O1/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, %r15
leaq 0xa0(%rsp), %r12
testq %rdx, %rdx
je 0x2568
xorl %eax, %eax
movb (%rdx,%rax), %cl
testb %cl, %cl
je 0x255f
movb %cl, 0x30(%rsp,%rax)
incq %rax
cmpq $0x29, %rax
jne 0x2546
movl $0x29, %eax
movl %eax, %eax
movb $0x0, 0x30(%rsp,%rax)
jmp 0x257b
leaq 0x2664(%rip), %rdi      # 0x4bd3
leaq 0x30(%rsp), %rsi
xorl %eax, %eax
callq 0x1120
movq 0x10(%r12), %rax
movq %rax, 0x10(%rsp)
movups (%r12), %xmm0
movups %xmm0, (%rsp)
leaq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0x23af
cmpl $-0x1, %eax
je 0x2687
movl %eax, %ebp
movq %r15, 0x28(%rsp)
movq %r12, %r15
movq (%r12), %r13
cltq
leaq (%rax,%rax,4), %rax
movq %rax, 0x20(%rsp)
movl 0x14(%r13,%rax,8), %r12d
movq %r12, %rdi
callq 0x10d0
testq %rax, %rax
je 0x2713
movq %rax, %r14
testl %r12d, %r12d
je 0x26bd
movl %ebx, 0x1c(%rsp)
movq 0x20(%rsp), %rax
leaq 0x14(,%rax,8), %rbx
addq %r13, %rbx
leaq 0x2692(%rip), %rdi      # 0x4c8c
leaq 0x30(%rsp), %rsi
xorl %eax, %eax
callq 0x1090
movslq 0x10(%r15), %rax
testq %rax, %rax
jle 0x263e
shlq $0x3, %rax
leaq (%rax,%rax,4), %r12
xorl %r15d, %r15d
cmpl %ebp, 0x1c(%r13,%r15)
jne 0x2635
cmpl $0x9, 0x4(%r13,%r15)
jne 0x2635
leaq 0x268f(%rip), %rdi      # 0x4cbf
callq 0x1060
addq $0x28, %r15
cmpq %r15, %r12
jne 0x261a
movq 0x20(%rsp), %rax
movl 0x10(%r13,%rax,8), %esi
movq 0x28(%rsp), %r12
movq %r12, %rdi
xorl %edx, %edx
callq 0x10e0
movl (%rbx), %esi
testl %esi, %esi
je 0x2676
xorl %r15d, %r15d
movq %r12, %rdi
callq 0x10a0
movb %al, (%r14,%r15)
incq %r15
movl (%rbx), %esi
cmpq %rsi, %r15
jb 0x2660
movq %r14, %rdi
callq 0x22b2
cmpl $0x0, 0x1c(%rsp)
jne 0x26df
jmp 0x26d4
movb (%r14), %al
leal -0x3a(%rax), %ecx
incq %r14
cmpb $-0xb, %cl
ja 0x2687
testb %al, %al
jne 0x26f1
leaq 0x30(%rsp), %rdi
callq 0x1110
cmpl 0x10(%r12), %eax
je 0x26dc
movq 0x4947(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x251b(%rip), %rsi      # 0x4bd6
jmp 0x2702
leaq 0x25a4(%rip), %rdi      # 0x4c68
leaq 0x30(%rsp), %rsi
xorl %eax, %eax
callq 0x1090
testl %ebx, %ebx
jne 0x26df
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 0x4900(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x251c(%rip), %rsi      # 0x4c1e
xorl %r14d, %r14d
leaq 0x30(%rsp), %rdx
xorl %eax, %eax
callq 0x10c0
jmp 0x26df
callq 0x1160