+++ /dev/null
-#define _GNU_SOURCE
-
-#include <errno.h>
-#include <string.h>
-#include <sys/types.h>
-#include <dirent.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdlib.h>
-
-int main(int argc, char *argv[]) {
- if (argc != 3) {
- fputs("invocation: ./viewmem /proc/<pid>/mem <addr>\n", stderr);
- return 1;
- }
- char *end;
- errno = 0;
- unsigned long long addr = strtoull(argv[2], &end, 0);
- if (errno != 0 || *end != 0) {
- fputs("invalid addr\n", stderr);
- return 1;
- }
- int fd = open(argv[1], O_RDWR);
- if (fd == -1) {
- fprintf(stderr, "error: can't open %s - %s\n", argv[1], strerror(errno));
- return 1;
- }
- fprintf(stderr, "please press the any key...\n");
- fd = openat(fd, "", 0, O_RDWR);
- while (getchar() != '\n');
- fprintf(stderr, "trying to dump...");
- errno = 0;
- lseek(fd, addr, SEEK_SET);
- if (errno != 0) {
- fprintf(stderr, "lseek() failed: %s\n", strerror(errno));
- return 1;
- }
- char buf[4096]; // nothing interesting has a different pagesize anyway
- int i=0;
- while (read(fd, buf, 4096) == 4096) {
- write(1, buf, 4096);
- i++;
- }
- fprintf(stderr, "read %i pages\n", i);
- return 0;
-}