static int handle_mmap(Tracee *tracee, ExtensionEvent event)
{
int status;
word_t flags;
char path[PATH_MAX];
char final_path[PATH_MAX];
switch (event) {
case SYSCALL_ENTER_START: {
switch (get_sysnum(tracee, ORIGINAL)) {
case PR_mmap:
case PR_mmap2:
flags = peek_reg(tracee, ORIGINAL, SYSARG_4);
if ((flags & MAP_ANONYMOUS) != 0)
break;
status = readlink_proc_pid_fd(tracee->pid, peek_reg(tracee, ORIGINAL, SYSARG_5), path);
if (status < 0)
return status;
status = copy_executable(tracee, path, final_path);
if (status <= 0)
return status;
/* Replace mmap(2) with open(2). */
set_sysnum(tracee, PR_open);
set_sysarg_path(tracee, final_path, SYSARG_1);
poke_reg(tracee, SYSARG_2, O_RDWR);
poke_reg(tracee, SYSARG_3, 0);
/* Chain this substituted syscall with mmap(2). Use -1 for fd
* since its value is not known as of now (this will be the
* result of the preceding open(2). */
register_chained_syscall(tracee, PR_mmap2, peek_reg(tracee, ORIGINAL, SYSARG_1), peek_reg(tracee, ORIGINAL, SYSARG_2), peek_reg(tracee, ORIGINAL, SYSARG_3), peek_reg(tracee, ORIGINAL, SYSARG_4), -1, peek_reg(tracee, ORIGINAL, SYSARG_6));
/* Don't leak the temporary file descriptor (same remark about
* fd == -1). */
register_chained_syscall(tracee, PR_close, -1, 0, 0, 0, 0, 0);
break;
default:
break;
}
return 0;
}
case SYSCALL_CHAINED_ENTER: {
switch (get_sysnum(tracee, CURRENT)) {
case PR_mmap:
case PR_mmap2:
/* Replace the fd placeholder with the result of the preceding
* open(2). */
poke_reg(tracee, SYSARG_5, temporary_fd);
break;
case PR_close:
/* Replace the fd placeholder with the result of the preceding
* open(2). */
poke_reg(tracee, SYSARG_1, temporary_fd);
break;
default:
break;
}
return 0;
}
case SYSCALL_CHAINED_EXIT: {
switch (get_sysnum(tracee, CURRENT)) {
case PR_open:
//save off result of open
temporary_fd = peek_reg(tracee, CURRENT, SYSARG_RESULT);
break;
case PR_mmap:
case PR_mmap2:
/* The return value of this chain of syscall is now known. */
force_chain_final_result(tracee, peek_reg(tracee, CURRENT, SYSARG_RESULT));
break;
default:
break;
}
return 0;
}
default:
return 0;
}
}
proot info: pid 7892: sysenter start: mmap2(0x0, 0x20880, 0x5, 0x802, 0x3, 0x0) = 0x0 [0xbe9f0ed8, 0]handle_mmap path: /storage/emulated/0/GNURoot/debian/2231/6139copy_executable:proot info: pid 7892: translate("/" + "/noexec/")proot info: pid 7892: -> "/storage/emulated/0/GNURoot/debian/"proot info: pid 7892: translate("/" + "/meta/2231/6139")proot info: pid 7892: -> "/data/data/com.gnuroot.debian/debian/meta/2231/6139"copy_executable meta_path: /data/data/com.gnuroot.debian/debian/meta/2231/6139proot info: pid 7892: translate("/" + "/data/data/com.gnuroot.debian/debian/lib/arm-linux-gnueabihf/libtinfo.so.5.9")proot info: pid 7892: -> "/data/data/com.gnuroot.debian/debian/lib/arm-linux-gnueabihf/libtinfo.so.5.9"copy_executable final_path: /data/data/com.gnuroot.debian/debian/lib/arm-linux-gnueabihf/libtinfo.so.5.9copy_executable done copyingproot info: pid 7892: sysenter end: open(0xbe9f0e8b, 0x2, 0x0, 0x802, 0x3, 0x0) = 0xbe9f0e8b [0xbe9f0e8b, 0]proot info: pid 7892: sysexit start: open(0x7, 0x2, 0x0, 0x802, 0x3, 0x0) = 0x7 [0xbe9f0e8b, 0]chained file handle path: /data/data/com.gnuroot.debian/debian/lib/arm-linux-gnueabihf/libtinfo.so.5.9proot info: pid 7892: sysexit end: mmap2(0x0, 0x20880, 0x5, 0x802, 0xffffffff, 0x0) = 0x0 [0xbe9f0e8b, 0]proot info: pid 7892: sysenter start: mmap2(0x0, 0x20880, 0x5, 0x802, 0xffffffff, 0x0) = 0x0 [0xbe9f0e8b, 0]proot info: pid 7892: sysenter end: mmap2(0x0, 0x20880, 0x5, 0x802, 0x7, 0x0) = 0x0 [0xbe9f0e8b, 0]proot info: pid 7892: sysexit start: mmap2(0xfffffff7, 0x20880, 0x5, 0x802, 0x7, 0x0) = 0xfffffff7 [0xbe9f0e8b, 0]proot info: pid 7892: sysexit end: close(0xffffffff, 0x0, 0x0, 0x0, 0x0, 0x0) = 0xffffffff [0xbe9f0e8b, 0]proot info: pid 7892: sysenter start: close(0xffffffff, 0x0, 0x0, 0x0, 0x0, 0x0) = 0xffffffff [0xbe9f0e8b, 0]proot info: pid 7892: sysenter end: close(0x7, 0x0, 0x0, 0x0, 0x0, 0x0) = 0x7 [0xbe9f0e8b, 0]proot info: pid 7892: sysexit start: close(0x0, 0x0, 0x0, 0x0, 0x0, 0x0) = 0x0 [0xbe9f0e8b, 0]proot info: pid 7892: sysexit end: mmap2(0xfffffff7, 0x20880, 0x5, 0x802, 0x3, 0x0) = 0xfffffff7 [0xbe9f0ed8, 0]