diff --git a/.gitmodules b/.gitmodules index 994fc319b..160402b49 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,6 @@ [submodule "MagiskManager"] path = MagiskManager url = https://github.com/topjohnwu/MagiskManager.git +[submodule "jni/busybox"] + path = jni/busybox + url = https://github.com/topjohnwu/ndk-busybox.git diff --git a/build.py b/build.py index 7b1a5f151..6ff304bf8 100755 --- a/build.py +++ b/build.py @@ -58,7 +58,7 @@ def build_binary(args): header('* Building Magisk binaries') ndk_build = os.path.join(os.environ['ANDROID_HOME'], 'ndk-bundle', 'ndk-build') - debug_flag = '' if args.release else '-DDEBUG' + debug_flag = '' if args.release else '-DMAGISK_DEBUG' proc = subprocess.run('{} APP_CFLAGS=\"-DMAGISK_VERSION=\\\"{}\\\" -DMAGISK_VER_CODE={} {}\" -j{}'.format( ndk_build, args.versionString, args.versionCode, debug_flag, multiprocessing.cpu_count()), shell=True) if proc.returncode != 0: @@ -113,8 +113,8 @@ def sign_adjust_zip(unsigned, output): header('* Signing / Adjusting Zip') # Unsigned->signed - proc = subprocess.run(['java', '-jar', os.path.join('ziptools', 'signapk.jar'), - os.path.join('ziptools', 'test.certificate.x509.pem'), + proc = subprocess.run(['java', '-jar', os.path.join('ziptools', 'signapk.jar'), + os.path.join('ziptools', 'test.certificate.x509.pem'), os.path.join('ziptools', 'test.key.pk8'), unsigned, 'tmp_signed.zip']) if proc.returncode != 0: error('First sign flashable zip failed!') @@ -131,8 +131,8 @@ def sign_adjust_zip(unsigned, output): error('Adjust flashable zip failed!') # Adjusted -> output - proc = subprocess.run(['java', '-jar', os.path.join('ziptools', 'minsignapk.jar'), - os.path.join('ziptools', 'test.certificate.x509.pem'), + proc = subprocess.run(['java', '-jar', os.path.join('ziptools', 'minsignapk.jar'), + os.path.join('ziptools', 'test.certificate.x509.pem'), os.path.join('ziptools', 'test.key.pk8'), 'tmp_adjusted.zip', output]) if proc.returncode != 0: error('Second sign flashable zip failed!') diff --git a/jni/Android.mk b/jni/Android.mk index 43dfe1582..a629bb132 100644 --- a/jni/Android.mk +++ b/jni/Android.mk @@ -39,6 +39,7 @@ LOCAL_SRC_FILES := \ su/su_socket.c LOCAL_CFLAGS := -Wno-implicit-exception-spec-mismatch +LOCAL_CPPFLAGS := -std=c++11 LOCAL_LDLIBS := -llog include $(BUILD_EXECUTABLE) @@ -51,3 +52,10 @@ include jni/selinux/libsepol/Android.mk # Build magiskboot include jni/magiskboot/Android.mk + +# Build busybox (32-bit only) +ifneq ($(TARGET_ARCH_ABI), x86_64) +ifneq ($(TARGET_ARCH_ABI), arm64-v8a) +include jni/busybox/Android.mk +endif +endif diff --git a/jni/Application.mk b/jni/Application.mk index 52d77327c..29ed9d379 100644 --- a/jni/Application.mk +++ b/jni/Application.mk @@ -1,4 +1,2 @@ APP_ABI := x86 x86_64 armeabi-v7a arm64-v8a APP_PLATFORM := android-21 -APP_UNIFIED_HEADERS := true -APP_CPPFLAGS += -std=c++11 diff --git a/jni/busybox b/jni/busybox new file mode 160000 index 000000000..2178671c6 --- /dev/null +++ b/jni/busybox @@ -0,0 +1 @@ +Subproject commit 2178671c6ef5322f2695cb0ee56df4195d8218ae diff --git a/jni/daemon/bootstages.c b/jni/daemon/bootstages.c index 733d859ea..1886ab4ec 100644 --- a/jni/daemon/bootstages.c +++ b/jni/daemon/bootstages.c @@ -25,7 +25,7 @@ static char *buf, *buf2; static struct vector module_list; -#ifdef DEBUG +#ifdef MAGISK_DEBUG static int debug_log_pid, debug_log_fd; #endif @@ -69,7 +69,7 @@ static int merge_img(const char *source, const char *target) { rename(source, target); return 0; } - + // resize target to worst case int s_used, s_total, t_used, t_total, n_total; get_img_size(source, &s_used, &s_total); @@ -261,7 +261,7 @@ static void construct_tree(const char *module, struct node_entry *parent) { * 1. File in module is a symlink * 2. Target file do not exist * 3. Target file is a symlink, but not /system/vendor - */ + */ int clone = 0; if (IS_LNK(node) || access(buf, F_OK) == -1) { clone = 1; @@ -296,7 +296,7 @@ static void construct_tree(const char *module, struct node_entry *parent) { construct_tree(module, node); } } - + closedir(dir); cleanup: @@ -484,7 +484,7 @@ void post_fs_data(int client) { if (!check_data()) goto unblock; -#ifdef DEBUG +#ifdef MAGISK_DEBUG // Start debug logs in new process debug_log_fd = xopen(DEBUG_LOG, O_WRONLY | O_CREAT | O_CLOEXEC | O_TRUNC, 0644); char *const command[] = { "logcat", "-v", "brief", NULL }; @@ -751,7 +751,7 @@ void late_start(int client) { if (access(MANAGERAPK, F_OK) == 0) { while (1) { sleep(5); - char *const command[] = { "sh", "-c", + char *const command[] = { "sh", "-c", "CLASSPATH=/system/framework/pm.jar " "/system/bin/app_process /system/bin " "com.android.commands.pm.Pm install -r " MANAGERAPK, NULL }; @@ -773,7 +773,7 @@ void late_start(int client) { buf = buf2 = NULL; vec_deep_destroy(&module_list); -#ifdef DEBUG +#ifdef MAGISK_DEBUG // Stop recording the boot logcat after every boot task is done kill(debug_log_pid, SIGTERM); waitpid(debug_log_pid, NULL, 0); diff --git a/jni/include/magisk.h b/jni/include/magisk.h index 510d51a3b..3b4f5ca44 100644 --- a/jni/include/magisk.h +++ b/jni/include/magisk.h @@ -58,7 +58,7 @@ static inline void do_nothing() {} // Dummy function to depress debug message static inline void stub(const char *fmt, ...) {} -#ifdef DEBUG +#ifdef MAGISK_DEBUG #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__) #else #define LOGD(...) stub(__VA_ARGS__)