-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintFileHeader.c
More file actions
70 lines (65 loc) · 2.62 KB
/
Copy pathprintFileHeader.c
File metadata and controls
70 lines (65 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "holberton.h"
/* memcmp */
#include <string.h>
/**
* printFileHeader - formatted printing of file header stored in state
*
* @state: struct containing file data and info for error printing
* Return: 1 on failure, 0 on success
*/
int printFileHeader(re_state *state)
{
unsigned int i;
/* this second check of full magic 16 after header load needs to also happen when not printing file header */
if (memcmp(state->f_header.e_ident, ELFMAG, SELFMAG) != 0)
{
errorMsg("Not an ELF file - it has the wrong magic bytes " \
"at the start\n", NULL, state);
return (1);
}
puts("ELF Header:");
printf(" Magic: ");
/* stock readelf prints 1 space before newline */
for (i = 0; i < EI_NIDENT; i++)
printf("%2.2x ", state->f_header.e_ident[i]);
putchar('\n');
printf(" Class: %s\n",
state->ELF_32bit ? "ELF32" : "ELF64");
printf(" Data: %s, %s endian\n",
"2's complement", state->big_endian ? "big" : "little");
printf(" Version: %u%s\n",
state->f_header.e_ident[EI_VERSION],
state->f_header.e_ident[EI_VERSION] ==
EV_CURRENT ? " (current)" : "");
printf(" OS/ABI: %s\n",
getOsabiName(state->f_header.e_ident[EI_OSABI]));
printf(" ABI Version: %u\n",
state->f_header.e_ident[EI_ABIVERSION]);
printf(" Type: %s\n",
getELFType(state->f_header.e_type));
printf(" Machine: %s\n",
getMachineName(state->f_header.e_machine));
printf(" Version: 0x%x\n",
state->f_header.e_version);
printf(" Entry point address: 0x%lx\n",
state->f_header.e_entry);
printf(" Start of program headers: %lu (bytes into file)\n",
state->f_header.e_phoff);
printf(" Start of section headers: %lu (bytes into file)\n",
state->f_header.e_shoff);
printf(" Flags: 0x%x\n",
state->f_header.e_flags);
printf(" Size of this header: %u (bytes)\n",
state->f_header.e_ehsize);
printf(" Size of program headers: %u (bytes)\n",
state->f_header.e_phentsize);
printf(" Number of program headers: %u\n",
state->f_header.e_phnum);
printf(" Size of section headers: %u (bytes)\n",
state->f_header.e_shentsize);
printf(" Number of section headers: %u\n",
state->f_header.e_shnum);
printf(" Section header string table index: %u\n",
state->f_header.e_shstrndx);
return (0);
}