-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdumpauxv.c
More file actions
128 lines (111 loc) · 2.04 KB
/
dumpauxv.c
File metadata and controls
128 lines (111 loc) · 2.04 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <elf.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
typedef unsigned long ulong;
int wrap_open(const char* str) {
if (!strcmp(str, "-"))
return 0;
int fd = open(str, O_RDONLY);
if (fd < 0)
perror(str);
return fd;
}
int pr_u(ulong x) {
return printf("%lu", x);
}
int pr_x(ulong x) {
return printf("%#lx", x);
}
struct {
ulong type;
const char* str;
int (*pr)(ulong);
} parser[] = {
#define X(X, print) { .type = AT_##X, .str = #X, .pr = pr_##print }
X(BASE, x),
X(BASE_PLATFORM, x),
X(IGNORE, x),
X(EXECFD, x),
X(PHDR, x),
X(PHENT, u),
X(PHNUM, u),
X(PAGESZ, u),
X(BASE, x),
X(FLAGS, x),
X(ENTRY, x),
X(NOTELF, x),
X(UID, u),
X(EUID, u),
X(GID, u),
X(EGID, u),
X(CLKTCK, u),
X(PLATFORM, x),
X(HWCAP, x),
X(FPUCW, x),
X(DCACHEBSIZE, x),
X(ICACHEBSIZE, x),
X(UCACHEBSIZE, x),
X(IGNOREPPC, x),
X(SECURE, x),
X(BASE_PLATFORM, x),
X(RANDOM, x),
X(HWCAP2, x),
X(EXECFN, x),
X(SYSINFO, x),
X(SYSINFO_EHDR, x),
X(L1I_CACHESHAPE, x),
X(L1D_CACHESHAPE, x),
X(L2_CACHESHAPE, x),
X(L3_CACHESHAPE, x),
X(L1I_CACHESIZE, x),
X(L1I_CACHEGEOMETRY, x),
X(L1D_CACHESIZE, x),
X(L1D_CACHEGEOMETRY, x),
X(L2_CACHESIZE, x),
X(L2_CACHEGEOMETRY, x),
X(L3_CACHESIZE, x),
X(L3_CACHEGEOMETRY, x),
#undef X
};
#define arrsze(X) (sizeof(X) / sizeof(*(X)))
static int dump_auxv(int fd) {
struct { ulong type; ulong val; } at;
int err;
while ((err = read(fd, &at, sizeof(at))) > 0 && at.type != AT_NULL) {
for (size_t j = 0; j < arrsze(parser); j++) {
if (parser[j].type == at.type) {
printf("%s:\t", parser[j].str);
parser[j].pr(at.val);
printf("\n");
goto iter;
}
}
printf("%#016lx:\t%#016lx\n", at.type, at.val);
iter:
;
}
if (err < 0)
perror("read");
return err;
}
int main(int argc, const char** argv) {
const char *argv_no_args[] = {
"-",
NULL
};
argc--; argv++;
if (!*argv) {
argv = argv_no_args;
argc++;
}
for (int i = 0; i < argc; i++) {
int fd = wrap_open(argv[i]);
if (fd < 0)
return 1;
if (dump_auxv(fd) < 0)
return 1;
}
return 0;
}