#include <limits.h>
#include <sys/mman.h>
#include <sys/types.h>
+#include <stdint.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
#include <unistd.h>
#define MAX_BITS (sizeof(size_t) * CHAR_BIT - 1)
}
}
- getchar();
+ srand48(time(NULL));
+ while (1) {
+ printf("Press enter to read a random byte of memory. (pid %d) >", pid);
+ while (getchar() != '\n');
+ uint32_t lower = lrand48();
+ uint32_t upper = lrand48();
+
+ long pvalue = ((long)lower << 32) | ((long)upper);
+ // align to integer, keep in "userspace" address space
+ pvalue &= 0x00007FFFFFFFFFF0;
+
+ int *pi = (void*)(pvalue);
+ printf("*%p = %x\n", (void*)pi, *pi);
+ }
}