0x15. C File I O TASK 04 - humtej1204/holbertonschool-low_level_programming GitHub Wiki
4. elf
#advanced
Write a program that displays the information contained in the ELF
header at the start of an ELF file.
- Usage:
elf_header elf_filename
- Displayed information: (no less, no more, do not include trailing whitespace)
- Magic
- Class
- Data
- Version
- OS/ABI
- ABI Version
- Type
- Entry point address
- Format: the same as
readelf -h
(version2.26.1
) - If the file is not an
ELF
file, or on error, exit with status code 98 and display a comprehensive error message to stderr - You are allowed to use
lseek
once - You are allowed to use
read
a maximum of 2 times at runtime - You are allowed to have as many functions as you want in your source file
- You are allowed to use
printf
manelf
,readelf
julien@ubuntu:~/0x15. File descriptors and permissions$ gcc -Wall -pedantic -Werror -Wextra -std=gnu89 100-elf_header.c -o elf_header
julien@ubuntu:~/0x15. File descriptors and permissions$ ./elf_header ubuntu64
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Entry point address: 0x400600
julien@ubuntu:~/0x15. File descriptors and permissions$ readelf --version
GNU readelf (GNU Binutils for Ubuntu) 2.26.1
Copyright (C) 2015 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) any later version.
This program has absolutely no warranty.
julien@ubuntu:~/0x15. File descriptors and permissions$ readelf -h ubuntu64
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: Advanced Micro Devices X86-64
Version: 0x1
Entry point address: 0x400600
Start of program headers: 64 (bytes into file)
Start of section headers: 6936 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 9
Size of section headers: 64 (bytes)
Number of section headers: 31
Section header string table index: 28
julien@ubuntu:~/0x15. File descriptors and permissions$ ./elf_header /lib/ld-linux.so.2
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Shared object file)
Entry point address: 0xac0
julien@ubuntu:~/0x15. File descriptors and permissions$ readelf -h /lib/ld-linux.so.2
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Shared object file)
Machine: Intel 80386
Version: 0x1
Entry point address: 0xac0
Start of program headers: 52 (bytes into file)
Start of section headers: 145756 (bytes into file)
Flags: 0x0
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 7
Size of section headers: 40 (bytes)
Number of section headers: 24
Section header string table index: 23
julien@ubuntu:~/0x15. File descriptors and permissions$ ./elf_header netbsd32
ELF Header:
Magic: 7f 45 4c 46 01 01 01 02 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - NetBSD
ABI Version: 0
Type: EXEC (Executable file)
Entry point address: 0x80484c0
julien@ubuntu:~/0x15. File descriptors and permissions$ ./elf_header sortix32
ELF Header:
Magic: 7f 45 4c 46 01 01 01 53 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: <unknown: 53>
ABI Version: 0
Type: EXEC (Executable file)
Entry point address: 0x80484c0
julien@ubuntu:~/0x15. File descriptors and permissions$ ./elf_header solaris32
ELF Header:
Magic: 7f 45 4c 46 01 01 01 06 01 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - Solaris
ABI Version: 1
Type: EXEC (Executable file)
Entry point address: 0x8052400
julien@ubuntu:~/0x15. File descriptors and permissions$ ./elf_header sparc32
ELF Header:
Magic: 7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, big endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Entry point address: 0x10d20
julien@ubuntu:~/0x15. File descriptors and permissions$
Repo:
- GitHub repository: holbertonschool-low_level_programming
- Directory: 0x15-file_io
- File: 100-elf_header.c