From 3af50b956b8887b64c3c29b30a0008be866b24c4 Mon Sep 17 00:00:00 2001 From: the lemons Date: Sun, 5 Feb 2023 19:06:16 -0600 Subject: initial commit --- procfs.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 procfs.c (limited to 'procfs.c') diff --git a/procfs.c b/procfs.c new file mode 100644 index 0000000..63aef3a --- /dev/null +++ b/procfs.c @@ -0,0 +1,28 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "procfs.h" + +int procfs_open(pid_t pid) { + char path[2048]; + sprintf(path, "/proc/%d/mem", pid); + return open(path, O_RDWR); +} + +int read_page(int fd, uintptr_t index, uint8_t *data) { + if (lseek(fd, index * PAGE_SIZE, SEEK_SET) == -1) + return -1; + size_t n = 0; + while (n < PAGE_SIZE) { + ssize_t result = read(fd, data + n, PAGE_SIZE - n); + if (result == -1) return -1; + n += result; + } + return 0; +} -- cgit v1.2.3