From a0c58e5bd1bb00220020ae9ab26d5effd5783c3b Mon Sep 17 00:00:00 2001 From: Matt Mullins Date: Fri, 20 Sep 2013 21:37:50 -0700 Subject: [PATCH] Read random memory out of the address space. --- mmap_everything.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/mmap_everything.c b/mmap_everything.c index 2e9c7c3..8cd4646 100644 --- a/mmap_everything.c +++ b/mmap_everything.c @@ -1,7 +1,10 @@ #include #include #include +#include #include +#include +#include #include #define MAX_BITS (sizeof(size_t) * CHAR_BIT - 1) @@ -41,5 +44,18 @@ int main() { } } - 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); + } } -- 2.11.0