I want to define a buffer of any size which gets some space allocated in the memory. I want to read existing data inside the memory allocated to that buffer.
I have tried following code but all I am just seeing some special characters every time.
If I take dump of my memory via DumpIt tool and then open it via HEX Editor, I can see normal characters (like digits and abc etc).
I used following code which uses two techniques first mentioned here and second uses just simple array and go through each character one by one.
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <process.h>
#include <time.h>
#include <cstdlib>
#include <stdint.h>
int main()
{
int x = 4;
char arr[400];
char * src;
src = arr;
uint8_t *memory = (uint8_t *) malloc(1000);
while(*memory != NULL) {
printf("Character %c\n", *(memory++));
memory++;
}
while(src != NULL) {
printf("%c ", *src);
x++;
if(x == 1000)
break;
}
printf("And the data stored in memory is %s\n", arr);
system("PAUSE");
return 0;
}
When you run malloc, you’re just going to get random stuff in that memory segment. Some of it won’t be able to be encoded into anything readable with ASCII. You could try printing the hex values of what’s in memory with “%X” instead of “%c”.
Though I have no idea why you would want to do such a thing.