diff --git a/native/src/Android-rs.mk b/native/src/Android-rs.mk index 2a0027335..cb04a076f 100644 --- a/native/src/Android-rs.mk +++ b/native/src/Android-rs.mk @@ -8,6 +8,7 @@ LIBRARY_PATH = ../out/$(TARGET_ARCH_ABI)/libmagisk-rs.a ifneq (,$(wildcard $(LOCAL_PATH)/$(LIBRARY_PATH))) include $(CLEAR_VARS) LOCAL_MODULE := magisk-rs +LOCAL_EXPORT_C_INCLUDES := src/core/include LOCAL_SRC_FILES := $(LIBRARY_PATH) include $(PREBUILT_STATIC_LIBRARY) endif diff --git a/native/src/Android.mk b/native/src/Android.mk index 4c58b2c02..c534bf465 100644 --- a/native/src/Android.mk +++ b/native/src/Android.mk @@ -26,19 +26,19 @@ LOCAL_SRC_FILES := \ core/selinux.cpp \ core/module.cpp \ core/thread.cpp \ - core/resetprop/resetprop.cpp \ core/core-rs.cpp \ + core/resetprop/resetprop.cpp \ core/su/su.cpp \ core/su/connect.cpp \ core/su/pts.cpp \ core/su/su_daemon.cpp \ - zygisk/entry.cpp \ - zygisk/main.cpp \ - zygisk/hook.cpp \ - zygisk/native_bridge.cpp \ - zygisk/deny/cli.cpp \ - zygisk/deny/utils.cpp \ - zygisk/deny/revert.cpp + core/zygisk/entry.cpp \ + core/zygisk/main.cpp \ + core/zygisk/hook.cpp \ + core/zygisk/native_bridge.cpp \ + core/deny/cli.cpp \ + core/deny/utils.cpp \ + core/deny/revert.cpp LOCAL_LDLIBS := -llog LOCAL_LDFLAGS := -Wl,--dynamic-list=src/exported_sym.txt diff --git a/native/src/core/applet_stub.cpp b/native/src/core/applet_stub.cpp index 52a6f32df..291abb962 100644 --- a/native/src/core/applet_stub.cpp +++ b/native/src/core/applet_stub.cpp @@ -1,6 +1,6 @@ #include -#include +#include #include #include diff --git a/native/src/core/applets.cpp b/native/src/core/applets.cpp index ee1578812..0b6d0b537 100644 --- a/native/src/core/applets.cpp +++ b/native/src/core/applets.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include diff --git a/native/src/core/bootstages.cpp b/native/src/core/bootstages.cpp index 88d9edff1..45c1722f9 100644 --- a/native/src/core/bootstages.cpp +++ b/native/src/core/bootstages.cpp @@ -6,14 +6,12 @@ #include #include -#include +#include #include #include -#include +#include #include -#include "core.hpp" - using namespace std; // Boot stage state diff --git a/native/src/core/core.hpp b/native/src/core/core.hpp deleted file mode 100644 index 7f5148e5b..000000000 --- a/native/src/core/core.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -#include -#include - -#include "core-rs.hpp" -#include "resetprop/resetprop.hpp" - -extern bool RECOVERY_MODE; -extern std::atomic pkg_xml_ino; - -std::string find_preinit_device(); -void unlock_blocks(); -void reboot(); - -// Module stuffs -void handle_modules(); -void load_modules(); -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 &modules); -void install_apk(const char *apk); -void uninstall_pkg(const char *pkg); -void clear_pkg(const char *pkg, int user_id); -[[noreturn]] void install_module(const char *file); diff --git a/native/src/core/daemon.cpp b/native/src/core/daemon.cpp index 27a4c85b9..e05ae964c 100644 --- a/native/src/core/daemon.cpp +++ b/native/src/core/daemon.cpp @@ -3,15 +3,13 @@ #include #include -#include +#include #include -#include +#include #include #include #include -#include "core.hpp" - using namespace std; int SDK_INT = -1; diff --git a/native/src/core/db.cpp b/native/src/core/db.cpp index b55c93110..3c6f13959 100644 --- a/native/src/core/db.cpp +++ b/native/src/core/db.cpp @@ -2,12 +2,10 @@ #include #include -#include -#include -#include +#include #include - -#include "core.hpp" +#include +#include #define DB_VERSION 12 diff --git a/native/src/zygisk/deny/cli.cpp b/native/src/core/deny/cli.cpp similarity index 99% rename from native/src/zygisk/deny/cli.cpp rename to native/src/core/deny/cli.cpp index 0e9e7434f..33d380cc8 100644 --- a/native/src/zygisk/deny/cli.cpp +++ b/native/src/core/deny/cli.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include #include #include "deny.hpp" diff --git a/native/src/zygisk/deny/deny.hpp b/native/src/core/deny/deny.hpp similarity index 77% rename from native/src/zygisk/deny/deny.hpp rename to native/src/core/deny/deny.hpp index 656b1dcca..557b92c42 100644 --- a/native/src/zygisk/deny/deny.hpp +++ b/native/src/core/deny/deny.hpp @@ -6,7 +6,7 @@ #include #include -#include +#include #define ISOLATED_MAGIC "isolated" @@ -44,9 +44,3 @@ int disable_deny(); int add_list(int client); int rm_list(int client); void ls_list(int client); - -// Utility functions -bool is_deny_target(int uid, std::string_view process); -void revert_unmount(); - -extern std::atomic denylist_enforced; diff --git a/native/src/zygisk/deny/revert.cpp b/native/src/core/deny/revert.cpp similarity index 96% rename from native/src/zygisk/deny/revert.cpp rename to native/src/core/deny/revert.cpp index 01cdcf01a..90dd206ca 100644 --- a/native/src/zygisk/deny/revert.cpp +++ b/native/src/core/deny/revert.cpp @@ -1,8 +1,9 @@ #include #include -#include +#include #include +#include #include "deny.hpp" diff --git a/native/src/zygisk/deny/utils.cpp b/native/src/core/deny/utils.cpp similarity index 99% rename from native/src/zygisk/deny/utils.cpp rename to native/src/core/deny/utils.cpp index 68c4b75ac..63629d5d5 100644 --- a/native/src/zygisk/deny/utils.cpp +++ b/native/src/core/deny/utils.cpp @@ -6,9 +6,10 @@ #include #include -#include +#include #include #include +#include #include "deny.hpp" diff --git a/native/src/include/daemon.hpp b/native/src/core/include/core.hpp similarity index 71% rename from native/src/include/daemon.hpp rename to native/src/core/include/core.hpp index e9d063db7..fb6efd872 100644 --- a/native/src/include/daemon.hpp +++ b/native/src/core/include/core.hpp @@ -7,8 +7,8 @@ #include #include -#include -#include "../core/core-rs.hpp" +#include "socket.hpp" +#include "../core-rs.hpp" #define AID_ROOT 0 #define AID_SHELL 2000 @@ -65,12 +65,16 @@ struct module_info { #endif }; +extern bool RECOVERY_MODE; extern bool zygisk_enabled; extern std::vector *module_list; -void reset_zygisk(bool restore); +void reset_zygisk(bool restore); extern "C" const char *get_magisk_tmp(); int connect_daemon(int req, bool create = false); +std::string find_preinit_device(); +void unlock_blocks(); +void reboot(); // Poll control using poll_callback = void(*)(pollfd*); @@ -88,6 +92,7 @@ void su_daemon_handler(int client, const sock_cred *cred); void zygisk_handler(int client, const sock_cred *cred); // Package +extern std::atomic pkg_xml_ino; void preserve_stub_apk(); void check_pkg_refresh(); std::vector get_app_no_list(); @@ -96,7 +101,26 @@ std::vector get_app_no_list(); int get_manager(int user_id = 0, std::string *pkg = nullptr, bool install = false); void prune_su_access(); +// Module stuffs +void handle_modules(); +void load_modules(); +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 &modules); +void install_apk(const char *apk); +void uninstall_pkg(const char *pkg); +void clear_pkg(const char *pkg, int user_id); +[[noreturn]] void install_module(const char *file); + // Denylist extern std::atomic_flag skip_pkg_rescan; -void initialize_denylist(); +extern std::atomic denylist_enforced; int denylist_cli(int argc, char **argv); +void initialize_denylist(); +bool is_deny_target(int uid, std::string_view process); +void revert_unmount(); diff --git a/native/src/include/db.hpp b/native/src/core/include/db.hpp similarity index 100% rename from native/src/include/db.hpp rename to native/src/core/include/db.hpp diff --git a/native/src/core/resetprop/resetprop.hpp b/native/src/core/include/resetprop.hpp similarity index 91% rename from native/src/core/resetprop/resetprop.hpp rename to native/src/core/include/resetprop.hpp index 05b297dd7..931f52500 100644 --- a/native/src/core/resetprop/resetprop.hpp +++ b/native/src/core/include/resetprop.hpp @@ -4,9 +4,6 @@ #include #include -#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ -#include - struct prop_cb { virtual void exec(const char *name, const char *value) = 0; }; diff --git a/native/src/include/selinux.hpp b/native/src/core/include/selinux.hpp similarity index 100% rename from native/src/include/selinux.hpp rename to native/src/core/include/selinux.hpp diff --git a/native/src/include/socket.hpp b/native/src/core/include/socket.hpp similarity index 100% rename from native/src/include/socket.hpp rename to native/src/core/include/socket.hpp diff --git a/native/src/core/lib.rs b/native/src/core/lib.rs index d15588494..55529096b 100644 --- a/native/src/core/lib.rs +++ b/native/src/core/lib.rs @@ -19,7 +19,7 @@ mod resetprop; #[cxx::bridge] pub mod ffi { extern "C++" { - include!("resetprop/resetprop.hpp"); + include!("include/resetprop.hpp"); #[cxx_name = "prop_cb"] type PropCb; diff --git a/native/src/core/magisk.cpp b/native/src/core/magisk.cpp index 1278ba93e..3d4f264b4 100644 --- a/native/src/core/magisk.cpp +++ b/native/src/core/magisk.cpp @@ -2,13 +2,11 @@ #include #include -#include -#include +#include +#include #include #include -#include "core.hpp" - using namespace std; [[noreturn]] static void usage() { diff --git a/native/src/core/module.cpp b/native/src/core/module.cpp index 48539f740..280516f51 100644 --- a/native/src/core/module.cpp +++ b/native/src/core/module.cpp @@ -5,11 +5,10 @@ #include #include -#include -#include +#include +#include #include -#include "core.hpp" #include "node.hpp" using namespace std; diff --git a/native/src/core/package.cpp b/native/src/core/package.cpp index 096fdf980..e26ba38ca 100644 --- a/native/src/core/package.cpp +++ b/native/src/core/package.cpp @@ -1,11 +1,9 @@ #include -#include -#include +#include +#include #include #include -#include "core.hpp" - using namespace std; using rust::Vec; diff --git a/native/src/core/resetprop/resetprop.cpp b/native/src/core/resetprop/resetprop.cpp index f5606e709..a9eca71f7 100644 --- a/native/src/core/resetprop/resetprop.cpp +++ b/native/src/core/resetprop/resetprop.cpp @@ -4,9 +4,11 @@ #include #include +#include +#include -#include "resetprop.hpp" -#include "../core-rs.hpp" +#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ +#include using namespace std; diff --git a/native/src/core/scripting.cpp b/native/src/core/scripting.cpp index 854df54c7..e2a5d5a2a 100644 --- a/native/src/core/scripting.cpp +++ b/native/src/core/scripting.cpp @@ -2,12 +2,10 @@ #include #include -#include +#include #include #include -#include - -#include "core.hpp" +#include using namespace std; diff --git a/native/src/core/selinux.cpp b/native/src/core/selinux.cpp index 7a1994ce7..5dfb240a5 100644 --- a/native/src/core/selinux.cpp +++ b/native/src/core/selinux.cpp @@ -2,10 +2,10 @@ #include #include -#include +#include #include #include -#include +#include #include using namespace std; diff --git a/native/src/core/su/connect.cpp b/native/src/core/su/connect.cpp index 2db72abb0..af78a5e06 100644 --- a/native/src/core/su/connect.cpp +++ b/native/src/core/su/connect.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include "su.hpp" diff --git a/native/src/core/su/su.cpp b/native/src/core/su/su.cpp index e84a6713f..ba1783954 100644 --- a/native/src/core/su/su.cpp +++ b/native/src/core/su/su.cpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include diff --git a/native/src/core/su/su.hpp b/native/src/core/su/su.hpp index 2c9b14719..68485c286 100644 --- a/native/src/core/su/su.hpp +++ b/native/src/core/su/su.hpp @@ -5,7 +5,7 @@ #include #include -#include +#include #define DEFAULT_SHELL "/system/bin/sh" diff --git a/native/src/core/su/su_daemon.cpp b/native/src/core/su/su_daemon.cpp index 28b311a6b..6334e75d6 100644 --- a/native/src/core/su/su_daemon.cpp +++ b/native/src/core/su/su_daemon.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include diff --git a/native/src/core/thread.cpp b/native/src/core/thread.cpp index 4a7a7da63..d9a2e0c37 100644 --- a/native/src/core/thread.cpp +++ b/native/src/core/thread.cpp @@ -2,7 +2,7 @@ #include -#include +#include using namespace std; diff --git a/native/src/zygisk/api.hpp b/native/src/core/zygisk/api.hpp similarity index 100% rename from native/src/zygisk/api.hpp rename to native/src/core/zygisk/api.hpp diff --git a/native/src/zygisk/entry.cpp b/native/src/core/zygisk/entry.cpp similarity index 99% rename from native/src/zygisk/entry.cpp rename to native/src/core/zygisk/entry.cpp index b143c4ff3..a307878c8 100644 --- a/native/src/zygisk/entry.cpp +++ b/native/src/core/zygisk/entry.cpp @@ -6,11 +6,10 @@ #include #include -#include +#include #include "zygisk.hpp" #include "module.hpp" -#include "deny/deny.hpp" using namespace std; diff --git a/native/src/zygisk/gen_jni_hooks.py b/native/src/core/zygisk/gen_jni_hooks.py similarity index 100% rename from native/src/zygisk/gen_jni_hooks.py rename to native/src/core/zygisk/gen_jni_hooks.py diff --git a/native/src/zygisk/hook.cpp b/native/src/core/zygisk/hook.cpp similarity index 99% rename from native/src/zygisk/hook.cpp rename to native/src/core/zygisk/hook.cpp index 297c196a1..7a5ee994d 100644 --- a/native/src/zygisk/hook.cpp +++ b/native/src/core/zygisk/hook.cpp @@ -9,11 +9,10 @@ #include #include -#include +#include #include "zygisk.hpp" #include "module.hpp" -#include "deny/deny.hpp" using namespace std; diff --git a/native/src/zygisk/jni_hooks.hpp b/native/src/core/zygisk/jni_hooks.hpp similarity index 100% rename from native/src/zygisk/jni_hooks.hpp rename to native/src/core/zygisk/jni_hooks.hpp diff --git a/native/src/zygisk/main.cpp b/native/src/core/zygisk/main.cpp similarity index 97% rename from native/src/zygisk/main.cpp rename to native/src/core/zygisk/main.cpp index 66ded0858..85e70d768 100644 --- a/native/src/zygisk/main.cpp +++ b/native/src/core/zygisk/main.cpp @@ -2,10 +2,9 @@ #include #include -#include +#include #include -#include -#include +#include #include #include "zygisk.hpp" diff --git a/native/src/zygisk/module.hpp b/native/src/core/zygisk/module.hpp similarity index 100% rename from native/src/zygisk/module.hpp rename to native/src/core/zygisk/module.hpp diff --git a/native/src/zygisk/native_bridge.cpp b/native/src/core/zygisk/native_bridge.cpp similarity index 93% rename from native/src/zygisk/native_bridge.cpp rename to native/src/core/zygisk/native_bridge.cpp index 51a52b15a..dd83fc087 100644 --- a/native/src/zygisk/native_bridge.cpp +++ b/native/src/core/zygisk/native_bridge.cpp @@ -2,9 +2,10 @@ #include #include -#include +#include +#include + #include "zygisk.hpp" -#include "../core/core.hpp" static bool is_compatible_with(uint32_t) { auto name = get_prop(NBPROP); diff --git a/native/src/zygisk/zygisk.hpp b/native/src/core/zygisk/zygisk.hpp similarity index 98% rename from native/src/zygisk/zygisk.hpp rename to native/src/core/zygisk/zygisk.hpp index 91087041b..fe1247134 100644 --- a/native/src/zygisk/zygisk.hpp +++ b/native/src/core/zygisk/zygisk.hpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include namespace ZygiskRequest { enum : int { diff --git a/native/src/include/magisk.hpp b/native/src/include/consts.hpp similarity index 96% rename from native/src/include/magisk.hpp rename to native/src/include/consts.hpp index 1142a29cc..7df3f96a6 100644 --- a/native/src/include/magisk.hpp +++ b/native/src/include/consts.hpp @@ -1,7 +1,5 @@ #pragma once -#include - #define JAVA_PACKAGE_NAME "com.topjohnwu.magisk" #define ZYGISKLDR "libzygisk.so" #define NBPROP "ro.dalvik.vm.native.bridge" @@ -23,7 +21,6 @@ #define ROOTOVL INTLROOT "/rootdir" #define SHELLPTS INTLROOT "/pts" #define ROOTMNT ROOTOVL "/.mount_list" -#define ZYGISKBIN INTLROOT "/zygisk" #define SELINUXMOCK INTLROOT "/selinux" #define MAIN_CONFIG INTLROOT "/config" #define MAIN_SOCKET INTLROOT "/socket" diff --git a/native/src/init/mount.cpp b/native/src/init/mount.cpp index 04e82dc87..476257870 100644 --- a/native/src/init/mount.cpp +++ b/native/src/init/mount.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include #include "init.hpp" diff --git a/native/src/init/rootdir.cpp b/native/src/init/rootdir.cpp index 0adbf32af..359c5f169 100644 --- a/native/src/init/rootdir.cpp +++ b/native/src/init/rootdir.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include diff --git a/native/src/init/selinux.cpp b/native/src/init/selinux.cpp index 2eff10411..8159205a3 100644 --- a/native/src/init/selinux.cpp +++ b/native/src/init/selinux.cpp @@ -1,6 +1,6 @@ #include -#include +#include #include #include diff --git a/native/src/init/twostage.cpp b/native/src/init/twostage.cpp index 0e1079709..50fc348ac 100644 --- a/native/src/init/twostage.cpp +++ b/native/src/init/twostage.cpp @@ -1,6 +1,6 @@ #include -#include +#include #include #include diff --git a/native/src/sepolicy/rules.cpp b/native/src/sepolicy/rules.cpp index 4bd372024..abc85d1b2 100644 --- a/native/src/sepolicy/rules.cpp +++ b/native/src/sepolicy/rules.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include "policy.hpp"