Created
May 29, 2020 04:47
-
-
Save Archenoth/43cf79c858925f21684ababe19a1af33 to your computer and use it in GitHub Desktop.
An aarch64 ptrace-based system call intercepter for the Raspberry Pi version of ADOM, allowing you to run it in Termux on Android without it getting SECCOMP killed by the kernel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <errno.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <asm-generic/unistd.h> | |
#include <sys/procfs.h> | |
#include <sys/ptrace.h> | |
#include <sys/types.h> | |
#include <sys/uio.h> | |
#include <sys/user.h> | |
#include <sys/wait.h> | |
#include <elf.h> | |
int main(int argc, char* argv[]){ | |
setenv("TERM", "xterm", 1); | |
setenv("TERMINFO", "/data/data/com.termux/files/usr/share/terminfo", 1); | |
pid_t pid = fork(); | |
if(pid == -1){ | |
fprintf(stderr, "Failed to fork: %s", strerror(errno)); | |
exit(1); | |
} else if (pid == 0){ | |
ptrace(PTRACE_TRACEME, 0, 0, 0); | |
execvp("/data/data/com.termux/files/home/compspace/adom/adom.bin", argv); | |
} | |
waitpid(pid, 0, 0); | |
ptrace(PTRACE_SETOPTIONS, pid, 0, PTRACE_O_EXITKILL); | |
while(1){ | |
ptrace(PTRACE_SYSCALL, pid, 0, 0); | |
if(waitpid(pid, 0, 0) < 1){ | |
exit(0); | |
} | |
struct user_regs_struct regs; | |
struct iovec iovec; | |
iovec.iov_base = ®s; | |
iovec.iov_len = sizeof(regs); | |
ptrace(PTRACE_GETREGSET, pid, NT_ARM_VFP, &iovec); | |
int blocked = 0; | |
if(regs.regs[0] == __NR_setuid){ | |
blocked = 1; | |
regs.regs[0] = -1; | |
ptrace(PTRACE_SETREGSET, pid, 0, ®s); | |
} | |
ptrace(PTRACE_SYSCALL, pid, 0, 0); | |
waitpid(pid, 0, 0); | |
if(blocked){ | |
regs.regs[0] = -EPERM; | |
ptrace(PTRACE_SETREGSET, pid, 0, ®s); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment