Raw Memory Dump/Access Outside Memory

Sep 14, 2010 at 11:29pm
closed account (Lv0f92yv)
This is sort of a two part question. The first (and more practical) is, can I dump or somehow view the memory my program is using to a file or to standard output? How would I go about doing this?

Ex: I have a program that allocates space on the stack for a character array "my letters". I want to dump the memory allocated to my program at runtime to a file/std output, such that I can try to find the letters stored in that program. I understand that I will probably be only seeing bytes, and not the letters themselves. This is OK. Is this possible?

Also, is there a way to see the contents of memory that is allocated to other programs, such as games, browsers, music applications, anything running on my computer? Even if it amounts to guessing at the address in memory where these things MIGHT be allocated?

This is something I've wanted to do for a while, but have never really looked into.

Thanks for any direction on where to look for information on this.
Sep 15, 2010 at 9:50am
Yes, you can dump memory. For ex:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
struct A
{
  int a;
  std::string b;
  void dump()
  {
    char * start=reinterpret_cast<char*>(this);
    char * end=&(start+sizeof(A));
    while (start!=end)
    {
      std::cout<<(int)*start;
      ++start;
    }
  }
};

this dump function dumps the binary representation of A (in form of decimal numbers - you can convert it to hex using ostream manipulators)
To dump the stack you must know its location somehow. Refer to you compiler manual, the part describing how stack and heap allocators work.
In fact most character data allocated in the heap, not stack. (And constants usually live in data section of executable)

About other programs - first you must have the rights to do it, second - the methods are specific to system.
Sep 16, 2010 at 12:36am
closed account (Lv0f92yv)
Thanks for this, I will play around with it some more.

Cheers.
Sep 26, 2010 at 1:05am
closed account (Lv0f92yv)
About the rights to access memory used by other programs - the program that owns the memory has to allow other programs to see it? I thought this was managed by the OS (the operating system knows about what memory was allocated to the program, and can prevent other programs from accessing it).
Sep 27, 2010 at 10:40am
Access system in modern OS are complex, and doubtly can be described in two words. All access checks are made by OS, but rights can be set and/or modified by any process that has rights to do it.
Sep 27, 2010 at 12:45pm
closed account (EzwRko23)

Also, is there a way to see the contents of memory that is allocated to other programs, such as games, browsers, music applications, anything running on my computer?


The easiest way to do this is to make your program start that other program. In such case, your process becomes its parent and has all the required privileges to read its memory and/or even write it. This option is commonly used by debuggers and... cracks.
Sep 27, 2010 at 1:46pm
closed account (Lv0f92yv)
I should clarify - my goal here isn't to crack software. I was just curious to see if this could be done. This came after a discussion our professor had about accessing private members of a class from outside without using accessors (via unions or void pointers), and this got me thinking about memory access in general and what the limits were. Though I can both see the implications for debugging software and writing cracks...

Thanks for the feedback.
Topic archived. No new replies allowed.