From: Matt Mullins Date: Sat, 21 Sep 2013 04:37:50 +0000 (-0700) Subject: Read random memory out of the address space. X-Git-Url: http://git.mmlx.us/?a=commitdiff_plain;h=a0c58e5bd1bb00220020ae9ab26d5effd5783c3b;p=mmap_everything.git Read random memory out of the address space. --- 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); + } }