89 lines
1.8 KiB
C
Raw Normal View History

2019-05-27 00:29:43 -07:00
#include <stdlib.h>
struct cmdline {
bool system_as_root;
char slot[3];
char dt_dir[128];
};
struct raw_data {
void *buf;
size_t sz;
};
2019-06-16 12:45:32 -07:00
class BaseInit {
protected:
2019-06-15 22:25:09 -07:00
cmdline *cmd;
2019-05-27 00:29:43 -07:00
char **argv;
2019-06-22 03:14:33 -07:00
void re_exec_init();
virtual void cleanup();
public:
BaseInit(char *argv[], cmdline *cmd) : cmd(cmd), argv(argv) {}
virtual ~BaseInit() = default;
virtual void start() = 0;
};
class MagiskInit : public BaseInit {
protected:
raw_data self{};
2019-05-27 00:29:43 -07:00
bool mnt_system = false;
bool mnt_vendor = false;
bool mnt_product = false;
bool mnt_odm = false;
2019-06-22 03:14:33 -07:00
virtual void early_mount() = 0;
2019-05-27 02:55:46 -07:00
bool read_dt_fstab(const char *name, char *partname, char *fstype);
2019-06-25 21:34:02 -07:00
bool patch_sepolicy(const char *file = "/sepolicy");
2019-06-22 03:14:33 -07:00
void cleanup() override;
2019-05-27 00:29:43 -07:00
public:
2019-06-22 03:14:33 -07:00
MagiskInit(char *argv[], cmdline *cmd) : BaseInit(argv, cmd) {};
};
class SARInit : public MagiskInit {
protected:
2019-06-24 01:21:33 -07:00
raw_data config{};
dev_t system_dev;
void early_mount() override;
2019-06-24 01:21:33 -07:00
void patch_rootdir();
public:
SARInit(char *argv[], cmdline *cmd) : MagiskInit(argv, cmd) {};
void start() override;
};
class RootFSInit : public MagiskInit {
protected:
2019-06-24 01:50:47 -07:00
int root = -1;
virtual void setup_rootfs();
public:
RootFSInit(char *argv[], cmdline *cmd) : MagiskInit(argv, cmd) {};
2019-06-22 03:14:33 -07:00
void start() override;
2019-06-16 12:45:32 -07:00
};
class LegacyInit : public RootFSInit {
2019-06-16 12:45:32 -07:00
protected:
void early_mount() override;
public:
LegacyInit(char *argv[], cmdline *cmd) : RootFSInit(argv, cmd) {};
2019-06-16 12:45:32 -07:00
};
class SARCompatInit : public RootFSInit {
2019-06-16 12:45:32 -07:00
protected:
void early_mount() override;
2019-06-24 01:50:47 -07:00
void setup_rootfs() override;
2019-06-16 12:45:32 -07:00
public:
SARCompatInit(char *argv[], cmdline *cmd) : RootFSInit(argv, cmd) {};
2019-05-27 00:29:43 -07:00
};
static inline bool is_lnk(const char *name) {
struct stat st;
if (lstat(name, &st))
return false;
return S_ISLNK(st.st_mode);
}
2019-06-15 22:25:09 -07:00
void load_kernel_info(cmdline *cmd);
2019-05-27 00:29:43 -07:00
int dump_magisk(const char *path, mode_t mode);
2019-06-22 03:14:33 -07:00
int magisk_proxy_main(int argc, char *argv[]);