sorry to pollute... but my conclusion is probably interesting for you
as well... it works with pread... which means is better than lseek +
read, as it is only one kernel call...
however the problem was with the variable ... I was failing to read
due to the variable... I can access fpat's address that , but not
buff, that is allocated on the stack... It is a strange limitation...
It seems that you simply cannot access the stack...
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
int main()
{
char *fpat = "/proc/%d/mem";
pid_t pp = getpid();
char buff[100];
pid_t cp;
char bb[1000];
if( (cp = fork()) == 0)
{
cp = getpid(); //child
sprintf(buff, fpat, cp);
int fd = open(buff, O_RDONLY );
//int s = pread(fd, bb, 10, buff ); //fails!!!
int s = pread(fd, bb, 10, fpat );//works... why? both are
allocated on the stack
printf("child, child memory: cp: %d, pp: %d, f: %s, fd: %d,
read: %d, errno: %s\n",
cp, pp, buff, fd, s, strerror(errno));
_exit(1);
}
else
{
sprintf(buff, fpat, pp);
int fd = open(buff, O_RDONLY );
//int s = pread(fd, bb, 10, buff ); //fails!!!
int s = pread(fd, bb, 10, fpat ); //works... , both are
allocated on the stack...
write(1,bb, 10);
write(1,"\n",1);
printf("main, main memory: cp: %d, pp: %d, f: %s, fd: %d, read:
%d, errno: %s\n",
cp, pp, buff, fd, s, strerror(errno));
}
}
~
--
rgrds,
mobi phil
being mobile, but including technology
http://mobiphil.com
_______________________________________________
radare mailing list
[email protected]
http://lists.nopcode.org/listinfo.cgi/radare-nopcode.org