Changeset 2906
- Timestamp:
- Oct 10, 2008, 12:24:51 AM (14 years ago)
- Location:
- neercs/trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
neercs/trunk/src/grab.c
r2785 r2906 40 40 char fdstr[1024]; 41 41 struct mytrace *parent, *child; 42 int i, fd = 0, mode,ret;42 int i, fd = 0, ret; 43 43 char to_open[3]; 44 int mode[3]; 44 45 struct stat stat_buf; 46 struct termios tos; 45 47 46 48 debug("pty is %s", ptyname); … … 54 56 55 57 child = mytrace_fork(parent); 56 mytrace_write(parent, 1, "\x1b]0;\x07", 5); 57 mytrace_write(parent, 1, "\x1b[1000l", 7); 58 mytrace_write(parent, 1, "\x1b[?12l\x1b[?25h", 12); 58 mytrace_write(parent, 1, "\x1b[H\x1b[2J", 7); 59 59 mytrace_write(parent, 1, "\n[Process stolen by neercs]\n", 28); 60 /* FIXME Reset the term */ 60 mytrace_tcgets(parent, 1, &tos); 61 tos.c_lflag |= ICANON|ECHO; 62 mytrace_tcsets(parent, 1, &tos); 61 63 mytrace_close(parent, 1); 62 63 64 mytrace_exit(parent, 0); 64 65 mytrace_detach(parent); … … 72 73 lstat(fdstr, &stat_buf); 73 74 if((stat_buf.st_mode & S_IRUSR) && (stat_buf.st_mode & S_IWUSR)) 74 mode = O_RDWR;75 mode[i] = O_RDWR; 75 76 else if(stat_buf.st_mode & S_IWUSR) 76 mode = O_WRONLY;77 mode[i] = O_WRONLY; 77 78 else 78 mode = O_RDONLY;79 mode[i] = O_RDONLY; 79 80 80 81 if(stat(fdstr, &stat_buf) < 0) … … 128 129 if(!to_open[i]) 129 130 continue; 130 fd = mytrace_open(child, ptyname, mode );131 fd = mytrace_open(child, ptyname, mode[i]); 131 132 if(fd < 0) 132 133 { -
neercs/trunk/src/mytrace.c
r2786 r2906 165 165 #define MYCALL_FORK 7 166 166 #define MYCALL_EXIT 8 167 #define MYCALL_IOCTL 9 167 168 168 169 #if defined __x86_64__ 169 170 /* from unistd_32.h on an amd64 system */ 170 int syscalls32[] = { 5, 6, 4, 63, 57, 66, 37, 2, 1 };171 int syscalls32[] = { 5, 6, 4, 63, 57, 66, 37, 2, 1, 54 }; 171 172 int syscalls64[] = 172 173 #else … … 174 175 #endif 175 176 { SYS_open, SYS_close, SYS_write, SYS_dup2, SYS_setpgid, SYS_setsid, 176 SYS_kill, SYS_fork, SYS_exit };177 SYS_kill, SYS_fork, SYS_exit, SYS_ioctl }; 177 178 178 179 char const *syscallnames[] = 179 180 { "open", "close", "write", "dup2", "setpgid", "setsid", "kill", "fork", 180 "exit" };181 "exit", "ioctl" }; 181 182 182 183 struct mytrace … … 394 395 ptrace(PTRACE_SETOPTIONS, t->pid, NULL, PTRACE_O_TRACEEXIT); 395 396 return remote_syscall(t, MYCALL_EXIT, status, 0, 0); 397 #else 398 errno = ENOSYS; 399 return -1; 400 #endif 401 } 402 403 int mytrace_tcgets(struct mytrace *t, int fd, struct termios *tos) 404 { 405 #if defined USE_GRAB 406 struct user_regs_struct regs; 407 struct termios mytos; 408 int ret; 409 410 if(ptrace(PTRACE_GETREGS, t->pid, NULL, ®s) < 0) 411 { 412 fprintf(stderr, "PTRACE_GETREGS failed\n"); 413 return errno; 414 } 415 416 /* Backup the data that we will use */ 417 if(memcpy_from_target(t, (char *)&mytos, regs.RSP, sizeof(struct termios)) < 0) 418 return -1; 419 420 ret = remote_syscall(t, MYCALL_IOCTL, fd, TCGETS, regs.RSP); 421 422 memcpy_from_target(t, (char *)tos, regs.RSP, sizeof(struct termios)); 423 424 /* Restore the data */ 425 memcpy_into_target(t, regs.RSP, (char *)&mytos, sizeof(struct termios)); 426 427 if(ret < 0) 428 { 429 errno = ret; 430 return -1; 431 } 432 433 return ret; 434 #else 435 errno = ENOSYS; 436 return -1; 437 #endif 438 } 439 440 int mytrace_tcsets(struct mytrace *t, int fd, struct termios *tos) 441 { 442 #if defined USE_GRAB 443 struct user_regs_struct regs; 444 struct termios mytos; 445 int ret; 446 447 if(ptrace(PTRACE_GETREGS, t->pid, NULL, ®s) < 0) 448 { 449 fprintf(stderr, "PTRACE_GETREGS failed\n"); 450 return errno; 451 } 452 453 /* Backup the data that we will use */ 454 if(memcpy_from_target(t, (char *)&mytos, regs.RSP, sizeof(struct termios)) < 0) 455 return -1; 456 457 memcpy_into_target(t, regs.RSP, (char *)tos, sizeof(struct termios)); 458 459 ret = remote_syscall(t, MYCALL_IOCTL, fd, TCSETS, regs.RSP); 460 461 /* Restore the data */ 462 memcpy_into_target(t, regs.RSP, (char *)&mytos, sizeof(struct termios)); 463 464 if(ret < 0) 465 { 466 errno = ret; 467 return -1; 468 } 469 470 return ret; 396 471 #else 397 472 errno = ENOSYS; -
neercs/trunk/src/mytrace.h
r2516 r2906 12 12 * http://sam.zoy.org/wtfpl/COPYING for more details. 13 13 */ 14 15 #include <termios.h> 14 16 15 17 struct mytrace; … … 28 30 int mytrace_kill(struct mytrace *t, long pid, int sig); 29 31 int mytrace_exit(struct mytrace *t, int status); 30 32 int mytrace_tcgets(struct mytrace *t, int fd, struct termios *tos); 33 int mytrace_tcsets(struct mytrace *t, int fd, struct termios *tos);
Note: See TracChangeset
for help on using the changeset viewer.