开发者

how to scan the system memory through program?

开发者 https://www.devze.com 2023-01-24 06:38 出处:网络
I just want to read the system memory, not the memory allocated for other processes, just free memory.

I just want to read the system memory, not the memory allocated for other processes, just free memory. I tried allocating huge memory using malloc:

char *ptr;
ptr = (char*)malloc((1024*1024*700)*sizeof(char));

I tried to print it, but it is printing the null character (i.e. nothing).

printf("%c",ptr[i]);

So I casted its type to int, thinking that it may print the ascii of it.

printf("",(int)ptr[i]);

All the values printed are 0.

malloc doesn't initialize the memory allocat开发者_高级运维ed, does it? I couldn't print the memory.

I tried it in linux, fedora 14, with latest gcc and windows xp with dev-c++

I just want to access the memory. Is it possible through some kernel pgm in linux by using the address and get the date out of it? Can you suggest some tools for reading the ram?


It's true that malloc() itself doesn't initialise the memory, but the operating system does typically sanitise the memory it hands your process when it requests more. This is a security measure.

If you wish to directly read physical memory, you can do so by opening /dev/mem and mapping the portion of interest using mmap(). The permissions on /dev/mem usually restrict this access to root.


Regarding:

the system memory , not the memory allocated for other processes, just free memory

On a modern operating system, this has no real meaning, as all memory is virtual. As caf has said you could try scanning /proc/mem (as root), but that would give you all physical memory (including physical memory that currently happens to contain other processes' data) and would miss data which has been swapped to disk or kept by some other backing than physical memory. Perhaps if you clarify what you want to achive, you'll get better answers.

0

精彩评论

暂无评论...
验证码 换一张
取 消