Restructure project files

This commit is contained in:
topjohnwu 2023-11-08 01:46:02 -08:00
parent ecb31eed40
commit 65c18f9c09
44 changed files with 85 additions and 113 deletions

View File

@ -8,6 +8,7 @@ LIBRARY_PATH = ../out/$(TARGET_ARCH_ABI)/libmagisk-rs.a
ifneq (,$(wildcard $(LOCAL_PATH)/$(LIBRARY_PATH))) ifneq (,$(wildcard $(LOCAL_PATH)/$(LIBRARY_PATH)))
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_MODULE := magisk-rs LOCAL_MODULE := magisk-rs
LOCAL_EXPORT_C_INCLUDES := src/core/include
LOCAL_SRC_FILES := $(LIBRARY_PATH) LOCAL_SRC_FILES := $(LIBRARY_PATH)
include $(PREBUILT_STATIC_LIBRARY) include $(PREBUILT_STATIC_LIBRARY)
endif endif

View File

@ -26,19 +26,19 @@ LOCAL_SRC_FILES := \
core/selinux.cpp \ core/selinux.cpp \
core/module.cpp \ core/module.cpp \
core/thread.cpp \ core/thread.cpp \
core/resetprop/resetprop.cpp \
core/core-rs.cpp \ core/core-rs.cpp \
core/resetprop/resetprop.cpp \
core/su/su.cpp \ core/su/su.cpp \
core/su/connect.cpp \ core/su/connect.cpp \
core/su/pts.cpp \ core/su/pts.cpp \
core/su/su_daemon.cpp \ core/su/su_daemon.cpp \
zygisk/entry.cpp \ core/zygisk/entry.cpp \
zygisk/main.cpp \ core/zygisk/main.cpp \
zygisk/hook.cpp \ core/zygisk/hook.cpp \
zygisk/native_bridge.cpp \ core/zygisk/native_bridge.cpp \
zygisk/deny/cli.cpp \ core/deny/cli.cpp \
zygisk/deny/utils.cpp \ core/deny/utils.cpp \
zygisk/deny/revert.cpp core/deny/revert.cpp
LOCAL_LDLIBS := -llog LOCAL_LDLIBS := -llog
LOCAL_LDFLAGS := -Wl,--dynamic-list=src/exported_sym.txt LOCAL_LDFLAGS := -Wl,--dynamic-list=src/exported_sym.txt

View File

@ -1,6 +1,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <magisk.hpp> #include <consts.hpp>
#include <selinux.hpp> #include <selinux.hpp>
#include <base.hpp> #include <base.hpp>

View File

@ -2,7 +2,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <magisk.hpp> #include <consts.hpp>
#include <selinux.hpp> #include <selinux.hpp>
#include <base.hpp> #include <base.hpp>

View File

@ -6,14 +6,12 @@
#include <set> #include <set>
#include <string> #include <string>
#include <magisk.hpp> #include <consts.hpp>
#include <db.hpp> #include <db.hpp>
#include <base.hpp> #include <base.hpp>
#include <daemon.hpp> #include <core.hpp>
#include <selinux.hpp> #include <selinux.hpp>
#include "core.hpp"
using namespace std; using namespace std;
// Boot stage state // Boot stage state

View File

@ -1,30 +0,0 @@
#pragma once
#include <string>
#include <vector>
#include "core-rs.hpp"
#include "resetprop/resetprop.hpp"
extern bool RECOVERY_MODE;
extern std::atomic<ino_t> 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<std::string_view> &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);

View File

@ -3,15 +3,13 @@
#include <sys/un.h> #include <sys/un.h>
#include <sys/mount.h> #include <sys/mount.h>
#include <magisk.hpp> #include <consts.hpp>
#include <base.hpp> #include <base.hpp>
#include <daemon.hpp> #include <core.hpp>
#include <selinux.hpp> #include <selinux.hpp>
#include <db.hpp> #include <db.hpp>
#include <flags.h> #include <flags.h>
#include "core.hpp"
using namespace std; using namespace std;
int SDK_INT = -1; int SDK_INT = -1;

View File

