Changeset 2513
- Timestamp:
- Jul 1, 2008, 9:43:36 PM (15 years ago)
- Location:
- neercs/trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
neercs/trunk/src/mytrace.c
r2511 r2513 56 56 #define MYCALL_OPEN 0 57 57 #define MYCALL_CLOSE 1 58 #define MYCALL_DUP2 2 59 #define MYCALL_SETPGID 3 60 #define MYCALL_SETSID 4 58 #define MYCALL_WRITE 2 59 #define MYCALL_DUP2 3 60 #define MYCALL_SETPGID 4 61 #define MYCALL_SETSID 5 61 62 62 63 #if defined __x86_64__ … … 70 71 # define RSI rsi 71 72 # define FMT "%016lx" 72 int syscalls64[] = { SYS_open, SYS_close, SYS_dup2, SYS_setpgid, SYS_setsid };73 int syscalls32[] = { 5, 6, 63, 57, 66 };74 73 #else 75 74 # define RAX eax … … 82 81 # define RSI esi 83 82 # define FMT "%08lx" 84 int syscalls32[] = { SYS_open, SYS_close, SYS_dup2, SYS_setpgid, SYS_setsid }; 85 #endif 83 #endif 84 85 #if defined __x86_64__ 86 int syscalls32[] = 87 { 5, 6, 4, 63, 57, 66 }; /* from unistd_32.h on an amd64 system */ 88 int syscalls64[] = 89 #else 90 int syscalls32[] = 91 #endif 92 { SYS_open, SYS_close, SYS_write, SYS_dup2, SYS_setpgid, SYS_setsid }; 86 93 87 94 struct mytrace … … 125 132 } 126 133 127 int mytrace_open(struct mytrace *t, char *path, int mode)134 int mytrace_open(struct mytrace *t, char const *path, int mode) 128 135 { 129 136 #if defined USE_GRAB … … 143 150 return -1; 144 151 145 /* +4 (or 8) because it's truncated on a multiple of 4 (or 8)146 * and we need 1 */147 sprintf(path, "%s", path);148 152 memcpy_into_target(t, regs.RSP, path, size); 149 153 … … 170 174 #if defined USE_GRAB 171 175 return remote_syscall(t->pid, MYCALL_CLOSE, fd, 0, 0); 176 #else 177 errno = ENOSYS; 178 return -1; 179 #endif 180 } 181 182 int mytrace_write(struct mytrace *t, int fd, char const *data, size_t len) 183 { 184 #if defined USE_GRAB 185 struct user_regs_struct regs; 186 char *backup_data; 187 int ret; 188 189 if(ptrace(PTRACE_GETREGS, t->pid, NULL, ®s) < 0) 190 { 191 fprintf(stderr, "PTRACE_GETREGS failed\n"); 192 return errno; 193 } 194 195 backup_data = malloc(len); 196 197 /* Backup the data that we will use */ 198 if(memcpy_from_target(t, backup_data, regs.RSP, len) < 0) 199 return -1; 200 201 memcpy_into_target(t, regs.RSP, data, len); 202 203 ret = remote_syscall(t->pid, MYCALL_WRITE, fd, regs.RSP, len); 204 205 /* Restore the data */ 206 memcpy_into_target(t, regs.RSP, backup_data, len); 207 208 if(ret < 0) 209 { 210 errno = ret; 211 return -1; 212 } 213 214 return ret; 172 215 #else 173 216 errno = ENOSYS; -
neercs/trunk/src/mytrace.h
r2509 r2513 18 18 int mytrace_detach(struct mytrace *t); 19 19 20 int mytrace_open(struct mytrace *t, char *path, int mode); 20 int mytrace_open(struct mytrace *t, char const *path, int mode); 21 int mytrace_write(struct mytrace *t, int fd, char const *data, size_t len); 21 22 int mytrace_close(struct mytrace *t, int fd); 22 23 int mytrace_dup2(struct mytrace *t, int oldfd, int newfd);
Note: See TracChangeset
for help on using the changeset viewer.