diff --git a/native/jni/core/applets.cpp b/native/jni/core/applets.cpp index a6a815830..ec3a06668 100644 --- a/native/jni/core/applets.cpp +++ b/native/jni/core/applets.cpp @@ -1,6 +1,4 @@ #include -#include -#include #include #include diff --git a/native/jni/core/bootstages.cpp b/native/jni/core/bootstages.cpp index 200503612..aedffb6e2 100644 --- a/native/jni/core/bootstages.cpp +++ b/native/jni/core/bootstages.cpp @@ -13,6 +13,8 @@ #include #include +#include "core.hpp" + using namespace std; static bool safe_mode = false; @@ -320,7 +322,7 @@ void post_fs_data(int client) { stop_magiskhide(); } else { exec_common_scripts("post-fs-data"); - auto_start_magiskhide(); + auto_start_magiskhide(false); handle_modules(); } @@ -369,7 +371,7 @@ void boot_complete(int client) { if (access(SECURE_DIR, F_OK) != 0) xmkdir(SECURE_DIR, 0700); - auto_start_magiskhide(); + auto_start_magiskhide(true); if (!check_manager()) { if (access(MANAGERAPK, F_OK) == 0) { diff --git a/native/jni/core/core.hpp b/native/jni/core/core.hpp new file mode 100644 index 000000000..538209d27 --- /dev/null +++ b/native/jni/core/core.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include +#include + +extern bool RECOVERY_MODE; +extern int DAEMON_STATE; + +void unlock_blocks(); +void reboot(); +void setup_logfile(bool reset); + +// Module stuffs +void handle_modules(); +void magic_mount(); +void disable_modules(); +void remove_modules(); +void exec_module_scripts(const char *stage); + +// Scripting +void exec_script(const char *script); +void exec_common_scripts(const char *stage); +void exec_module_scripts(const char *stage, const std::vector &module_list); +void install_apk(const char *apk); +[[noreturn]] void install_module(const char *file); + diff --git a/native/jni/core/daemon.cpp b/native/jni/core/daemon.cpp index e89efcd26..e70f9e291 100644 --- a/native/jni/core/daemon.cpp +++ b/native/jni/core/daemon.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include #include @@ -16,11 +16,14 @@ #include #include +#include "core.hpp" + using namespace std; int SDK_INT = -1; -bool RECOVERY_MODE = false; string MAGISKTMP; + +bool RECOVERY_MODE = false; int DAEMON_STATE = STATE_NONE; static struct stat self_st; diff --git a/native/jni/core/db.cpp b/native/jni/core/db.cpp index 8694e690b..ab963b523 100644 --- a/native/jni/core/db.cpp +++ b/native/jni/core/db.cpp @@ -1,14 +1,10 @@ -#include -#include -#include -#include #include #include #include #include #include -#include +#include #include #define DB_VERSION 10 diff --git a/native/jni/core/magisk.cpp b/native/jni/core/magisk.cpp index 15254dead..3246a2d5d 100644 --- a/native/jni/core/magisk.cpp +++ b/native/jni/core/magisk.cpp @@ -7,6 +7,8 @@ #include #include +#include "core.hpp" + using namespace std; [[noreturn]] static void usage() { diff --git a/native/jni/core/module.cpp b/native/jni/core/module.cpp index 1811f5679..30eb1b797 100644 --- a/native/jni/core/module.cpp +++ b/native/jni/core/module.cpp @@ -5,9 +5,10 @@ #include #include #include -#include #include +#include "core.hpp" + using namespace std; #define VLOGD(tag, from, to) LOGD("%-8s: %s <- %s\n", tag, to, from) diff --git a/native/jni/core/restorecon.cpp b/native/jni/core/restorecon.cpp index e2efabdc3..ffd2f5bee 100644 --- a/native/jni/core/restorecon.cpp +++ b/native/jni/core/restorecon.cpp @@ -1,7 +1,6 @@ #include #include -#include #include #include diff --git a/native/jni/core/scripting.cpp b/native/jni/core/scripting.cpp index 3a6536315..dc3dcbd38 100644 --- a/native/jni/core/scripting.cpp +++ b/native/jni/core/scripting.cpp @@ -6,6 +6,8 @@ #include #include +#include "core.hpp" + using namespace std; #define BBEXEC_CMD bbpath(), "sh" diff --git a/native/jni/core/socket.cpp b/native/jni/core/socket.cpp index 529066204..ec9523f72 100644 --- a/native/jni/core/socket.cpp +++ b/native/jni/core/socket.cpp @@ -1,5 +1,3 @@ -#include -#include #include #include diff --git a/native/jni/include/daemon.hpp b/native/jni/include/daemon.hpp index 6a58f01fb..c6a42a765 100644 --- a/native/jni/include/daemon.hpp +++ b/native/jni/include/daemon.hpp @@ -2,7 +2,6 @@ #include #include -#include #include @@ -39,10 +38,7 @@ enum { STATE_BOOT_COMPLETE }; -extern int SDK_INT; -extern bool RECOVERY_MODE; -extern int DAEMON_STATE; -#define APP_DATA_DIR (SDK_INT >= 24 ? "/data/user_de" : "/data/user") +int connect_daemon(bool create = false); // Daemon handlers void post_fs_data(int client); @@ -51,26 +47,6 @@ void boot_complete(int client); void magiskhide_handler(int client); void su_daemon_handler(int client, ucred *credential); -// Misc -int connect_daemon(bool create = false); -void unlock_blocks(); -void reboot(); -void setup_logfile(bool reset); - -// Module stuffs -void handle_modules(); -void magic_mount(); -void disable_modules(); -void remove_modules(); -void exec_module_scripts(const char *stage); - // MagiskHide -void auto_start_magiskhide(); +void auto_start_magiskhide(bool late_props); int stop_magiskhide(); - -// Scripting -void exec_script(const char *script); -void exec_common_scripts(const char *stage); -void exec_module_scripts(const char *stage, const std::vector &module_list); -void install_apk(const char *apk); -[[noreturn]] void install_module(const char *file); diff --git a/native/jni/include/magisk.hpp b/native/jni/include/magisk.hpp index 7ad234dd4..f954f10ef 100644 --- a/native/jni/include/magisk.hpp +++ b/native/jni/include/magisk.hpp @@ -30,6 +30,9 @@ constexpr const char *init_applet[] = { "magiskpolicy", "supolicy", nullptr }; #define POST_FS_DATA_WAIT_TIME 40 #define POST_FS_DATA_SCRIPT_MAX_TIME 35 +extern int SDK_INT; +#define APP_DATA_DIR (SDK_INT >= 24 ? "/data/user_de" : "/data/user") + // Multi-call entrypoints int magisk_main(int argc, char *argv[]); int magiskhide_main(int argc, char *argv[]); diff --git a/native/jni/magiskhide/hide_utils.cpp b/native/jni/magiskhide/hide_utils.cpp index 7c4d5f6d3..56f073985 100644 --- a/native/jni/magiskhide/hide_utils.cpp +++ b/native/jni/magiskhide/hide_utils.cpp @@ -267,7 +267,7 @@ static void update_hide_config() { db_err(err); } -int launch_magiskhide() { +int launch_magiskhide(bool late_props) { mutex_guard g(hide_state_lock); if (SDK_INT < 19) @@ -289,7 +289,7 @@ int launch_magiskhide() { return DAEMON_ERROR; hide_sensitive_props(); - if (DAEMON_STATE >= STATE_BOOT_COMPLETE || DAEMON_STATE == STATE_NONE) + if (late_props) hide_late_sensitive_props(); #if ENABLE_PTRACE_MONITOR @@ -320,7 +320,7 @@ int stop_magiskhide() { return DAEMON_SUCCESS; } -void auto_start_magiskhide() { +void auto_start_magiskhide(bool late_props) { if (hide_enabled()) { #if ENABLE_PTRACE_MONITOR pthread_kill(monitor_thread, SIGALRM); @@ -330,7 +330,7 @@ void auto_start_magiskhide() { db_settings dbs; get_db_settings(dbs, HIDE_CONFIG); if (dbs[HIDE_CONFIG]) - launch_magiskhide(); + launch_magiskhide(late_props); } } diff --git a/native/jni/magiskhide/magiskhide.cpp b/native/jni/magiskhide/magiskhide.cpp index 3a3e03a46..1f2aad99a 100644 --- a/native/jni/magiskhide/magiskhide.cpp +++ b/native/jni/magiskhide/magiskhide.cpp @@ -1,14 +1,6 @@ -#include -#include -#include -#include -#include -#include #include -#include #include -#include #include #include "magiskhide.hpp" @@ -53,7 +45,7 @@ void magiskhide_handler(int client) { switch (req) { case LAUNCH_MAGISKHIDE: - res = launch_magiskhide(); + res = launch_magiskhide(true); break; case STOP_MAGISKHIDE: res = stop_magiskhide(); diff --git a/native/jni/magiskhide/magiskhide.hpp b/native/jni/magiskhide/magiskhide.hpp index 81a33e25e..7cb154277 100644 --- a/native/jni/magiskhide/magiskhide.hpp +++ b/native/jni/magiskhide/magiskhide.hpp @@ -18,7 +18,7 @@ #define ENABLE_PTRACE_MONITOR 1 // CLI entries -int launch_magiskhide(); +int launch_magiskhide(bool late_props); int stop_magiskhide(); int add_list(int client); int rm_list(int client); diff --git a/native/jni/su/connect.cpp b/native/jni/su/connect.cpp index c1a829487..d796cd058 100644 --- a/native/jni/su/connect.cpp +++ b/native/jni/su/connect.cpp @@ -1,7 +1,6 @@ #include #include -#include #include #include diff --git a/native/jni/su/pts.cpp b/native/jni/su/pts.cpp index 32e2aa5be..fecde743d 100644 --- a/native/jni/su/pts.cpp +++ b/native/jni/su/pts.cpp @@ -9,13 +9,9 @@ * helper functions to handle raw input mode and terminal window resizing */ -#include #include #include -#include #include -#include -#include #include @@ -116,7 +112,7 @@ static int stdin_is_raw = 0; /** * set_stdin_raw * - * Changes stdin to raw unbuffered mode, disables echo, + * Changes stdin to raw unbuffered mode, disables echo, * auto carriage return, etc. * * Return Value @@ -180,7 +176,7 @@ int restore_stdin(void) { static volatile bool close_sigwinch_watcher = false; /** - * Thread process. Wait for a SIGWINCH to be received, then update + * Thread process. Wait for a SIGWINCH to be received, then update * the terminal size. */ static void *watch_sigwinch(void *data) { @@ -214,7 +210,7 @@ static void *watch_sigwinch(void *data) { * watch_sigwinch_async * * After calling this function, if the application receives - * SIGWINCH, the terminal window size will be read from + * SIGWINCH, the terminal window size will be read from * "input" and set on "output". * * NOTE: This function blocks SIGWINCH and spawns a thread. @@ -228,7 +224,7 @@ static void *watch_sigwinch(void *data) { * * Return Value * on failure, -1 and errno will be set. In this case, no - * thread has been spawned and SIGWINCH will not be + * thread has been spawned and SIGWINCH will not be * blocked. * on success, 0 */ diff --git a/native/jni/su/su.cpp b/native/jni/su/su.cpp index 3be8512c6..73d69a150 100644 --- a/native/jni/su/su.cpp +++ b/native/jni/su/su.cpp @@ -1,26 +1,19 @@ /* - * Copyright 2017, John Wu (@topjohnwu) + * Copyright 2017 - 2021, John Wu (@topjohnwu) * Copyright 2015, Pierre-Hugues Husson * Copyright 2010, Adam Shanks (@ChainsDD) * Copyright 2008, Zinx Verituse (@zinxv) */ -/* su.c - The main function running in the daemon - */ - -#include -#include -#include #include #include #include #include -#include -#include #include #include #include +#include #include #include #include diff --git a/native/jni/su/su.hpp b/native/jni/su/su.hpp index fd9c51c79..9bcd9c9da 100644 --- a/native/jni/su/su.hpp +++ b/native/jni/su/su.hpp @@ -5,7 +5,6 @@ #include #include -#include #define DEFAULT_SHELL "/system/bin/sh" diff --git a/native/jni/su/su_daemon.cpp b/native/jni/su/su_daemon.cpp index 0960dd498..1a26c577b 100644 --- a/native/jni/su/su_daemon.cpp +++ b/native/jni/su/su_daemon.cpp @@ -1,20 +1,14 @@ #include -#include -#include #include -#include -#include #include -#include #include -#include -#include #include #include #include #include #include +#include #include "su.hpp" #include "pts.hpp"