@ -2,12 +2,10 @@
#include <dlfcn.h> #include <dlfcn.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <magisk.hpp> #include <consts.hpp>
#include <db.hpp>
#include <socket.hpp>
#include <base.hpp> #include <base.hpp>
#include <db.hpp>
#include "core.hpp" #include <core.hpp>
#define DB_VERSION 12 #define DB_VERSION 12

View File

@ -1,7 +1,7 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/mount.h> #include <sys/mount.h>
#include <magisk.hpp> #include <consts.hpp>
#include <base.hpp> #include <base.hpp>
#include "deny.hpp" #include "deny.hpp"

View File

@ -6,7 +6,7 @@
#include <map> #include <map>
#include <atomic> #include <atomic>
#include <daemon.hpp> #include <core.hpp>
#define ISOLATED_MAGIC "isolated" #define ISOLATED_MAGIC "isolated"
@ -44,9 +44,3 @@ int disable_deny();
int add_list(int client); int add_list(int client);
int rm_list(int client); int rm_list(int client);
void ls_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<bool> denylist_enforced;

View File

@ -1,8 +1,9 @@
#include <set> #include <set>
#include <sys/mount.h> #include <sys/mount.h>
#include <magisk.hpp> #include <consts.hpp>
#include <base.hpp> #include <base.hpp>
#include <core.hpp>
#include "deny.hpp" #include "deny.hpp"

View File

@ -6,9 +6,10 @@
#include <dirent.h> #include <dirent.h>
#include <set> #include <set>
#include <magisk.hpp> #include <consts.hpp>
#include <base.hpp> #include <base.hpp>
#include <db.hpp> #include <db.hpp>
#include <core.hpp>
#include "deny.hpp" #include "deny.hpp"

View File

@ -7,8 +7,8 @@
#include <atomic> #include <atomic>
#include <functional> #include <functional>
#include <socket.hpp> #include "socket.hpp"
#include "../core/core-rs.hpp" #include "../core-rs.hpp"
#define AID_ROOT 0 #define AID_ROOT 0
#define AID_SHELL 2000 #define AID_SHELL 2000
@ -65,12 +65,16 @@ struct module_info {
#endif #endif
}; };
extern bool RECOVERY_MODE;
extern bool zygisk_enabled; extern bool zygisk_enabled;
extern std::vector<module_info> *module_list; extern std::vector<module_info> *module_list;
void reset_zygisk(bool restore);
void reset_zygisk(bool restore);
extern "C" const char *get_magisk_tmp(); extern "C" const char *get_magisk_tmp();
int connect_daemon(int req, bool create = false); int connect_daemon(int req, bool create = false);
std::string find_preinit_device();
void unlock_blocks();
void reboot();
// Poll control // Poll control
using poll_callback = void(*)(pollfd*); 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); void zygisk_handler(int client, const sock_cred *cred);
// Package // Package
extern std::atomic<ino_t> pkg_xml_ino;
void preserve_stub_apk(); void preserve_stub_apk();
void check_pkg_refresh(); void check_pkg_refresh();
std::vector<bool> get_app_no_list(); std::vector<bool> get_app_no_list();
@ -96,7 +101,26 @@ std::vector<bool> get_app_no_list();
int get_manager(int user_id = 0, std::string *pkg = nullptr, bool install = false); int get_manager(int user_id = 0, std::string *pkg = nullptr, bool install = false);
void prune_su_access(); 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<std::string_view> &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 // Denylist
extern std::atomic_flag skip_pkg_rescan; extern std::atomic_flag skip_pkg_rescan;
void initialize_denylist(); extern std::atomic<bool> denylist_enforced;
int denylist_cli(int argc, char **argv); int denylist_cli(int argc, char **argv);
void initialize_denylist();
bool is_deny_target(int uid, std::string_view process);
void revert_unmount();

View File

@ -4,9 +4,6 @@
#include <map> #include <map>
#include <cxx.h> #include <cxx.h>
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
#include <api/_system_properties.h>
struct prop_cb { struct prop_cb {
virtual void exec(const char *name, const char *value) = 0; virtual void exec(const char *name, const char *value) = 0;
}; };

View File

