// File: /workspace/github_c_makefile_star2_O0/Astor-Bizard[P]ProjetS5_Groupe2/src/lectureSH.c
// Function: displaySectionsHeaders
void displaySectionsHeaders(Elf32_Ehdr elfHeader, SectionsHeadersList shList) {
	int i;
	char* sectionName;
	char* flags;

	printf("There are %d section headers, starting at offset 0x%x:\n\n", shList.size, elfHeader.e_shoff);
	printf("Section Headers:\n");
	printf("  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al\n");
	
	for(i=0; i<shList.size; i++) {
		sectionName = getSectionName(shList.names, shList.headers[i].sh_name);
		if(strlen(sectionName)>17)
			sectionName[17] = '\0';
		flags = sectionFlagsTranslation(shList.headers[i].sh_flags);

		printf("  [%2d] %-17s %-15s %08x %06x %06x %02x %3s %2d %3d %2d\n", i, sectionName, typeNameFromValue(shList.headers[i].sh_type), shList.headers[i].sh_addr, shList.headers[i].sh_offset, shList.headers[i].sh_size, shList.headers[i].sh_entsize, flags, shList.headers[i].sh_link, shList.headers[i].sh_info, shList.headers[i].sh_addralign);
		
		free(flags);
		free(sectionName);
	}
	printf("Key to Flags:\n");
	printf("  W (write), A (alloc), X (execute), M (merge), S (strings)\n");
	printf("  I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)\n");
	printf("  O (extra OS processing required) o (OS specific), p (processor specific)\n");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x68, %rsp
leaq 0x48(%rbp), %rcx
movq %rcx, -0x38(%rbp)
leaq 0x10(%rbp), %rax
movl 0x10(%rcx), %esi
movl 0x20(%rax), %edx
leaq 0x32dd(%rip), %rdi      # 0x5a43
movb $0x0, %al
callq 0x1070
leaq 0x3308(%rip), %rdi      # 0x5a7c
movb $0x0, %al
callq 0x1070
leaq 0x330c(%rip), %rdi      # 0x5a8e
movb $0x0, %al
callq 0x1070
movl $0x0, -0x1c(%rbp)
movq -0x38(%rbp), %rcx
movl -0x1c(%rbp), %eax
cmpl 0x10(%rcx), %eax
jge 0x28fa
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
movq (%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %esi
callq 0x2420
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x1060
cmpq $0x11, %rax
jbe 0x27d8
movq -0x28(%rbp), %rax
movb $0x0, 0x11(%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %edi
callq 0x2520
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, -0x30(%rbp)
movl -0x1c(%rbp), %ecx
movl %ecx, -0x44(%rbp)
movq -0x28(%rbp), %rcx
movq %rcx, -0x40(%rbp)
movq (%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %edi
callq 0x20b0
movl -0x44(%rbp), %esi
movq -0x40(%rbp), %rdx
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq (%rax), %rdi
movslq -0x1c(%rbp), %r8
imulq $0x28, %r8, %r8
addq %r8, %rdi
movl 0xc(%rdi), %r8d
movq (%rax), %rdi
movslq -0x1c(%rbp), %r9
imulq $0x28, %r9, %r9
addq %r9, %rdi
movl 0x10(%rdi), %r9d
movq (%rax), %rdi
movslq -0x1c(%rbp), %r10
imulq $0x28, %r10, %r10
addq %r10, %rdi
movl 0x14(%rdi), %r15d
movq (%rax), %rdi
movslq -0x1c(%rbp), %r10
imulq $0x28, %r10, %r10
addq %r10, %rdi
movl 0x24(%rdi), %r14d
movq -0x30(%rbp), %rbx
movq (%rax), %rdi
movslq -0x1c(%rbp), %r10
imulq $0x28, %r10, %r10
addq %r10, %rdi
movl 0x18(%rdi), %r11d
movq (%rax), %rdi
movslq -0x1c(%rbp), %r10
imulq $0x28, %r10, %r10
addq %r10, %rdi
movl 0x1c(%rdi), %r10d
movq (%rax), %rax
movslq -0x1c(%rbp), %rdi
imulq $0x28, %rdi, %rdi
addq %rdi, %rax
movl 0x20(%rax), %eax
leaq 0x3229(%rip), %rdi      # 0x5ae0
movl %r15d, (%rsp)
movl %r14d, 0x8(%rsp)
movq %rbx, 0x10(%rsp)
movl %r11d, 0x18(%rsp)
movl %r10d, 0x20(%rsp)
movl %eax, 0x28(%rsp)
movb $0x0, %al
callq 0x1070
movq -0x30(%rbp), %rdi
callq 0x1030
movq -0x28(%rbp), %rdi
callq 0x1030
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x2790
leaq 0x3218(%rip), %rdi      # 0x5b19
movb $0x0, %al
callq 0x1070
leaq 0x3219(%rip), %rdi      # 0x5b28
movb $0x0, %al
callq 0x1070
leaq 0x3248(%rip), %rdi      # 0x5b65
movb $0x0, %al
callq 0x1070
leaq 0x3284(%rip), %rdi      # 0x5baf
movb $0x0, %al
callq 0x1070
addq $0x68, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)