2017-04-16 02:42:24 +08:00
|
|
|
/* post_fs_data.c - post-fs-data actions
|
|
|
|
*/
|
|
|
|
|
2017-04-17 16:36:49 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2017-04-16 02:42:24 +08:00
|
|
|
#include <unistd.h>
|
2017-04-17 16:36:49 +08:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <linux/loop.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/mount.h>
|
2017-04-16 02:42:24 +08:00
|
|
|
|
2017-04-17 16:36:49 +08:00
|
|
|
#include "magisk.h"
|
2017-04-16 02:42:24 +08:00
|
|
|
#include "utils.h"
|
|
|
|
#include "daemon.h"
|
2017-04-17 16:36:49 +08:00
|
|
|
#include "resetprop.h"
|
|
|
|
|
|
|
|
static char *loopsetup(const char *img) {
|
|
|
|
char device[20];
|
|
|
|
struct loop_info64 info;
|
|
|
|
int i, lfd, ffd;
|
|
|
|
// First get an empty loop device
|
|
|
|
for (i = 0; i <= 7; ++i) {
|
|
|
|
sprintf(device, "/dev/block/loop%d", i);
|
|
|
|
lfd = xopen(device, O_RDWR);
|
|
|
|
if (ioctl(lfd, LOOP_GET_STATUS64, &info) == -1)
|
|
|
|
break;
|
|
|
|
close(lfd);
|
|
|
|
}
|
|
|
|
if (i == 8) return NULL;
|
|
|
|
ffd = xopen(img, O_RDWR);
|
|
|
|
if (ioctl(lfd, LOOP_SET_FD, ffd) == -1)
|
|
|
|
return NULL;
|
|
|
|
return strdup(device);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *mount_image(const char *img, const char *target) {
|
|
|
|
char *device = loopsetup(img);
|
|
|
|
if (device)
|
2017-04-18 19:32:50 +08:00
|
|
|
xmount(device, target, "ext4", 0, NULL);
|
2017-04-17 16:36:49 +08:00
|
|
|
return device;
|
|
|
|
}
|
2017-04-16 02:42:24 +08:00
|
|
|
|
|
|
|
void post_fs_data(int client) {
|
|
|
|
// ack
|
|
|
|
write_int(client, 0);
|
|
|
|
close(client);
|
2017-04-17 16:36:49 +08:00
|
|
|
if (!check_data())
|
|
|
|
goto unblock;
|
|
|
|
|
|
|
|
LOGI("** post-fs-data mode running\n");
|
|
|
|
LOGI("* Mounting magisk.img\n");
|
|
|
|
// Mounting magisk image
|
|
|
|
char *magiskimg = mount_image("/data/magisk.img", "/magisk");
|
|
|
|
free(magiskimg);
|
|
|
|
|
|
|
|
// Start magiskhide if enabled
|
|
|
|
char *hide_prop = getprop("persist.magisk.hide");
|
|
|
|
if (hide_prop) {
|
|
|
|
if (strcmp(hide_prop, "1") == 0)
|
|
|
|
launch_magiskhide(-1);
|
|
|
|
free(hide_prop);
|
|
|
|
}
|
|
|
|
|
|
|
|
unblock:
|
2017-04-16 02:42:24 +08:00
|
|
|
unblock_boot_process();
|
2017-04-17 16:36:49 +08:00
|
|
|
return;
|
2017-04-16 02:42:24 +08:00
|
|
|
}
|