Добавил:
ivanov666
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Проектирование экзоскелета. Монография
.pdf
191
}
else if (!strcmp(f,"getenv")) {
get_string_from_child(current->lcpar[0],buf,sizeof(buf));
if (r.eax) get_string_from_child(r.eax,b2,sizeof(buf));
debug("%x \"%s\") = %x",Xv(current->lcpar[0]),buf,(int)r.eax);
if (r.eax) debug("\"%s\"\n",b2); else debug("\n");
DD();
warn_opt(1,current->lcpcnt);
add_mem(current->lcpar[0],strlen(buf)+1,0,n,0);
add_mem(r.eax,strlen(b2)+1,0,n,0);
}
else if (!strcmp(f,"atexit")) {
debug("%x) = %d\n",Xv(current->lcpar[0]),(int)r.eax);
DD();
debug("*******************************************************\
n"
"* In some cases, atexit() statement can be not traced *\n"
"* properly (see documentation). *\n"
"*******************************************************\n");
warn_opt(1,current->lcpcnt);
}
else if (!strcmp(f,"strcpy")) {
get_string_from_child(current->lcpar[1],b2,sizeof(buf));
debug("%x, %x \"%s\") = %x\n",Xv(current->lcpar[0]),
Xv(current->lcpar[1]),b2,(int)r.eax);
DD();
warn_opt(2,current->lcpcnt);
add_mem(current->lcpar[0],strlen(b2)+1,0,n,0);

192
add_mem(current->lcpar[1],strlen(b2)+1,0,n,0);
modify_lasti(current->lcpar[0],n,0,0,0);
indent(0);
debug("\\ data migration: %x to %x\n",current->lcpar[1],current-
>lcpar[0]);
}
else if (!strcmp(f,"memcpy") || !strcmp(f,"memmove")) {
debug("%x, %x, %d) = %x\n",Xv(current->lcpar[0]),
Xv(current->lcpar[1]),current->lcpar[2],(int)r.eax);
DD();
warn_opt(3,current->lcpcnt);
add_mem(current->lcpar[0],current->lcpar[2],0,n,0);
add_mem(current->lcpar[1],current->lcpar[2],0,n,0);
modify_lasti(current->lcpar[0],n,0,0,0);
indent(0);
debug("\\ data migration: %x to %x\n",current->lcpar[1],current-
>lcpar[0]);
}
else if (!strcmp(f,"memset")) {
debug("%x, %x, %d) = %x\n",Xv(current->lcpar[0]),
current->lcpar[1],current->lcpar[2],(int)r.eax);
DD();
warn_opt(3,current->lcpcnt);
add_mem(current->lcpar[0],current->lcpar[2],0,n,0);
modify_lasti(current->lcpar[0],n,0,0,0);
indent(0);
}
else if (!strcmp(f,"bzero")) {
debug("%x, %d) = %x\n",Xv(current->lcpar[0]),
current->lcpar[1],(int)r.eax);

193
DD();
warn_opt(2,current->lcpcnt);
add_mem(current->lcpar[0],current->lcpar[1],0,n,0);
modify_lasti(current->lcpar[0],n,0,0,0);
}
else if (!strcmp(f,"bcopy")) {
debug("%x, %x, %d) = %x\n",Xv(current->lcpar[0]),
Xv(current->lcpar[1]),current->lcpar[2],(int)r.eax);
DD();
warn_opt(3,current->lcpcnt);
add_mem(current->lcpar[0],current->lcpar[2],0,n,0);
add_mem(current->lcpar[1],current->lcpar[2],0,n,0);
modify_lasti(current->lcpar[1],n,0,0,0);
indent(0);
debug("\\ data migration: %x to %x\n",current->lcpar[0],current-
>lcpar[1]);
}
else if (!strcmp(f,"memcmp") || !strcmp(f,"bcmp")) {
debug("%x, %x, %d) = %x\n",Xv(current->lcpar[0]),
Xv(current->lcpar[1]),current->lcpar[2],(int)r.eax);
DD();
warn_opt(3,current->lcpcnt);
add_mem(current->lcpar[0],current->lcpar[2],0,n,0);
add_mem(current->lcpar[1],current->lcpar[2],0,n,0);
}
else if (!strcmp(f,"getc")) {
FILE x;
int fd;
int off=((int)&x._fileno - (int)&x);
fd=ptrace(PTRACE_PEEKDATA,pid,current->lcpar[0]+off,0);

194
debug("%x [%d]) = '%c' %d\n",Xv(current->lcpar[0]),
Xf(fd),isprint(r.eax)?(int)r.eax:'?',(int)r.eax);
DD();
warn_opt(1,current->lcpcnt);
add_mem(current->lcpar[0],sizeof(x),0,n,0);
}
else if (!strcmp(f,"strcmp")) {
get_string_from_child(current->lcpar[0],buf,sizeof(buf));
get_string_from_child(current->lcpar[1],b2,sizeof(buf));
debug("%x \"%s\", %x \"%s\") = %x\n",current->lcpar[0],buf,
current->lcpar[1],b2,(int)r.eax);
DD();
warn_opt(2,current->lcpcnt);
add_mem(current->lcpar[0],strlen(buf)+1,0,n,0);
add_mem(current->lcpar[1],strlen(b2)+1,0,n,0);
}
else if (!strcmp(f,"strncmp")) {
get_string_from_child(current->lcpar[0],buf,sizeof(buf));
get_string_from_child(current->lcpar[1],b2,sizeof(buf));
debug("%x \"%s\", %x \"%s\", %d) = %x\n",Xv(current->lcpar[0]),buf,
Xv(current->lcpar[1]),b2,current->lcpar[2],(int)r.eax);
DD();
warn_opt(3,current->lcpcnt);
add_mem(current->lcpar[0],strlen(buf)+1,0,n,0);
add_mem(current->lcpar[1],strlen(b2)+1,0,n,0);
}
else if (!strcmp(f,"strncpy")) {
get_string_from_child(current->lcpar[1],b2,sizeof(buf));
debug("%x, %x \"%s\", %d) = %x\n",Xv(current->lcpar[0]),
Xv(current->lcpar[1]),b2,current->lcpar[2],(int)r.eax);

195
DD();
warn_opt(3,current->lcpcnt);
add_mem(current->lcpar[0],current->lcpar[2],0,n,0);
add_mem(current->lcpar[1],strlen(b2)+1,0,n,0);
modify_lasti(current->lcpar[0],n,0,0,0);
indent(0);
debug("\\ data migration: %x to %x\n",current->lcpar[1],current-
>lcpar[0]);
}
else fatal("display_specific called on something non-specific",0);
RD();
}
/*********************************************************
********
* Check if we handle this one separately, save all the stuff... *
**************************************************************
***/
static inline char check_specific(char* n,unsigned int esP,int pcnt) {
int i;
if (strcmp(n,"strlen"))
if (strcmp(n,"getenv"))
if (strcmp(n,"strcpy"))

196
if (strcmp(n,"memcpy"))
if (strcmp(n,"strdup"))
if (strcmp(n,"calloc"))
if (strcmp(n,"malloc"))
if (strcmp(n,"realloc"))
if (strcmp(n,"free"))
if (strcmp(n,"getc"))
if (strcmp(n,"strcmp"))
if (strcmp(n,"strncmp"))
if (strcmp(n,"strncpy"))
if (strcmp(n,"atexit"))
if (strcmp(n,"memmove"))
if (strcmp(n,"memset"))
if (strcmp(n,"bzero"))
if (strcmp(n,"bcopy"))
if (strcmp(n,"memcmp"))
if (strcmp(n,"bcmp"))
return 0;
strncpy(current->lcname,n,MAXNAME);
current->lcpcnt=pcnt;
for (i=0;i<MAXPARS;i++)
current->lcpar[i]=ptrace(PTRACE_PEEKDATA,pid,esP+i*4,0);
return 1;
}

