#ifndef INTERFERE_H #define INTERFERE_H #include #include #include #include #define PHASE_INIT0 0 #define PHASE_INIT1 1 #define PHASE_INIT2 2 #define PHASE_GO 3 #define PHASE_COLLECT1 4 #define PHASE_COLLECT2 5 struct process { pid_t pid; int phase; int again; int sv; long retval; int error; int last_error; int tampered; unsigned long stack; unsigned long oldstack; unsigned long regs[FRAME_SIZE]; unsigned long origregs[FRAME_SIZE]; int mem; int exitsig; }; extern struct process *proc_new(void); extern struct process *proc_init(struct process *handle); extern void proc_attach(struct process *handle, pid_t pid); extern void do_proc_detach(struct process *handle); extern unsigned long proc_pushstackbuf(struct process *handle, const void *buf, size_t len); extern unsigned long proc_pushstack(struct process *handle, size_t len); extern unsigned long proc_popstack(struct process *handle, size_t len); extern void proc_copystackbuf(struct process *handle, void *buf, ssize_t len, off_t offset); extern void do_proc_syncphase(struct process *handle); extern void do_proc_advance(struct process *handle); extern void do_proc_write(struct process *handle, int fd, const void *buf, size_t len); extern void do_proc_read(struct process *handle, int fd, void *buf, size_t len); extern void do_proc_getcwd(struct process *handle, void *buf, size_t len); extern void do_proc_open(struct process *handle, const char *pathname, int flags, mode_t mode); extern void do_proc_close(struct process *handle, int fd); extern void do_proc_dup(struct process *handle, int fd); extern void do_proc_dup2(struct process *handle, int oldfd, int newfd); extern void do_proc_lseek(struct process *handle, int fd, off_t offset, int whence); extern void do_proc_signal(struct process *handle, int signum, void (*handler)(int)); extern void do_proc_fstat(struct process *handle, int fd, struct stat *buf); extern void do_proc_fcntl(struct process *handle, int fd, int cmd, long arg); #define proc_write(handle, fd, buf, len) case __LINE__: do_proc_write(handle, fd, buf, len); if (handle->again) { handle->sv=__LINE__; return 0; } #define proc_read(handle, fd, buf, len) case __LINE__: do_proc_read(handle, fd, buf, len); if (handle->again) { handle->sv=__LINE__; return 0; } #define proc_getcwd(handle, buf, len) case __LINE__: do_proc_getcwd(handle, buf, len); if (handle->again) { handle->sv=__LINE__; return 0; } #define proc_open(handle, pathname, flags, mode) case __LINE__: do_proc_open(handle, pathname, flags, mode); if (handle->again) { handle->sv=__LINE__; return 0; } #define proc_close(handle, fd) case __LINE__: do_proc_close(handle, fd); if (handle->again) { handle->sv=__LINE__; return 0; } #define proc_dup(handle, fd) case __LINE__: do_proc_dup(handle, fd); if (handle->again) { handle->sv=__LINE__; return 0; } #define proc_dup2(handle, oldfd, newfd) case __LINE__: do_proc_dup2(handle, oldfd, newfd); if (handle->again) { handle->sv=__LINE__; return 0; } #define proc_lseek(handle, fd, offset, whence) case __LINE__: do_proc_lseek(handle, fd, offset, whence); if (handle->again) { handle->sv=__LINE__; return 0; } #define proc_signal(handle, signum, handler) case __LINE__: do_proc_signal(handle, signum, handler); if (handle->again) { handle->sv=__LINE__; return 0; } #define proc_fstat(handle, fd, buf) case __LINE__: do_proc_fstat(handle, fd, buf); if (handle->again) { handle->sv=__LINE__; return 0; } #define proc_fcntl(handle, fd, cmd, arg) case __LINE__: do_proc_fcntl(handle, fd, cmd, arg); if (handle->again) { handle->sv=__LINE__; return 0; } #define PROC_BEGIN(handle) switch(handle->sv) { case 0: do_proc_syncphase(handle); if (handle->again) return 0; #define PROC_ADVANCE(handle) case __LINE__: do_proc_advance(handle); if (handle->again) { handle->sv=__LINE__; return 0; } #define PROC_END(handle) case __LINE__: do_proc_detach(handle); if (handle->again) { handle->sv=__LINE__; return 0; } } return 1; #endif