ptrace seems to work but any ideas about how to pass that address (other than in a string, which seems to be a dead end)?
For example: This is program1, which gives up its pid and a char pointer address, then waits around using getc...
Code:
#include <stdio.h>
int main () {
short int pid=getpid();
char this[]="that";
printf("%d\t%x\n", pid, this);
getc(stdin);
}
This is program2, which accepts a pid and a "memory address":
Code:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ptrace.h>
int main (int argc, char *argv[]) {
int pid=atoi(argv[1]), word;
if ((ptrace(PTRACE_ATTACH,pid,NULL,NULL)) != 0) {perror("ptrace fail");return -1;}
if ((word=ptrace(PTRACE_PEEKTEXT,pid,(void*)argv[2],NULL)) == -1) perror("peektext fail");
else printf("%d\n", word);
ptrace(PTRACE_DETACH,pid,NULL,NULL);
}
peektext always fails with an Input/output error