Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

The design of the exoskeleton. Monograph

.pdf
Скачиваний:
0
Добавлен:
07.09.2026
Размер:
2 Мб
Скачать
171
* Handle int $0x80 calls - no matter why and where * ****************************************************/
static inline void want_ret(void) { current->syscall=r.eax; memcpy(¤t->pr,&r,sizeof(r)); }
/******************** * "Before" handler * ********************/
static void handle_syscall(void) { char buf[MAXFNAME]; unsigned int addr;
if (current->nest>=-1) current->syscalls++;
switch (r.eax) {
case __NR_clone:
debug("***************************************************************\n" "* This application uses clone(). This is probably a sign of *\n" "* multi-threaded application. Multi-threading involves shared *\n" "* memory segments, file descriptors and such, and I am not *\n" "* able to handle it properly for now. Sorry... *\n" "***************************************************************\n");
fatal("clone() is not supported",0);
break;
case __NR_fork: #ifdef __NR_vfork case __NR_vfork: #endif /* __NR_vfork */
if (T_forks) trace_fork(); else { remove_traps(); want_ret(); } break;
172
case __NR_exit:
indent(0); debug("%sSYS exit (%d) = ???\n",in_libc?"[L] ":"", (int)r.ebx);
while (--current->nest>= -1 ) { indent(0); debug("...function never returned (program exited before).\n"); if (current->nest<0 || current->isfnct[current->nest]) { dump_memchg(0); if (current->fntop) current->fntop--; } if (T_dostep) break_nestdown(); }
break;
case __NR_execve:
indent(0);
get_string_from_child(r.ebx,buf,MAXFNAME);
RD();
debug("%sSYS execve (%x \"%s\", 0x%x, 0x%x) = ",in_libc?"[L] ":"", Xv(r.ebx),buf,Xv(r.ecx),Xv(r.edx));
DD();
current->syscall=__NR_execve; break;
case __NR_sigaction: #ifdef __NR_rt_sigaction case __NR_rt_sigaction: #endif /* __NR_rt_sigaction */
// Modify address in memory structure. addr=ptrace(PTRACE_PEEKDATA,pid,r.ecx,0);
if (!addr) break;
if ((addr >> 24) == CODESEG) ptrace(PTRACE_POKEDATA,pid,r.ecx,addr-1);
173
else break;
goto aftersig;
case __NR_signal:
// Simply adjust address in register. addr=r.ecx;
if (!addr) break; if ((addr >> 24) == CODESEG || INLIBC(addr)) r.ecx--; else break;
ptrace(PTRACE_SETREGS,pid,0,&r); r.ecx++; // So __NR_signal handler won't have to do anything.
aftersig:
// Inject int3 into code. if (addr) if ((addr >> 24) == CODESEG || INLIBC(addr)) { unsigned int chg,c2; chg=ptrace(PTRACE_PEEKDATA,pid,addr-1,0); if ((current->signals < r.ebx) && (r.ebx < MAXSIG)) current->signals=r.ebx;
if (((chg & 0xff) != 0x90) && ((chg & 0xff) != 0xc3) && ((chg & 0xff) != 0xcc)) { c2=ptrace(PTRACE_PEEKDATA,pid,addr-3,0); if ((c2 & 0xffffff) != 0x00768d) // Stupid gcc -O9 lea debug("* WARNING: Handler for sig %d (%x) w/o leading NOP or RET,
problems!\n",(int)r.ebx,addr);
}
if ((chg & 0xff) == 0xc3) set_withret(r.ebx,1); else if ((chg & 0xff) == 0x90) set_withret(r.ebx,0); chg = ( chg & 0xffffff00 ) + 0xcc; /* cc: int3 */ ptrace(PTRACE_POKEDATA,pid,addr-1,chg);
}
default: want_ret();
}
174
if (T_dostep && current) { fflush(0); break_syscall(r.eax); }
}
/************************ * Add item to fd table * ************************/
static void add_filedes(const int fd,const char* fname,char* who,int p) {
char tmpbuf[MAXDESCR];
if (!current->fd) { current->fd=malloc(TABINC*sizeof(struct fenris_fd)); current->fdtop=TABINC; }
while (current->fdtop<=fd) { current->fdtop+=TABINC; current->fd=realloc(current->fd,current->fdtop*sizeof(struct fenris_fd)); }
(*current->fd)[fd].special=0; (*current->fd)[fd].name=strdup(fname);
snprintf(tmpbuf,MAXDESCR,"opened in %s",who);
(*current->fd)[fd].descr=strdup(tmpbuf); (*current->fd)[fd].p=p;
if (current->nest>=-1 && !T_nodesc) { indent(0); debug("@ created fd %d (%s)\n",fd,fname); }
}
/*********************** * Add unknown filedes * ***********************/
175
static void unknown_filedes(const int fd,const char* fname) {
char tmpbuf[MAXDESCR];
if (!current->fd) { current->fd=malloc(TABINC*sizeof(struct fenris_fd)); current->fdtop=TABINC; }
while (current->fdtop<=fd) { current->fdtop+=TABINC; current->fd=realloc(current->fd,current->fdtop*sizeof(struct fenris_fd)); }
(*current->fd)[fd].special=0; (*current->fd)[fd].name=strdup(fname);
snprintf(tmpbuf,MAXDESCR,"origin unknown");
(*current->fd)[fd].descr=strdup(tmpbuf); (*current->fd)[fd].p=0;
}
/********************** * Duplicate filedes. * **********************/
static void dup_filedes(const int old,const int fd,char* who) { char tmpbuf[MAXDESCR];
if (current->fdtop<=old) fatal("dup_filedes with excessive fd",0); if (old<0 || fd<0) fatal("dup_filedes with excessive fd",0);
while (current->fdtop<=fd) { current->fdtop+=TABINC; current->fd=realloc(current->fd,current->fdtop*sizeof(struct fenris_fd)); }
if ((*current->fd)[fd].name) { RD(); Xf(fd); DD(); remove_filedes(fd); }
176
if (!(*current->fd)[old].name) (*current->fd)[fd].name=strdup("<unknown>"); else (*current->fd)[fd].name=strdup((*current->fd)[old].name);
snprintf(tmpbuf,MAXDESCR,"cloned in %s",who); (*current->fd)[fd].descr=strdup(tmpbuf); (*current->fd)[fd].p=(*current->fd)[old].p;
if (current->nest>=-1 && !T_nodesc) { indent(0); debug("@ new duplicate fd %d from %d (%s)\n",fd,old,(*current->fd)[fd].name); }
}
/***************************** * Remove item from fd table * *****************************/
static void remove_filedes(const int fd) {
if ((fd>=0) && (fd<current->fdtop) && (*current->fd)[fd].name) {
if (current->nest>=-1 && !T_nodesc) { indent(0); debug("@ removed fd %d (%s)\n",fd,(*current->fd)[fd].name); }
free((*current->fd)[fd].name); free((*current->fd)[fd].descr); (*current->fd)[fd].name=0; (*current->fd)[fd].descr=0;
}
}
/*********************** * Change filedes info * ***********************/
static void modify_filedes(const int fd,const char* newt, int newp) { if ((fd>=0) && (fd<current->fdtop) && (*current->fd)[fd].name) { if (newt) {
177
free((*current->fd)[fd].name); (*current->fd)[fd].name=strdup(newt); } if (newp) (*current->fd)[fd].p=newp;
} }
/*************************** * Get .p parameter (port) * ***************************/
static int get_filep(const int fd) { if ((fd>=0) && (fd<current->fdtop) && (*current->fd)[fd].name) return (*current->fd)[fd].p; return 0;
178
Scientific publication
О.V. Malyuga
The design of the exoskeleton
Monograph
Published in the author's edition
Distribution of mandatory copies is carried out in accordance with
applicable regulations
Signed in print 22.04.2018 Format 60x84 / 16.
Usl. p. L. 45. Circulation 2000. Order 314.
IPR-media
Saratov, Russia
2019