Ignore:
Timestamp:
Jul 1, 2008 9:43:36 PM (6 years ago)
Author:
sam
Message:
  • Add write() to the list of supported remote syscalls.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • neercs/trunk/src/mytrace.c

    r2511 r2513  
    5656#define MYCALL_OPEN     0
    5757#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
    6162
    6263#if defined __x86_64__
     
    7071#   define RSI rsi
    7172#   define FMT "%016lx"
    72 int syscalls64[] = { SYS_open, SYS_close, SYS_dup2, SYS_setpgid, SYS_setsid };
    73 int syscalls32[] = { 5, 6, 63, 57, 66 };
    7473#else
    7574#   define RAX eax
     
    8281#   define RSI esi
    8382#   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__
     86int syscalls32[] =
     87    { 5, 6, 4, 63, 57, 66 }; /* from unistd_32.h on an amd64 system */
     88int syscalls64[] =
     89#else
     90int syscalls32[] =
     91#endif
     92    { SYS_open, SYS_close, SYS_write, SYS_dup2, SYS_setpgid, SYS_setsid };
    8693
    8794struct mytrace
     
    125132}
    126133
    127 int mytrace_open(struct mytrace *t, char *path, int mode)
     134int mytrace_open(struct mytrace *t, char const *path, int mode)
    128135{
    129136#if defined USE_GRAB
     
    143150        return -1;
    144151
    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);
    148152    memcpy_into_target(t, regs.RSP, path, size);
    149153
     
    170174#if defined USE_GRAB
    171175    return remote_syscall(t->pid, MYCALL_CLOSE, fd, 0, 0);
     176#else
     177    errno = ENOSYS;
     178    return -1;
     179#endif
     180}
     181
     182int 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, &regs) < 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;
    172215#else
    173216    errno = ENOSYS;
Note: See TracChangeset for help on using the changeset viewer.