mirror of
https://github.com/zhaarey/wrapper.git
synced 2025-07-01 23:59:56 +09:00
init
This commit is contained in:
62
wrapper.c
Normal file
62
wrapper.c
Normal file
@ -0,0 +1,62 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <errno.h>
|
||||
#include <sched.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/sysmacros.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
pid_t child_proc = -1;
|
||||
|
||||
static void intHan(int signum) {
|
||||
if (child_proc != -1) {
|
||||
kill(child_proc, SIGKILL);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[], char *envp[]) {
|
||||
if (signal(SIGINT, intHan) == SIG_ERR) {
|
||||
perror("signal");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (argc > 2) {
|
||||
system("rm -r ./rootfs/data/data/com.apple.android.music/files/");
|
||||
}
|
||||
|
||||
if (chdir("./rootfs") != 0) {
|
||||
perror("chdir");
|
||||
return 1;
|
||||
}
|
||||
if (chroot("./") != 0) {
|
||||
perror("chroot");
|
||||
return 1;
|
||||
}
|
||||
mknod("/dev/urandom", S_IFCHR | 0666, makedev(0x1, 0x9));
|
||||
chmod("/system/bin/linker64", 0755);
|
||||
chmod("/system/bin/main", 0755);
|
||||
|
||||
if (unshare(CLONE_NEWPID)) {
|
||||
perror("unshare");
|
||||
return 1;
|
||||
}
|
||||
child_proc = fork();
|
||||
if (child_proc == -1) {
|
||||
perror("fork");
|
||||
return 1;
|
||||
}
|
||||
if (child_proc > 0) {
|
||||
close(STDOUT_FILENO);
|
||||
wait(NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
mkdir("/data/data/com.apple.android.music/files", 0777);
|
||||
mkdir("/data/data/com.apple.android.music/files/mpl_db", 0777);
|
||||
execve("/system/bin/main", argv, envp);
|
||||
perror("execve");
|
||||
return 1;
|
||||
}
|
Reference in New Issue
Block a user