// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
leaq 0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl $0x0, -0x54(%rbp)
movq $0x0, -0x60(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x30e8
leaq -0x50(%rbp), %rsi
leaq 0x2b69(%rip), %rdi      # 0x5c48
movb $0x0, %al
callq 0x1110
jmp 0x313f
movl $0x0, -0x58(%rbp)
xorl %eax, %eax
cmpl $0x29, -0x58(%rbp)
movb %al, -0x69(%rbp)
jge 0x310f
movq -0x20(%rbp), %rax
movslq -0x58(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x69(%rbp)
movb -0x69(%rbp), %al
testb $0x1, %al
jne 0x3118
jmp 0x3136
movq -0x20(%rbp), %rax
movslq -0x58(%rbp), %rcx
movb (%rax,%rcx), %cl
movslq -0x58(%rbp), %rax
movb %cl, -0x50(%rbp,%rax)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x30ef
movslq -0x58(%rbp), %rax
movb $0x0, -0x50(%rbp,%rax)
movq -0x68(%rbp), %rax
leaq -0x50(%rbp), %rdi
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x2eb0
movl %eax, -0x54(%rbp)
cmpl $-0x1, -0x54(%rbp)
jne 0x31d5
leaq -0x50(%rbp), %rdi
callq 0x2ca0
cmpl $0x0, %eax
je 0x31ac
leaq -0x50(%rbp), %rdi
callq 0x1100
movq -0x68(%rbp), %rcx
cmpl 0x10(%rcx), %eax
je 0x31aa
movq 0x4e63(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq -0x50(%rbp), %rdx
leaq 0x2aa8(%rip), %rsi      # 0x5c4b
movb $0x0, %al
callq 0x10a0
jmp 0x31c8
movq 0x4e45(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq -0x50(%rbp), %rdx
leaq 0x2ad2(%rip), %rsi      # 0x5c93
movb $0x0, %al
callq 0x10a0
movq $0x0, -0x8(%rbp)
jmp 0x338d
movq -0x68(%rbp), %rax
movq (%rax), %rax
movslq -0x54(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movl %eax, %edi
shlq $0x0, %rdi
callq 0x10c0
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0x3361
movq -0x68(%rbp), %rax
movq (%rax), %rax
movslq -0x54(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x14(%rax)
jne 0x3252
leaq -0x50(%rbp), %rsi
leaq 0x2ab6(%rip), %rdi      # 0x5cdd
movb $0x0, %al
callq 0x1070
cmpl $0x0, -0x14(%rbp)
jne 0x3245
movq -0x60(%rbp), %rdi
callq 0x1030
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x338d
leaq -0x50(%rbp), %rsi
leaq 0x2aa4(%rip), %rdi      # 0x5d01
movb $0x0, %al
callq 0x1070
movl $0x0, -0x58(%rbp)
movq -0x68(%rbp), %rcx
movl -0x58(%rbp), %eax
cmpl 0x10(%rcx), %eax
jge 0x32c4
movq -0x68(%rbp), %rax
movq (%rax), %rax
movslq -0x58(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x1c(%rax), %eax
cmpl -0x54(%rbp), %eax
jne 0x32b7
movq -0x68(%rbp), %rax
movq (%rax), %rax
movslq -0x58(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpl $0x9, 0x4(%rax)
jne 0x32b7
leaq 0x2a6d(%rip), %rdi      # 0x5d1d
movb $0x0, %al
callq 0x1070
jmp 0x32b9
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x326b
movq -0x68(%rbp), %rax
movq -0x10(%rbp), %rdi
movq (%rax), %rax
movslq -0x54(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x10d0
movl $0x0, -0x58(%rbp)
movq -0x68(%rbp), %rcx
movl -0x58(%rbp), %eax
movq (%rcx), %rcx
movslq -0x54(%rbp), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x14(%rcx), %eax
jae 0x3328
movq -0x10(%rbp), %rdi
callq 0x1080
movb %al, %dl
movq -0x60(%rbp), %rax
movslq -0x58(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x32ed
jmp 0x332a
movq -0x68(%rbp), %rax
movq -0x60(%rbp), %rdi
movq (%rax), %rax
movslq -0x54(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %esi
callq 0x2d00
cmpl $0x0, -0x14(%rbp)
jne 0x335f
movq -0x60(%rbp), %rdi
callq 0x1030
movq $0x0, -0x60(%rbp)
jmp 0x3383
movq 0x4c90(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq 0x2a0a(%rip), %rsi      # 0x5d7c
movb $0x0, %al
callq 0x10a0
movl $0x2a, %edi
callq 0x1120
jmp 0x3385
movq -0x60(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopw (%rax,%rax)