accessing memory used by another program

would make a simple one line program that would print the string pointed to by a pointer from another program if argv[1] was the address of the pointer (eg, bfde768f), but it seems not to work.

Now I notice that if I ask gdb (running without an input program) "x/s 0xbfde768f", it can't access this memory (it's "out of bounds"). I had thought memory was "protected" by simple assigned (ie. the same address won't be handed out twice) and not by actual restriction, as appears to be the case.

thanks matsp...this implies unless the other program is a forked child, it's memory space is permanently out-of-bounds.

Which means there is not much purpose in trying to do the following, but given that char address[9] is a string containing a memory address, how can I actually get the content of that address if it's "in bounds" (as it turns out, &address doesn't do that)?

Alternatively, the parent may commence trace of an existing process using PTRACE_ATTACH.

You can check if the address is valid in the child process:

On success, PTRACE_PEEK* requests return the requested data, while other requests return zero. On error, all requests return -1, and errno is set appropriately. Since the value returned by a successful PTRACE_PEEK* request may be -1, the caller must check errno after such requests to determine whether or not an error occurred.

--
Mats

Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.

What are you ACTUALLY trying to do? [not the "I want to undo a bolt", but "I want to replace my wheel, because I have a puncture"]

Edit: You may find that PEEKTEXT fails because the address of this is in the stack, so the data segment rather than the text (code) segment?

--
Mats

Eventually I'd like to ride down the hill

I think PEEKTEXT fails because passing it a string from a character array can't work. This is why I asked "given that char address[9] is a string containing a memory address, how can I actually get the content of that address". Here's what I mean:

This just prints the address -- which is to say that is a string containing an address (as a string), but it's useless for obtaining the contents of an actual location in memory. So that's probably true of argv[2] in program2. Generally, one would use *ptr=this and never deal with addresses as string values. But I don't see a way to pass "the information" otherwise...

The goal here is to print "that" (literally) without using anything except a literal number or string as the address (no "%p"). Besides w/ the ptrace example, this would be the same as if you asked for user input in the form of a memory address, where the user might type:

0xbfbc446d

Now, how could you use that address (a string literal inputted by the user) the same way you would a *ptr? It seems it cannot be done...

You can only expect a fixed address like this if you have some way of making your executable operate within a fixed address. Which is highly unlikely that you have this capability at your disposal. Thus you need to go about acquiring the address location you are wanting to manipulate via other means.