Can't undate running process binary in Solaris?
- From: Boltar <boltar2003@xxxxxxxxxxx>
- Date: Thu, 05 Jul 2007 03:40:12 -0700
Hi
I'm trying to get a running process to update its own binary but for
some reason under Solaris it doesn't work , the binary remains
unchanged even though no errors are returned from any function. Does
anyone know why this might happen? My test code is below:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mman.h>
char *tag = "TEST";
int main(int argc, char **argv)
{
struct stat fs;
char *mptr;
char *start;
char *end;
int fd;
if ((fd = open(argv[0],O_RDWR)) == -1)
{
perror("open()"); exit(1);
}
if (fstat(fd,&fs) == -1)
{
perror("fstat()"); exit(1);
}
mptr = (char *)mmap(
NULL,fs.st_size,PROT_READ | PROT_WRITE,MAP_PRIVATE,fd,
0);
if (mptr == MAP_FAILED)
{
perror("mmap()"); exit(1);
}
end = mptr + fs.st_size - strlen(tag) - 1;
for(start = mptr;start != end;++start)
{
if (start[0] == 'T' &&
start[1] == 'E' &&
start[2] == 'S' &&
start[3] == 'T')
{
printf("Found tag at address 0x%08X\n",start);
memcpy(start,"DONE",4);
if (munmap(mptr,fs.st_size) == -1)
{
perror("munmap()"); exit(1);
}
if (close(fd) == -1)
{
perror("close()"); exit(1);
}
return 0;
}
}
puts("Tag not found.");
return 0;
}
Thanks for any help
B2003
.
- Follow-Ups:
- Re: Can't undate running process binary in Solaris?
- From: Paul Pluzhnikov
- Re: Can't undate running process binary in Solaris?
- From: Frank Cusack
- Re: Can't undate running process binary in Solaris?
- From: Eric Sosman
- Re: Can't undate running process binary in Solaris?
- From: David Schwartz
- Re: Can't undate running process binary in Solaris?
- Prev by Date: Re: Cross platform pointer to program text area?
- Next by Date: Re: hiding a counter
- Previous by thread: hiding a counter
- Next by thread: Re: Can't undate running process binary in Solaris?
- Index(es):
Relevant Pages
|