From 03c8079858f68a335a9b75b34f4623221750a6fe Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 30 Mar 2017 02:24:16 +0800 Subject: [PATCH] Add --magisk option --- magiskpolicy.h | 2 +- main.c | 21 +++++++++++++++------ rules.c | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/magiskpolicy.h b/magiskpolicy.h index 32e92f4e0..4e5f15586 100644 --- a/magiskpolicy.h +++ b/magiskpolicy.h @@ -63,7 +63,7 @@ void vec_push_back(vector *v, char* s); void vec_destroy(vector *v); // Built in rules -void su_rules(); +void full_rules(); void min_rules(); #endif diff --git a/main.c b/main.c index 814d65b46..2428878a2 100644 --- a/main.c +++ b/main.c @@ -34,9 +34,16 @@ static void statements() { } static void usage(char *arg0) { - fprintf(stderr, "%s [--live] [--minimal] [--load ] [--save ] [policystatement...]\n\n", arg0); - fprintf(stderr, " --live: directly load patched policy to device\n"); - fprintf(stderr, " --minimal: minimal patches for boot image to let Magisk live patch on boot\n"); + fprintf(stderr, + "%s [--options...] [policystatements...]\n\n" + "Options:\n" + " --live: directly load patched policy to device\n" + " --magisk: complete (very large!) patches for Magisk and MagiskSU\n" + " --minimal: minimal patches, used for boot image patches\n" + " --load : load policies from \n" + " (load from current policies if not specified)" + " --save : save policies to \n" + , arg0); statements(); exit(1); } @@ -248,7 +255,7 @@ static void syntax_error_msg() { int main(int argc, char *argv[]) { char *infile = NULL, *outfile = NULL, *tok, *saveptr; - int live = 0, minimal = 0; + int live = 0, minimal = 0, full = 0; struct vector rules; vec_init(&rules); @@ -258,6 +265,8 @@ int main(int argc, char *argv[]) { if (argv[i][0] == '-' && argv[i][1] == '-') { if (strcmp(argv[i], "--live") == 0) live = 1; + else if (strcmp(argv[i], "--magisk") == 0) + full = 1; else if (strcmp(argv[i], "--minimal") == 0) minimal = 1; else if (strcmp(argv[i], "--load") == 0) { @@ -294,8 +303,8 @@ int main(int argc, char *argv[]) { if (policydb_load_isids(&policydb, &sidtab)) return 1; - if (!minimal && rules.size == 0) su_rules(); - if (minimal) min_rules(); + if (full) full_rules(); + else if (minimal) min_rules(); for (int i = 0; i < rules.size; ++i) { // Since strtok will modify the origin string, copy the policy for error messages diff --git a/rules.c b/rules.c index 6d19a427b..65ee3dba0 100644 --- a/rules.c +++ b/rules.c @@ -129,7 +129,7 @@ void otherToSU() { allow("audioserver", "audioserver", "process", "execmem"); } -void su_rules() { +void full_rules() { // Samsung specific // Prevent system from loading policy if(exists("knox_system_app"))