|
|
@@ -0,0 +1,40 @@
|
|
|
+#include <sys/uio.h>
|
|
|
+#include <stdlib.h>
|
|
|
+#include <string.h>
|
|
|
+#include "sandbox.h"
|
|
|
+
|
|
|
+static inline size_t process_vm_read(int pid, struct iovec *local, struct iovec *remote)
|
|
|
+{
|
|
|
+ return process_vm_readv(pid, local, 1, remote, 1, 0);
|
|
|
+}
|
|
|
+
|
|
|
+void *getMem(const struct s_sandboxenv *env, size_t ptr, int *readlen)
|
|
|
+{
|
|
|
+ char *result;
|
|
|
+ int seg = 1;
|
|
|
+ struct iovec local, remote;
|
|
|
+ size_t read;
|
|
|
+
|
|
|
+ local.iov_base = result = (char *) malloc(sizeof(*result) * 2048);
|
|
|
+ local.iov_len = 2048;
|
|
|
+ remote.iov_base = (char *) ptr;
|
|
|
+ remote.iov_len = 2048;
|
|
|
+
|
|
|
+ while (1)
|
|
|
+ {
|
|
|
+ read = process_vm_read(env->child_pid, &local, &remote);
|
|
|
+ if (read < 2048)
|
|
|
+ {
|
|
|
+ ((char*)local.iov_base)[read] = 0;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if ((read = strnlen(local.iov_base, 2048)) < 2048)
|
|
|
+ break;
|
|
|
+ result = realloc(result, (++seg) * 2048);
|
|
|
+ local.iov_base += 2048;
|
|
|
+ }
|
|
|
+ if (readlen)
|
|
|
+ *readlen = (2048 * seg) + read;
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|