197
/*********************
* Clean up old mess *
*********************/
static void remove_process(void) {
int i;
if (!current)
fatal("trying to remove process but current is NULL",0);
if (current->gopt+current->bopt)
debug("+++ Parameter prediction %0.2f%% successful [%d:%d]
+++\n",100.0*((float)current->gopt)/((float)(current->gopt+current>bopt)),current->bopt,current->gopt);
if (T_dostep) break_exitcond();
for (i=0;i<MAXNEST;i++) {
if (current->wlog[i]) free(current->wlog[i]);
}
if (current->mem) {
int i;
for (i=0;i<current->memtop;i++)
if ((*current->mem)[i].descr) free((*current->mem)[i].descr);
for (i=0;i<current->memtop;i++)
if ((*current->mem)[i].lasti) free((*current->mem)[i].lasti);
free(current->mem);
}
if (current->b) bfd_close(current->b);
if (current->syms) free(current->syms);

198
if (current->map) {
int i;
for (i=0;i<current->mtop+1;i++) {
if ((*current->map)[i].name) free((*current->map)[i].name);
if ((*current->map)[i].descr) free((*current->map)[i].descr);
if ((*current->map)[i].lasti) free((*current->map)[i].lasti);
}
free(current->map);
}
if (current->fd) {
int i;
for (i=0;i<current->fdtop;i++) {
if ((*current->fd)[i].name) free((*current->fd)[i].name);
if ((*current->fd)[i].descr) free((*current->fd)[i].descr);
}
free(current->fd);
}
if (current->fnaddr) free(current->fnaddr);
bzero(current,sizeof(struct fenris_process));
current=0;
}
/********************************************
* Duplicate some structures. I do not even *
* want to think how would it look like for *
* partially shared process info (clone()). *
********************************************/

199
static void clone_process(const int newpid) {
int i;
struct fenris_process *p;
if (!current)
fatal("trying to clone process but current is NULL",0);
p=current;
add_process(newpid);
memcpy(current,p,sizeof(struct fenris_process));
current->pid=newpid;
current->syscall=0;
for (i=0;i<MAXNEST;i++) {
if (current->wlog[i]) current->wlog[i]=strdup(current->wlog[i]);
}
if (current->mem) {
int i;
current->mem=malloc((1+TABINC+current->memtop)*sizeof(struct
fenris_mem));
memcpy(current->mem,p->mem,(1+TABINC+current-
>memtop)*sizeof(struct fenris_mem));
for (i=0;i<current->memtop;i++) {
if ((*p->mem)[i].descr) (*current->mem)[i].descr=strdup((*p-
>mem)[i].descr);
if ((*p->mem)[i].lasti) (*current->mem)[i].lasti=strdup((*p-
>mem)[i].lasti);
}
}
if (current->map) {

200
int i;
current->map=malloc((1+TABINC+current->mtop)*sizeof(struct
fenris_map));
memcpy(current->map,p->map,(1+TABINC+current-
>mtop)*sizeof(struct fenris_map));
for (i=0;i<current->mtop;i++) {
if ((*p->map)[i].descr) (*current->map)[i].descr=strdup((*p-
>map)[i].descr);
if ((*p->map)[i].name) (*current->map)[i].name=strdup((*p-
>map)[i].name);
if ((*p->map)[i].lasti) (*current->map)[i].lasti=strdup((*p-
>map)[i].lasti);
}
}
if (current->fd) {
int i;
current->fd=malloc((1+TABINC+current->fdtop)*sizeof(struct
fenris_fd));
memcpy(current->fd,p->fd,(TABINC+current->fdtop+1)*sizeof(struct
fenris_fd));
for (i=0;i<current->fdtop;i++) {
if ((*p->fd)[i].descr) (*current->fd)[i].descr=strdup((*p->fd)[i].descr);
if ((*p->fd)[i].name) (*current->fd)[i].name=strdup((*p->fd)[i].name);
}
}
if (current->fnaddr) {
current->fnaddr=malloc((1+TABINC+current->idtop)*sizeof(int));
memcpy(current->fnaddr,p->fnaddr,current->idtop*sizeof(int));
}
current->b=0; current->syms=0;
Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]
