-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlp_proc.c
82 lines (78 loc) · 1.82 KB
/
lp_proc.c
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
#include "lp_interp.h"
#include "lp_debug.h"
static void
lp_proc_filepath(struct lp_ctx *ctx)
{
int pid = getpid();
char tmp[PATH_MAX + 1];
snprintf(tmp, PATH_MAX, "/proc/%d/exe", pid);
ctx->proc.exec_proc_path = lp_strdup(tmp);
lp_debug("Set exec_proc_path: %s\n", ctx->proc.exec_proc_path);
return;
}
bool
lp_set_procinfo(struct lp_ctx *ctx)
{
struct lp_auxv_entry entry;
lp_auxv_iterator_t auxv_iter;
struct lp_proc *proc = &ctx->proc;
int argc, i;
/*
* Retrive values from the auxiliary vector
*/
if (lp_auxv_iterator_init(ctx, &auxv_iter) == false) {
lp_debug("No auxiliary vector found\n");
return false;
}
while(lp_auxv_iterator_next(&auxv_iter, &entry) == LP_ITER_OK) {
switch(entry.type) {
case AT_EXECFN:
lp_debug("AT_EXECFN: %s\n", entry.string);
proc->exec_file = lp_strdup((const char *)entry.string);
break;
case AT_PAGESZ:
lp_debug("AT_PAGESZ: %#lx\n", entry.value);
proc->pagesz = entry.value;
break;
case AT_PHDR:
lp_debug("AT_PHDR: %#lx\n", entry.value);
proc->phdr_vaddr = entry.value;
break;
case AT_PHENT:
lp_debug("AT_PHENT: %lu\n", entry.value);
proc->phdr_count = entry.value;
break;
case AT_BASE:
lp_debug("AT_BASE: %#lx\n", entry.value);
proc->interp_base = entry.value;
break;
case AT_FLAGS:
lp_debug("AT_FLAGS: %#lx\n", entry.value);
proc->flags = entry.value;
break;
case AT_ENTRY:
proc->entrypoint = entry.value;
lp_debug("AT_ENTRY: %#lx\n", entry.value);
break;
case AT_UID:
proc->uid = entry.value;
break;
case AT_EUID:
proc->euid = entry.value;
break;
case AT_GID:
proc->gid = entry.value;
break;
case AT_EGID:
proc->egid = entry.value;
break;
case AT_SECURE:
proc->secure = entry.value;
break;
case AT_RANDOM:
proc->random = entry.value;
break;
}
}
lp_proc_filepath(ctx);
}