From 285025ee086b7631cb102c20300c8da7f2d9a52e Mon Sep 17 00:00:00 2001 From: the lemons Date: Tue, 7 Feb 2023 15:15:00 -0600 Subject: change behavior of jumping between maps --- procfs.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'procfs.c') diff --git a/procfs.c b/procfs.c index e3bfb2c..2558f03 100644 --- a/procfs.c +++ b/procfs.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -27,12 +28,33 @@ ssize_t procfs_maps(pid_t pid, struct procfs_map **maps) { if (!*maps) return -1; while (1) { void *base, *max; - int matches = fscanf(f, "%p-%p", &base, &max); + char prot_str[4]; + int matches = fscanf(f, "%p-%p %4c", &base, &max, prot_str); if (matches == EOF) goto eof; - if (matches < 2) goto err; + if (matches < 3) goto err; + + int prot = 0; + for (int i = 0; i < 4; i++) { + switch (prot_str[i]) { + case 'r': + prot |= PROT_READ; + break; + case 'w': + prot |= PROT_WRITE; + break; + case 'x': + prot |= PROT_EXEC; + break; + default: + break; + } + } + if (prot == 0) prot = PROT_NONE; + int c; while ((c = getc(f)) != '\n') if (c == EOF) goto eof; + n++; if (n > capacity) { capacity <<= 1; @@ -40,8 +62,9 @@ ssize_t procfs_maps(pid_t pid, struct procfs_map **maps) { if (!r) goto err; *maps = r; } - (*maps)[n - 1].base = (uintptr_t) base; - (*maps)[n - 1].max = (uintptr_t) max; + (*maps)[n - 1] = (struct procfs_map) { + (uintptr_t) base, (uintptr_t) max, prot + }; } eof: if (ferror(f)) goto err; -- cgit v1.2.3