@ -19,7 +19,7 @@ mod resetprop;
#[cxx::bridge] #[cxx::bridge]
pub mod ffi { pub mod ffi {
extern "C++" { extern "C++" {
include!("resetprop/resetprop.hpp"); include!("include/resetprop.hpp");
#[cxx_name = "prop_cb"] #[cxx_name = "prop_cb"]
type PropCb; type PropCb;

View File

@ -2,13 +2,11 @@
#include <libgen.h> #include <libgen.h>
#include <base.hpp> #include <base.hpp>
#include <magisk.hpp> #include <consts.hpp>
#include <daemon.hpp> #include <core.hpp>
#include <selinux.hpp> #include <selinux.hpp>
#include <flags.h> #include <flags.h>
#include "core.hpp"
using namespace std; using namespace std;
[[noreturn]] static void usage() { [[noreturn]] static void usage() {

View File

@ -5,11 +5,10 @@
#include <utility> #include <utility>
#include <base.hpp> #include <base.hpp>
#include <magisk.hpp> #include <consts.hpp>
#include <daemon.hpp> #include <core.hpp>
#include <selinux.hpp> #include <selinux.hpp>
#include "core.hpp"
#include "node.hpp" #include "node.hpp"
using namespace std; using namespace std;

View File

@ -1,11 +1,9 @@
#include <base.hpp> #include <base.hpp>
#include <magisk.hpp> #include <consts.hpp>
#include <daemon.hpp> #include <core.hpp>
#include <db.hpp> #include <db.hpp>
#include <flags.h> #include <flags.h>
#include "core.hpp"
using namespace std; using namespace std;
using rust::Vec; using rust::Vec;

View File

@ -4,9 +4,11 @@
#include <map> #include <map>
#include <base.hpp> #include <base.hpp>
#include <core.hpp>
#include <resetprop.hpp>
#include "resetprop.hpp" #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
#include "../core-rs.hpp" #include <api/_system_properties.h>
using namespace std; using namespace std;

View File

@ -2,12 +2,10 @@
#include <vector> #include <vector>
#include <sys/wait.h> #include <sys/wait.h>
#include <magisk.hpp> #include <consts.hpp>
#include <base.hpp> #include <base.hpp>
#include <selinux.hpp> #include <selinux.hpp>
#include <daemon.hpp> #include <core.hpp>
#include "core.hpp"
using namespace std; using namespace std;

View File

@ -2,10 +2,10 @@
#include <sys/syscall.h> #include <sys/syscall.h>
#include <sys/xattr.h> #include <sys/xattr.h>
#include <magisk.hpp> #include <consts.hpp>
#include <base.hpp> #include <base.hpp>
#include <selinux.hpp> #include <selinux.hpp>
#include <daemon.hpp> #include <core.hpp>
#include <flags.h> #include <flags.h>
using namespace std; using namespace std;

View File

@ -3,7 +3,7 @@
#include <base.hpp> #include <base.hpp>
#include <selinux.hpp> #include <selinux.hpp>
#include <magisk.hpp> #include <consts.hpp>
#include "su.hpp" #include "su.hpp"

View File

@ -13,7 +13,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <magisk.hpp> #include <consts.hpp>
#include <base.hpp> #include <base.hpp>
#include <flags.h> #include <flags.h>

View File

@ -5,7 +5,7 @@
#include <memory> #include <memory>
#include <db.hpp> #include <db.hpp>
#include <daemon.hpp> #include <core.hpp>
#define DEFAULT_SHELL "/system/bin/sh" #define DEFAULT_SHELL "/system/bin/sh"

View File

@ -5,7 +5,7 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/mount.h> #include <sys/mount.h>
#include <magisk.hpp> #include <consts.hpp>
#include <base.hpp> #include <base.hpp>
#include <selinux.hpp> #include <selinux.hpp>

View File

@ -2,7 +2,7 @@
#include <base.hpp> #include <base.hpp>
#include <daemon.hpp> #include <core.hpp>
using namespace std; using namespace std;

View File

@ -6,11 +6,10 @@
#include <android/dlext.h> #include <android/dlext.h>
#include <base.hpp> #include <base.hpp>
#include <magisk.hpp> #include <consts.hpp>
#include "zygisk.hpp" #include "zygisk.hpp"
#include "module.hpp" #include "module.hpp"
#include "deny/deny.hpp"
using namespace std; using namespace std;

View File

@ -9,11 +9,10 @@
#include <lsplt.hpp> #include <lsplt.hpp>
#include <base.hpp> #include <base.hpp>
#include <magisk.hpp> #include <consts.hpp>
#include "zygisk.hpp" #include "zygisk.hpp"
#include "module.hpp" #include "module.hpp"
#include "deny/deny.hpp"
using namespace std; using namespace std;

View File

@ -2,10 +2,9 @@
#include <android/dlext.h> #include <android/dlext.h>
#include <dlfcn.h> #include <dlfcn.h>
#include <magisk.hpp> #include <consts.hpp>
#include <base.hpp> #include <base.hpp>
#include <socket.hpp> #include <core.hpp>
#include <daemon.hpp>
#include <selinux.hpp> #include <selinux.hpp>
#include "zygisk.hpp" #include "zygisk.hpp"

View File

@ -2,9 +2,10 @@
#include <dlfcn.h> #include <dlfcn.h>
#include <unwind.h> #include <unwind.h>
#include <magisk.hpp> #include <consts.hpp>
#include <core.hpp>
#include "zygisk.hpp" #include "zygisk.hpp"
#include "../core/core.hpp"
static bool is_compatible_with(uint32_t) { static bool is_compatible_with(uint32_t) {
auto name = get_prop(NBPROP); auto name = get_prop(NBPROP);

View File

@ -4,7 +4,7 @@
#include <stdint.h> #include <stdint.h>
#include <jni.h> #include <jni.h>
#include <vector> #include <vector>
#include <daemon.hpp> #include <core.hpp>
namespace ZygiskRequest { namespace ZygiskRequest {
enum : int { enum : int {

View File

@ -1,7 +1,5 @@
#pragma once #pragma once
#include <string>
#define JAVA_PACKAGE_NAME "com.topjohnwu.magisk" #define JAVA_PACKAGE_NAME "com.topjohnwu.magisk"
#define ZYGISKLDR "libzygisk.so" #define ZYGISKLDR "libzygisk.so"
#define NBPROP "ro.dalvik.vm.native.bridge" #define NBPROP "ro.dalvik.vm.native.bridge"
@ -23,7 +21,6 @@
#define ROOTOVL INTLROOT "/rootdir" #define ROOTOVL INTLROOT "/rootdir"
#define SHELLPTS INTLROOT "/pts" #define SHELLPTS INTLROOT "/pts"
#define ROOTMNT ROOTOVL "/.mount_list" #define ROOTMNT ROOTOVL "/.mount_list"
#define ZYGISKBIN INTLROOT "/zygisk"
#define SELINUXMOCK INTLROOT "/selinux" #define SELINUXMOCK INTLROOT "/selinux"
#define MAIN_CONFIG INTLROOT "/config" #define MAIN_CONFIG INTLROOT "/config"
#define MAIN_SOCKET INTLROOT "/socket" #define MAIN_SOCKET INTLROOT "/socket"

View File

@ -5,7 +5,7 @@
#include <base.hpp> #include <base.hpp>
#include <flags.h> #include <flags.h>
#include <magisk.hpp> #include <consts.hpp>
#include "init.hpp" #include "init.hpp"

View File

@ -3,7 +3,7 @@
#include <sys/sysmacros.h> #include <sys/sysmacros.h>
#include <sepolicy.hpp> #include <sepolicy.hpp>
#include <magisk.hpp> #include <consts.hpp>
#include <base.hpp> #include <base.hpp>
#include <flags.h> #include <flags.h>

View File

@ -1,6 +1,6 @@
#include <sys/mount.h> #include <sys/mount.h>
#include <magisk.hpp> #include <consts.hpp>
#include <sepolicy.hpp> #include <sepolicy.hpp>
#include <embed.hpp> #include <embed.hpp>

View File

@ -1,6 +1,6 @@
#include <sys/mount.h> #include <sys/mount.h>
#include <magisk.hpp> #include <consts.hpp>
#include <base.hpp> #include <base.hpp>
#include <sys/vfs.h> #include <sys/vfs.h>

View File

@ -1,4 +1,4 @@
#include <magisk.hpp> #include <consts.hpp>
#include <base.hpp> #include <base.hpp>
#include "policy.hpp" #include "policy.hpp"