I wrote a very simple program , out of curiosity , to read the first 1000 bytes ahead and behind a single-element array , just to see what values I'd get, and what to make of them.
#include <stdio.h>
int main(){
char mem[1];
printf("\n\tSeeking Ahead...\n\t %lld to %lld\n\n",mem,mem+1000);
for(int i=0; i <= 1000; i++)
printf("%lld ",mem[i]);
printf("\n\n\tSeeking Behind...\n\t %lld to %lld\n\n",mem-1000,mem);
for(int i=1000; i >= 0; i--;)
printf("%lld ",*(mem-i));
printf("\n\n-------END------\n\n");
return 0;
}
The reason for choosing "%lld" was that I had some vague idea that a 64-bit system would have 64-bit addresses , and hence long long may be appropriate (a 64-bit int).
I didn't use "%d" because that would give me -ve values because of int being too small, and "%x" or "%o" will also go crazy with values beyond the size of an unsigned int - for example, I'd get ffff... where int would read -ve values.
I'm aware this is basically U.B. as far as the C standard is concerned but nothing is truly random and so I'd like to know probable reasons why :
- Some values, like
127,0, repeat consistently - Most of the values displayed are 8/10-digit with these digits fixed :
4294967... - Some apparently random 2 or 3 digit values float between this sea of large numbers , like
123,18,55,96...
I'm not asking why these exact values appear, that would be impossible to answer, I'm asking why the general pattern of 0s, 8-10 digit numbers (with 7 common digits ?) and a few normal looking 2-3 digit values appear, and also how to make sense of these values ?
Also, only running this on MacOSX (haven't tried Windows), and with "%c" , upon ' seeking forward ', it returns actual characters like so :
executable_path=./memdump./memdumpTERM_PROGRAM=Apple_TerminalSHELL=/bin/bashTERM=xterm-256colorTMPDIR=/var/folders...
Why ?