// File: /workspace/github_c_makefile_star2_O2/Astor-Bizard[P]ProjetS5_Groupe2/src/affichage_relocation.c
// Function: afficher_sectionR
void afficher_sectionR(FILE *f,
                        SectionsHeadersList liste_sections,
                        Elf32_Ehdr header,
                        int numS, 
                        Str_Reloc *RETOUR, 
                        ListeSymboles table_symbol, 
                        int silent)
{
	int i;
	unsigned char *section;
    section = recuperer_section_num(f, liste_sections, numS); // Y'a rien a voir circulez!
	unsigned long long int addr;
	unsigned long long int info;
    unsigned char type;
    unsigned int sym;
    
    char *nom_section = getSectionNameBis(liste_sections.names, liste_sections.headers[numS]);
    if(!silent)
    {
    	printf("\nRelocation section '%s' at offset 0x%x contains %i entries:\n",
                nom_section,
                liste_sections.headers[numS].sh_offset,
    			(int) liste_sections.headers[numS].sh_size/8);
    	printf(" Offset     Info    Type            Sym.Value  Sym. Name\n");
    }
    free(nom_section);

    RETOUR->Rel = realloc(RETOUR->Rel,sizeof(Elf32_Rel)*(RETOUR->nb_Rel+(int) liste_sections.headers[numS].sh_size/8));
    RETOUR->Sec_Rel = realloc(RETOUR->Sec_Rel,sizeof(int)*(RETOUR->nb_Rel+(int) liste_sections.headers[numS].sh_size/8));

	for(i=0; i<(int) liste_sections.headers[numS].sh_size/8; i++)
	{
		addr = lire_octets_charT(section, header.e_ident[EI_DATA], i*8, 4);
		info = lire_octets_charT(section, header.e_ident[EI_DATA], i*8 +4,4);
        type = info;
        sym = info >>8;

        if(!silent)
        {
    		printf("%08llx  %08llx ", addr,info);
            type_relocation(type);
            if(type != 40) print_symbol(sym, table_symbol, header, liste_sections);
            //print_section(addr, liste_sections, header); 
            
            //on affiche les infos.
            sym = sym *2;
            printf("\n");
        }
        RETOUR->nb_Rel ++;

        
        RETOUR->Rel[RETOUR->nb_Rel-1].r_offset = addr;
        RETOUR->Rel[RETOUR->nb_Rel-1].r_info = info;
        RETOUR->Sec_Rel[RETOUR->nb_Rel-1] = numS;
	}
	free(section);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl %ecx, %ebp
movq %rdx, %r14
movl %esi, %ebx
leaq 0x100(%rsp), %r12
movq 0x10(%r12), %rax
movq %rax, 0x10(%rsp)
movaps (%r12), %xmm0
movups %xmm0, (%rsp)
callq 0x2610
movq %rax, 0x78(%rsp)
movq (%r12), %rax
movq 0x8(%r12), %rdi
movl %ebx, 0x70(%rsp)
movslq %ebx, %rcx
imulq $0x28, %rcx, %r13
movq 0x20(%rax,%r13), %rcx
movq %rcx, 0xc0(%rsp)
movups (%rax,%r13), %xmm0
movups 0x10(%rax,%r13), %xmm1
movaps %xmm1, 0xb0(%rsp)
movaps %xmm0, 0xa0(%rsp)
movq 0xc0(%rsp), %rax
movq %rax, 0x20(%rsp)
movaps 0xa0(%rsp), %xmm0
movaps 0xb0(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x1d62
movq %rax, %rbx
pushq $0x8
popq %r15
movl %ebp, 0x74(%rsp)
testl %ebp, %ebp
movq %r13, %rbp
jne 0x2eba
movq (%r12), %rax
movl 0x10(%rax,%rbp), %ecx
movl 0x14(%rax,%rbp), %eax
cltd
idivl %r15d
leaq 0x21e7(%rip), %rdi      # 0x5087
movq %rbx, %rsi
movl %ecx, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0x1090
leaq 0x2220(%rip), %rdi      # 0x50d5
callq 0x1060
movq %rbx, %rdi
callq 0x1030
movq 0x8(%r14), %rdi
movslq (%r14), %rcx
movq (%r12), %rax
movl 0x14(%rax,%rbp), %eax
cltd
idivl %r15d
movslq %eax, %rsi
addq %rcx, %rsi
shlq $0x3, %rsi
callq 0x10f0
movq %rax, 0x8(%r14)
movq 0x10(%r14), %rdi
movslq (%r14), %rcx
movq (%r12), %rax
movl 0x14(%rax,%rbp), %eax
cltd
idivl %r15d
movslq %eax, %rsi
addq %rcx, %rsi
shlq $0x2, %rsi
callq 0x10f0
movq %r14, 0x88(%rsp)
movq %rax, 0x80(%rsp)
movq %rax, 0x10(%r14)
leaq 0x118(%rsp), %rax
movzbl 0x5(%rax), %eax
movl %eax, 0x6c(%rsp)
movq (%r12), %rax
movq %rax, 0x90(%rsp)
pushq $0x4
popq %rax
movl %eax, %ebx
xorl %r14d, %r14d
movq %rbp, 0x98(%rsp)
movq 0x90(%rsp), %rax
movl 0x14(%rax,%rbp), %eax
cltd
pushq $0x8
popq %rcx
idivl %ecx
cmpl %eax, %r14d
jge 0x309b
leal -0x4(%rbx), %edx
movq 0x78(%rsp), %r15
movq %r15, %rdi
movl 0x6c(%rsp), %r13d
movl %r13d, %esi
pushq $0x4
popq %r12
movl %r12d, %ecx
callq 0x2c20
movq %rax, %rbp
movq %r15, %rdi
movl %r13d, %esi
movl %ebx, %edx
movl %r12d, %ecx
callq 0x2c20
movq %rax, %r15
cmpl $0x0, 0x74(%rsp)
jne 0x305c
leaq 0x2119(%rip), %rdi      # 0x50c5
movq %rbp, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x1090
movzbl %r15b, %r13d
movl %r13d, %edi
callq 0x2c6f
cmpl $0x28, %r13d
leaq 0x100(%rsp), %r12
je 0x3034
movq %r15, %rdi
shrq $0x8, %rdi
movq 0x10(%r12), %rax
movq %rax, 0x60(%rsp)
movups (%r12), %xmm0
movups %xmm0, 0x50(%rsp)
leaq 0x118(%rsp), %rcx
movl 0x30(%rcx), %eax
movl %eax, 0x48(%rsp)
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups 0x20(%rcx), %xmm2
movups %xmm2, 0x38(%rsp)
movups %xmm1, 0x28(%rsp)
movups %xmm0, 0x18(%rsp)
leaq 0x150(%rsp), %rcx
movq 0x10(%rcx), %rax
movq %rax, 0x10(%rsp)
movups (%rcx), %xmm0
movups %xmm0, (%rsp)
callq 0x2d04
pushq $0xa
popq %rdi
callq 0x1040
movq (%r12), %rax
movq %rax, 0x90(%rsp)
movq 0x88(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x80(%rsp)
movq 0x88(%rsp), %rdx
movslq (%rdx), %rax
leaq 0x1(%rax), %rcx
movl %ecx, (%rdx)
movq 0x8(%rdx), %rcx
movl %ebp, (%rcx,%rax,8)
movl %r15d, 0x4(%rcx,%rax,8)
movl 0x70(%rsp), %ecx
movq 0x80(%rsp), %rdx
movl %ecx, (%rdx,%rax,4)
incl %r14d
addl $0x8, %ebx
movq 0x98(%rsp), %rbp
jmp 0x2f4a
movq 0x78(%rsp), %rdi
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1030