Add basic hide

This commit is contained in:
Nullptr
2023-02-02 20:51:36 +08:00
parent 73cf671fbf
commit d416758135
6 changed files with 47 additions and 58 deletions

View File

@@ -1,52 +0,0 @@
#pragma once
#include <pthread.h>
#include <string_view>
#include <functional>
#include <map>
#include <atomic>
#include <daemon.hpp>
#define ISOLATED_MAGIC "isolated"
namespace DenyRequest {
enum : int {
ENFORCE,
DISABLE,
ADD,
REMOVE,
LIST,
STATUS,
END
};
}
namespace DenyResponse {
enum : int {
OK,
ENFORCED,
NOT_ENFORCED,
ITEM_EXIST,
ITEM_NOT_EXIST,
INVALID_PKG,
NO_NS,
ERROR,
END
};
}
// CLI entries
int enable_deny();
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<bool> denylist_enforced;

View File

@@ -0,0 +1,23 @@
#include <sys/mount.h>
#include "logging.h"
#include "misc.hpp"
#include "zygisk.hpp"
using namespace std::string_view_literals;
static void lazy_unmount(const char* mountpoint) {
if (umount2(mountpoint, MNT_DETACH) != -1)
LOGD("Unmounted (%s)", mountpoint);
}
#define OVERLAY_MNT(dir) (mentry->mnt_type == "overlay"sv && std::string_view(mentry->mnt_dir).starts_with("/" #dir))
void revert_unmount() {
parse_mnt("/proc/self/mounts", [](mntent* mentry) {
if (OVERLAY_MNT("system") || OVERLAY_MNT("vendor") || OVERLAY_MNT("product") || OVERLAY_MNT("system_ext")) {
lazy_unmount(mentry->mnt_fsname);
}
return true;
});
}

View File

@@ -193,7 +193,7 @@ DCL_HOOK_FUNC(int, unshare, int flags) {
// Simply avoid doing any unmounts for SysUI to avoid potential issues.
(g_ctx->info_flags & PROCESS_IS_SYS_UI) == 0) {
if (g_ctx->flags[DO_REVERT_UNMOUNT]) {
// FIXME: revert_unmount();
revert_unmount();
}
/* Zygisksu changed: No umount app_process */

View File

@@ -23,6 +23,18 @@ int parse_int(std::string_view s) {
return val;
}
void parse_mnt(const char* file, const std::function<bool(mntent*)>& fn) {
auto fp = sFILE(setmntent(file, "re"), endmntent);
if (fp) {
mntent mentry{};
char buf[PATH_MAX];
while (getmntent_r(fp.get(), &mentry, buf, sizeof(buf))) {
if (!fn(&mentry))
break;
}
}
}
sDIR make_dir(DIR *dp) {
return sDIR(dp, [](DIR *dp){ return dp ? closedir(dp) : 1; });
}

View File

@@ -1,12 +1,14 @@
#pragma once
#include <pthread.h>
#include "logging.h"
#include <dirent.h>
#include <stdio.h>
#include <string_view>
#include <functional>
#include <memory>
#include <mntent.h>
#include <pthread.h>
#include <stdio.h>
#include <string_view>
#include "logging.h"
#define DISALLOW_COPY_AND_MOVE(clazz) \
clazz(const clazz &) = delete; \
@@ -93,6 +95,8 @@ struct StringCmp {
*/
int parse_int(std::string_view s);
void parse_mnt(const char* file, const std::function<bool(mntent*)>& fn);
template <typename T>
static inline T align_to(T v, int a) {
static_assert(std::is_integral<T>::value);

View File

@@ -7,3 +7,5 @@
extern void *self_handle;
void hook_functions();
void revert_unmount();