Changeset 2502 for neercs/trunk
- Timestamp:
- Jul 1, 2008, 1:26:17 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
neercs/trunk/src/grab.c
r2501 r2502 63 63 s = (long*) src; 64 64 n /= sizeof(long); 65 for (i = 0; i < n; i++) { 66 d[i] = ptrace(PTRACE_PEEKTEXT, pid, s+i, 0); 67 if (errno) { 65 for(i = 0; i < n; i++) 66 { 67 d[i] = ptrace(PTRACE_PEEKTEXT, pid, s + i, 0); 68 if(errno) 69 { 68 70 perror("ptrace(PTRACE_PEEKTEXT)"); 69 71 return -1; … … 79 81 d = (long*) dest; 80 82 s = (long*) src; 81 for (i = 0; i < n / sizeof(long); i++) { 82 if (ptrace(PTRACE_POKETEXT, pid, d+i, s[i]) == -1) { 83 for(i = 0; i < n / sizeof(long); i++) 84 { 85 if(ptrace(PTRACE_POKETEXT, pid, d + i, s[i]) == -1) 86 { 83 87 perror("ptrace(PTRACE_POKETEXT)"); 84 88 return -1; … … 90 94 static int do_syscall(pid_t pid, struct user_regs_struct *regs) 91 95 { 92 93 96 struct user_regs_struct oregs; 94 97 long oinst; … … 102 105 103 106 oinst = ptrace(PTRACE_PEEKTEXT, pid, regs->RSP, 0); 104 if (errno) { 107 if(errno) 108 { 105 109 fprintf(stderr, "PTRACE_PEEKTEXT failed\n"); 106 110 return errno; 107 111 } 108 112 109 if (ptrace(PTRACE_POKETEXT, pid, regs->RSP, 0x80cd) < 0) { /* int 0x80 */ 113 if(ptrace(PTRACE_POKETEXT, pid, regs->RSP, 0x80cd) < 0) /* int 0x80 */ 114 { 110 115 fprintf(stderr, "PTRACE_POKETEXT failed\n"); 111 116 return errno; … … 135 140 } 136 141 137 if(ptrace(PTRACE_POKETEXT, pid, oregs.RSP -4 , oinst) < 0)142 if(ptrace(PTRACE_POKETEXT, pid, oregs.RSP - 4 , oinst) < 0) 138 143 { 139 144 fprintf(stderr, "PTRACE_POKETEXT failed\n"); … … 180 185 void *backup_page; 181 186 void *target_page = (void*)(0x08048000); 182 size_t size = (1 <<12); /* 4K */187 size_t size = (1 << 12); /* 4K */ 183 188 int ret; 184 189 185 190 /* Backup the page that we will use */ 186 191 backup_page = malloc(size); 187 if 192 if(memcpy_from_target(pid, backup_page, target_page, size) < 0) 188 193 return -1; 189 194 … … 194 199 } 195 200 196 /* +4 because it's tr cuncated on a multiple of 4 and we need 1 */197 memcpy_into_target(pid, target_page, path, strlen(path) +4);201 /* +4 because it's truncated on a multiple of 4 and we need 1 */ 202 memcpy_into_target(pid, target_page, path, strlen(path) + 4); 198 203 199 204 regs.RAX = SYS_open; … … 215 220 } 216 221 217 static int do_setsid(pid_t pid) { 222 static int do_setsid(pid_t pid) 223 { 218 224 struct user_regs_struct regs; 219 225 int ret; … … 236 242 } 237 243 238 if (regs.RAX != 0) { 244 if(regs.RAX != 0) 245 { 239 246 fprintf(stderr, "setpgid failed\n"); 240 247 return -regs.RAX; … … 250 257 debug("pid %d has now sid %d", pid, getsid(pid)); 251 258 252 if (regs.RAX == -1) { 259 if((long int)regs.RAX == -1L) 260 { 253 261 fprintf(stderr, "getsid failed\n"); 254 262 return -regs.RAX; … … 278 286 waitpid(pid, NULL, 0); 279 287 280 for(i =0; i<=2; i++)288 for(i = 0; i <= 2; i++) 281 289 { 282 290 snprintf(fdstr, sizeof(fdstr), "/proc/%d/fd/%d", pid, i); 283 291 to_open[i]=0; 284 292 lstat(fdstr, &stat_buf); 285 if 293 if((stat_buf.st_mode & S_IRUSR) && (stat_buf.st_mode & S_IWUSR)) 286 294 mode = O_RDWR; 287 else if 295 else if(stat_buf.st_mode & S_IWUSR) 288 296 mode = O_WRONLY; 289 297 else 290 298 mode = O_RDONLY; 291 299 292 if 300 if(stat(fdstr, &stat_buf) < 0) 293 301 continue; 294 302 295 if 303 if(!S_ISCHR(stat_buf.st_mode) || MAJOR(stat_buf.st_rdev) != UNIX98_PTY_SLAVE_MAJOR) 296 304 continue; 297 305 … … 309 317 } 310 318 311 for(i =0; i<=2; i++)319 for(i = 0; i <= 2; i++) 312 320 { 313 321 if(!to_open[i])
Note: See TracChangeset
for help on using the changeset viewer.