// File: /workspace/github_c_makefile_star2_O2/Astor-Bizard[P]ProjetS5_Groupe2/src/lecture_headers.c
// Function: afficher_headers
void afficher_headers(Elf32_Ehdr headers)
{
	int i;
	printf("ELF Header:\n  Magic:   ");
	for(i=0;i<EI_NIDENT;i++) printf("%02x ",headers.e_ident[i]);
	printf("\n  Class:                             ELF%d\n",headers.e_ident[EI_CLASS]*32);
	printf("  Data:                              2's complement, ");
	if (headers.e_ident[EI_DATA] == L_ENDIAN) printf("little endian\n");
	else printf("big endian\n");

	printf("  Version:                           %d (current)\n",headers.e_ident[EI_VERSION]);

	printf("  OS/ABI:                            ");
	if(headers.e_machine==40)
		printf("UNIX - System V\n");
	else
		printf("Machine numero : %d (incompatible)\n", headers.e_machine);

	printf("  ABI Version:                       0\n");

	printf("  Type:                              ");
	switch(headers.e_type)
	{
		case ET_NONE:
			printf("NONE (No file type)\n");
			break;
		case ET_REL:
			printf("REL (Relocatable file)\n");
			break;
		case ET_EXEC:
			printf("EXEC (Executable)\n");
			break;
		case ET_DYN:
			printf("DYN (Shared object file)\n");
			break;
		case ET_CORE:
			printf("CORE (Core file)\n");
			break;
		case ET_LOPROC:
			printf("LOPROC (Processor-specific)\n");
			break;
		case ET_HIPROC:
			printf("HIPROC (Processor-specific)\n");
			break;
	}
	printf("  Machine:                           ARM\n");
	printf("  Version:                           0x%x\n",headers.e_version);
	printf("  Entry point address:               0x%x\n",headers.e_entry);

	printf("  Start of program headers:          %u (bytes into file)\n",headers.e_phoff);

	printf("  Start of section headers:          %u (bytes into file)\n",headers.e_shoff);

	printf("  Flags:                             0x%x",headers.e_flags);
	if(headers.e_flags==0x5000000) printf(", Version5 EABI");
	printf("\n");

	printf("  Size of this header:               %d (bytes)\n", headers.e_ehsize);
	printf("  Size of program headers:           %d (bytes)\n", headers.e_phentsize);
	printf("  Number of program headers:         %d\n", headers.e_phnum);
	printf("  Size of section headers:           %d (bytes)\n", headers.e_shentsize);
	printf("  Number of section headers:         %d\n", headers.e_shnum);

	if(headers.e_shstrndx==SHN_UNDEF)
		printf("  Section header string table index: SHN_UNDEF\n");
	else
		printf("  Section header string table index: %d\n", headers.e_shstrndx);

}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
leaq 0x20(%rsp), %r14
leaq 0x296f(%rip), %rdi      # 0x42d4
xorl %eax, %eax
callq 0x1090
leaq 0x2979(%rip), %rbx      # 0x42ec
xorl %r15d, %r15d
cmpq $0x10, %r15
je 0x1990
movzbl (%r14,%r15), %esi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1090
incq %r15
jmp 0x1976
movzbl 0x4(%r14), %esi
shll $0x5, %esi
leaq 0x2953(%rip), %rdi      # 0x42f2
xorl %eax, %eax
callq 0x1090
leaq 0x2972(%rip), %rdi      # 0x431f
xorl %eax, %eax
callq 0x1090
cmpb $0x1, 0x5(%r14)
leaq 0x2d19(%rip), %rax      # 0x46d9
leaq 0x2d07(%rip), %rdi      # 0x46ce
cmoveq %rax, %rdi
callq 0x1060
movzbl 0x6(%r14), %esi
leaq 0x2979(%rip), %rdi      # 0x4355
xorl %eax, %eax
callq 0x1090
leaq 0x299e(%rip), %rdi      # 0x4388
xorl %eax, %eax
callq 0x1090
movzwl 0x12(%r14), %esi
cmpl $0x28, %esi
jne 0x1a09
leaq 0x2ce5(%rip), %rdi      # 0x46e7
callq 0x1060
jmp 0x1a17
leaq 0x299e(%rip), %rdi      # 0x43ae
xorl %eax, %eax
callq 0x1090
leaq 0x2cd9(%rip), %rdi      # 0x46f7
callq 0x1060
leaq 0x29a8(%rip), %rdi      # 0x43d2
xorl %eax, %eax
callq 0x1090
movzwl 0x10(%r14), %eax
cmpq $0x4, %rax
ja 0x1a55
leaq 0x2859(%rip), %rcx      # 0x429c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x2d56(%rip), %rdi      # 0x47a9
jmp 0x1a97
cmpl $0xff00, %eax           # imm = 0xFF00
je 0x1a75
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0x1a9c
leaq 0x2cb4(%rip), %rdi      # 0x471e
jmp 0x1a97
leaq 0x2ce3(%rip), %rdi      # 0x4756
jmp 0x1a97
leaq 0x2cbe(%rip), %rdi      # 0x473a
jmp 0x1a97
leaq 0x2cfb(%rip), %rdi      # 0x4780
jmp 0x1a97
leaq 0x2cd9(%rip), %rdi      # 0x4767
jmp 0x1a97
leaq 0x2cfb(%rip), %rdi      # 0x4792
callq 0x1060
leaq 0x2d1a(%rip), %rdi      # 0x47bd
callq 0x1060
movl 0x14(%r14), %esi
leaq 0x2945(%rip), %rdi      # 0x43f8
xorl %eax, %eax
callq 0x1090
movl 0x18(%r14), %esi
leaq 0x295e(%rip), %rdi      # 0x4423
xorl %eax, %eax
callq 0x1090
movl 0x1c(%r14), %esi
leaq 0x2977(%rip), %rdi      # 0x444e
xorl %eax, %eax
callq 0x1090
movl 0x20(%r14), %esi
leaq 0x29a0(%rip), %rdi      # 0x4489
xorl %eax, %eax
callq 0x1090
movl 0x24(%r14), %ebx
leaq 0x29c9(%rip), %rdi      # 0x44c4
movl %ebx, %esi
xorl %eax, %eax
callq 0x1090
cmpl $0x5000000, %ebx        # imm = 0x5000000
jne 0x1b1a
leaq 0x29db(%rip), %rdi      # 0x44ee
xorl %eax, %eax
callq 0x1090
pushq $0xa
popq %rdi
callq 0x1040
movzwl 0x28(%r14), %esi
leaq 0x29d0(%rip), %rdi      # 0x44fe
xorl %eax, %eax
callq 0x1090
movzwl 0x2a(%r14), %esi
leaq 0x29ee(%rip), %rdi      # 0x452f
xorl %eax, %eax
callq 0x1090
movzwl 0x2c(%r14), %esi
leaq 0x2a0c(%rip), %rdi      # 0x4560
xorl %eax, %eax
callq 0x1090
movzwl 0x2e(%r14), %esi
leaq 0x2a22(%rip), %rdi      # 0x4589
xorl %eax, %eax
callq 0x1090
movzwl 0x30(%r14), %esi
leaq 0x2a40(%rip), %rdi      # 0x45ba
xorl %eax, %eax
callq 0x1090
movzwl 0x32(%r14), %esi
testl %esi, %esi
je 0x1b9d
leaq 0x2a52(%rip), %rdi      # 0x45e3
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
jmp 0x1090
leaq 0x2c42(%rip), %rdi      # 0x47e6
popq %rbx
popq %r14
popq %r15
jmp 0x1060
nop