mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-14 07:31:48 +00:00
Restructure project files
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#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"
|
||||
@@ -1,102 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <pthread.h>
|
||||
#include <poll.h>
|
||||
#include <string>
|
||||
#include <limits>
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
|
||||
#include <socket.hpp>
|
||||
#include "../core/core-rs.hpp"
|
||||
|
||||
#define AID_ROOT 0
|
||||
#define AID_SHELL 2000
|
||||
#define AID_APP_START 10000
|
||||
#define AID_APP_END 19999
|
||||
#define AID_USER_OFFSET 100000
|
||||
|
||||
#define to_app_id(uid) (uid % AID_USER_OFFSET)
|
||||
#define to_user_id(uid) (uid / AID_USER_OFFSET)
|
||||
|
||||
// Daemon command codes
|
||||
namespace MainRequest {
|
||||
enum : int {
|
||||
START_DAEMON,
|
||||
CHECK_VERSION,
|
||||
CHECK_VERSION_CODE,
|
||||
STOP_DAEMON,
|
||||
|
||||
_SYNC_BARRIER_,
|
||||
|
||||
SUPERUSER,
|
||||
ZYGOTE_RESTART,
|
||||
DENYLIST,
|
||||
SQLITE_CMD,
|
||||
REMOVE_MODULES,
|
||||
ZYGISK,
|
||||
|
||||
_STAGE_BARRIER_,
|
||||
|
||||
POST_FS_DATA,
|
||||
LATE_START,
|
||||
BOOT_COMPLETE,
|
||||
|
||||
END,
|
||||
};
|
||||
}
|
||||
|
||||
// Return codes for daemon
|
||||
namespace MainResponse {
|
||||
enum : int {
|
||||
ERROR = -1,
|
||||
OK = 0,
|
||||
ROOT_REQUIRED,
|
||||
ACCESS_DENIED,
|
||||
END
|
||||
};
|
||||
}
|
||||
|
||||
struct module_info {
|
||||
std::string name;
|
||||
int z32 = -1;
|
||||
#if defined(__LP64__)
|
||||
int z64 = -1;
|
||||
#endif
|
||||
};
|
||||
|
||||
extern bool zygisk_enabled;
|
||||
extern std::vector<module_info> *module_list;
|
||||
void reset_zygisk(bool restore);
|
||||
|
||||
extern "C" const char *get_magisk_tmp();
|
||||
int connect_daemon(int req, bool create = false);
|
||||
|
||||
// Poll control
|
||||
using poll_callback = void(*)(pollfd*);
|
||||
void register_poll(const pollfd *pfd, poll_callback callback);
|
||||
void unregister_poll(int fd, bool auto_close);
|
||||
void clear_poll();
|
||||
|
||||
// Thread pool
|
||||
void exec_task(std::function<void()> &&task);
|
||||
|
||||
// Daemon handlers
|
||||
void boot_stage_handler(int client, int code);
|
||||
void denylist_handler(int client, const sock_cred *cred);
|
||||
void su_daemon_handler(int client, const sock_cred *cred);
|
||||
void zygisk_handler(int client, const sock_cred *cred);
|
||||
|
||||
// Package
|
||||
void preserve_stub_apk();
|
||||
void check_pkg_refresh();
|
||||
std::vector<bool> get_app_no_list();
|
||||
// Call check_pkg_refresh() before calling get_manager(...)
|
||||
// to make sure the package state is invalidated!
|
||||
int get_manager(int user_id = 0, std::string *pkg = nullptr, bool install = false);
|
||||
void prune_su_access();
|
||||
|
||||
// Denylist
|
||||
extern std::atomic_flag skip_pkg_rescan;
|
||||
void initialize_denylist();
|
||||
int denylist_cli(int argc, char **argv);
|
||||
@@ -1,134 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <functional>
|
||||
|
||||
template <class T, size_t N>
|
||||
class db_dict {
|
||||
public:
|
||||
T& operator [](std::string_view key) {
|
||||
return data[get_idx(key)];
|
||||
}
|
||||
|
||||
const T& operator [](std::string_view key) const {
|
||||
return data[get_idx(key)];
|
||||
}
|
||||
|
||||
T& operator [](int key) {
|
||||
return data[key];
|
||||
}
|
||||
|
||||
const T& operator [](int key) const {
|
||||
return data[key];
|
||||
}
|
||||
|
||||
protected:
|
||||
T data[N + 1];
|
||||
virtual int get_idx(std::string_view key) const = 0;
|
||||
};
|
||||
|
||||
/***************
|
||||
* DB Settings *
|
||||
***************/
|
||||
|
||||
constexpr const char *DB_SETTING_KEYS[] = {
|
||||
"root_access",
|
||||
"multiuser_mode",
|
||||
"mnt_ns",
|
||||
"denylist",
|
||||
"zygisk"
|
||||
};
|
||||
|
||||
// Settings key indices
|
||||
enum {
|
||||
ROOT_ACCESS = 0,
|
||||
SU_MULTIUSER_MODE,
|
||||
SU_MNT_NS,
|
||||
DENYLIST_CONFIG,
|
||||
ZYGISK_CONFIG
|
||||
};
|
||||
|
||||
// Values for root_access
|
||||
enum {
|
||||
ROOT_ACCESS_DISABLED = 0,
|
||||
ROOT_ACCESS_APPS_ONLY,
|
||||
ROOT_ACCESS_ADB_ONLY,
|
||||
ROOT_ACCESS_APPS_AND_ADB
|
||||
};
|
||||
|
||||
// Values for multiuser_mode
|
||||
enum {
|
||||
MULTIUSER_MODE_OWNER_ONLY = 0,
|
||||
MULTIUSER_MODE_OWNER_MANAGED,
|
||||
MULTIUSER_MODE_USER
|
||||
};
|
||||
|
||||
// Values for mnt_ns
|
||||
enum {
|
||||
NAMESPACE_MODE_GLOBAL = 0,
|
||||
NAMESPACE_MODE_REQUESTER,
|
||||
NAMESPACE_MODE_ISOLATE
|
||||
};
|
||||
|
||||
class db_settings : public db_dict<int, std::size(DB_SETTING_KEYS)> {
|
||||
public:
|
||||
db_settings();
|
||||
protected:
|
||||
int get_idx(std::string_view key) const override;
|
||||
};
|
||||
|
||||
/**************
|
||||
* DB Strings *
|
||||
**************/
|
||||
|
||||
constexpr const char *DB_STRING_KEYS[] = { "requester" };
|
||||
|
||||
// Strings keys indices
|
||||
enum {
|
||||
SU_MANAGER = 0
|
||||
};
|
||||
|
||||
class db_strings : public db_dict<std::string, std::size(DB_STRING_KEYS)> {
|
||||
protected:
|
||||
int get_idx(std::string_view key) const override;
|
||||
};
|
||||
|
||||
/*************
|
||||
* SU Access *
|
||||
*************/
|
||||
|
||||
typedef enum {
|
||||
QUERY = 0,
|
||||
DENY = 1,
|
||||
ALLOW = 2,
|
||||
} policy_t;
|
||||
|
||||
struct su_access {
|
||||
policy_t policy;
|
||||
int log;
|
||||
int notify;
|
||||
};
|
||||
|
||||
#define DEFAULT_SU_ACCESS { QUERY, 1, 1 }
|
||||
#define SILENT_SU_ACCESS { ALLOW, 0, 0 }
|
||||
#define NO_SU_ACCESS { DENY, 0, 0 }
|
||||
|
||||
/********************
|
||||
* Public Functions *
|
||||
********************/
|
||||
|
||||
using db_row = std::map<std::string_view, std::string_view>;
|
||||
using db_row_cb = std::function<bool(db_row&)>;
|
||||
|
||||
int get_db_settings(db_settings &cfg, int key = -1);
|
||||
int get_db_strings(db_strings &str, int key = -1);
|
||||
void rm_db_strings(int key);
|
||||
void exec_sql(int client);
|
||||
char *db_exec(const char *sql);
|
||||
char *db_exec(const char *sql, const db_row_cb &fn);
|
||||
bool db_err(char *e);
|
||||
|
||||
#define db_err_cmd(e, cmd) if (db_err(e)) { cmd; }
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <base.hpp>
|
||||
|
||||
int setcon(const char *con);
|
||||
int getfilecon(const char *path, byte_data con);
|
||||
int lgetfilecon(const char *path, byte_data con);
|
||||
int fgetfilecon(int fd, byte_data con);
|
||||
int setfilecon(const char *path, const char *con);
|
||||
int lsetfilecon(const char *path, const char *con);
|
||||
int fsetfilecon(int fd, const char *con);
|
||||
int getfilecon_at(int dirfd, const char *name, byte_data con);
|
||||
void setfilecon_at(int dirfd, const char *name, const char *con);
|
||||
|
||||
void restorecon();
|
||||
void restore_tmpcon();
|
||||
@@ -1,38 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <sys/un.h>
|
||||
#include <sys/socket.h>
|
||||
#include <string_view>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct sock_cred : public ucred {
|
||||
std::string context;
|
||||
};
|
||||
|
||||
bool get_client_cred(int fd, sock_cred *cred);
|
||||
std::vector<int> recv_fds(int sockfd);
|
||||
int recv_fd(int sockfd);
|
||||
int send_fds(int sockfd, const int *fds, int cnt);
|
||||
int send_fd(int sockfd, int fd);
|
||||
int read_int(int fd);
|
||||
int read_int_be(int fd);
|
||||
void write_int(int fd, int val);
|
||||
void write_int_be(int fd, int val);
|
||||
std::string read_string(int fd);
|
||||
bool read_string(int fd, std::string &str);
|
||||
void write_string(int fd, std::string_view str);
|
||||
|
||||
template<typename T> requires(std::is_trivially_copyable_v<T>)
|
||||
void write_vector(int fd, const std::vector<T> &vec) {
|
||||
write_int(fd, static_cast<int>(vec.size()));
|
||||
xwrite(fd, vec.data(), vec.size() * sizeof(T));
|
||||
}
|
||||
|
||||
template<typename T> requires(std::is_trivially_copyable_v<T>)
|
||||
bool read_vector(int fd, std::vector<T> &vec) {
|
||||
int size = read_int(fd);
|
||||
if (size == -1) return false;
|
||||
vec.resize(size);
|
||||
return xread(fd, vec.data(), size * sizeof(T)) == size * sizeof(T);
|
||||
}
|
||||
Reference in New Issue
Block a user