Index: /neercs/trunk/src/mytrace.c
===================================================================
--- /neercs/trunk/src/mytrace.c	(revision 2512)
+++ /neercs/trunk/src/mytrace.c	(revision 2513)
@@ -56,7 +56,8 @@
 #define MYCALL_OPEN     0
 #define MYCALL_CLOSE    1
-#define MYCALL_DUP2     2
-#define MYCALL_SETPGID  3
-#define MYCALL_SETSID   4
+#define MYCALL_WRITE    2
+#define MYCALL_DUP2     3
+#define MYCALL_SETPGID  4
+#define MYCALL_SETSID   5
 
 #if defined __x86_64__
@@ -70,6 +71,4 @@
 #   define RSI rsi
 #   define FMT "%016lx"
-int syscalls64[] = { SYS_open, SYS_close, SYS_dup2, SYS_setpgid, SYS_setsid };
-int syscalls32[] = { 5, 6, 63, 57, 66 };
 #else
 #   define RAX eax
@@ -82,6 +81,14 @@
 #   define RSI esi
 #   define FMT "%08lx"
-int syscalls32[] = { SYS_open, SYS_close, SYS_dup2, SYS_setpgid, SYS_setsid };
-#endif
+#endif
+
+#if defined __x86_64__
+int syscalls32[] =
+    { 5, 6, 4, 63, 57, 66 }; /* from unistd_32.h on an amd64 system */
+int syscalls64[] =
+#else
+int syscalls32[] =
+#endif
+    { SYS_open, SYS_close, SYS_write, SYS_dup2, SYS_setpgid, SYS_setsid };
 
 struct mytrace
@@ -125,5 +132,5 @@
 }
 
-int mytrace_open(struct mytrace *t, char *path, int mode)
+int mytrace_open(struct mytrace *t, char const *path, int mode)
 {
 #if defined USE_GRAB
@@ -143,7 +150,4 @@
         return -1;
 
-    /* +4 (or 8) because it's truncated on a multiple of 4 (or 8)
-     * and we need 1 */
-    sprintf(path, "%s", path);
     memcpy_into_target(t, regs.RSP, path, size);
 
@@ -170,4 +174,43 @@
 #if defined USE_GRAB
     return remote_syscall(t->pid, MYCALL_CLOSE, fd, 0, 0);
+#else
+    errno = ENOSYS;
+    return -1;
+#endif
+}
+
+int mytrace_write(struct mytrace *t, int fd, char const *data, size_t len)
+{
+#if defined USE_GRAB
+    struct user_regs_struct regs;
+    char *backup_data;
+    int ret;
+
+    if(ptrace(PTRACE_GETREGS, t->pid, NULL, &regs) < 0)
+    {
+        fprintf(stderr, "PTRACE_GETREGS failed\n");
+        return errno;
+    }
+
+    backup_data = malloc(len);
+
+    /* Backup the data that we will use */
+    if(memcpy_from_target(t, backup_data, regs.RSP, len) < 0)
+        return -1;
+
+    memcpy_into_target(t, regs.RSP, data, len);
+
+    ret = remote_syscall(t->pid, MYCALL_WRITE, fd, regs.RSP, len);
+
+    /* Restore the data */
+    memcpy_into_target(t, regs.RSP, backup_data, len);
+
+    if(ret < 0)
+    {
+        errno = ret;
+        return -1;
+    }
+
+    return ret;
 #else
     errno = ENOSYS;
Index: /neercs/trunk/src/mytrace.h
===================================================================
--- /neercs/trunk/src/mytrace.h	(revision 2512)
+++ /neercs/trunk/src/mytrace.h	(revision 2513)
@@ -18,5 +18,6 @@
 int mytrace_detach(struct mytrace *t);
 
-int mytrace_open(struct mytrace *t, char *path, int mode);
+int mytrace_open(struct mytrace *t, char const *path, int mode);
+int mytrace_write(struct mytrace *t, int fd, char const *data, size_t len);
 int mytrace_close(struct mytrace *t, int fd);
 int mytrace_dup2(struct mytrace *t, int oldfd, int newfd);
