You've already forked Zygisk-Assistant
mirror of
https://github.com/snake-4/Zygisk-Assistant.git
synced 2025-09-06 06:37:02 +00:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7ec3214927 | ||
|
|
c797376230 | ||
|
|
33a9ff93f4 | ||
|
|
6f4d78b0fc | ||
|
|
08547864cd | ||
|
|
d59ac2bf26 | ||
|
|
52e5771205 | ||
|
|
ce278b37f7 | ||
|
|
fe05fbd621 | ||
|
|
83f2880922 | ||
|
|
112c4027fe | ||
|
|
aa9a8a04e3 | ||
|
|
670767a82b | ||
|
|
7200b77043 | ||
|
|
a07e62fcd7 | ||
|
|
0ee57d586f |
18
.github/workflows/ci.yml
vendored
18
.github/workflows/ci.yml
vendored
@@ -1,28 +1,24 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: [ main ]
|
||||
tags: [ v* ]
|
||||
pull_request:
|
||||
merge_group:
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: "recursive"
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup Java
|
||||
uses: actions/setup-java@v3
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: "temurin"
|
||||
java-version: "17"
|
||||
java-version: 17
|
||||
|
||||
- name: Setup Gradle
|
||||
uses: gradle/actions/setup-gradle@v3
|
||||
|
||||
- name: Build with Gradle
|
||||
run: |
|
||||
|
||||
@@ -4,17 +4,17 @@ plugins {
|
||||
alias(libs.plugins.agp.lib) apply false
|
||||
}
|
||||
|
||||
val commitHash: String by extra({
|
||||
val commitHash: String by extra {
|
||||
val stdout = ByteArrayOutputStream()
|
||||
rootProject.exec {
|
||||
commandLine("git", "rev-parse", "--short", "HEAD")
|
||||
standardOutput = stdout
|
||||
}
|
||||
stdout.toString().trim()
|
||||
})
|
||||
}
|
||||
|
||||
val moduleId by extra("zygisk-assistant")
|
||||
val moduleName by extra("Zygisk Assistant")
|
||||
val verName by extra("v2.0.0")
|
||||
val verCode by extra(200)
|
||||
val verName by extra("v2.0.4")
|
||||
val verCode by extra(204)
|
||||
val abiList by extra(listOf("armeabi-v7a","arm64-v8a","x86","x86_64"))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[versions]
|
||||
agp = "8.2.0"
|
||||
agp = "8.3.1"
|
||||
|
||||
[plugins]
|
||||
agp-lib = { id = "com.android.library", version.ref = "agp" }
|
||||
|
||||
@@ -13,7 +13,7 @@ val abiList: List<String> by rootProject.extra
|
||||
|
||||
android {
|
||||
namespace = "com.example.library"
|
||||
compileSdkVersion = "android-31"
|
||||
compileSdkVersion = "android-34"
|
||||
defaultConfig {
|
||||
minSdk = 21
|
||||
ndk {
|
||||
@@ -37,7 +37,7 @@ androidComponents.onVariants { variant ->
|
||||
val variantCapped = variant.name.capitalizeUS()
|
||||
val buildTypeLowered = variant.buildType?.lowercase()
|
||||
|
||||
val libOutDir = layout.buildDirectory.dir("intermediates/stripped_native_libs/$variantLowered/out/lib").get()
|
||||
val libOutDir = layout.buildDirectory.dir("intermediates/stripped_native_libs/$variantLowered/strip${variantCapped}DebugSymbols/out/lib").get()
|
||||
val moduleDir = layout.buildDirectory.dir("outputs/module/$variantLowered").get()
|
||||
val zipOutDir = layout.buildDirectory.dir("outputs/release").get()
|
||||
val zipFileName = "$moduleName-$verName-$commitHash-$buildTypeLowered.zip".replace(' ', '-')
|
||||
@@ -55,6 +55,9 @@ androidComponents.onVariants { variant ->
|
||||
"versionCode" to verCode
|
||||
)
|
||||
}
|
||||
from("$projectDir/template") {
|
||||
exclude("module.prop")
|
||||
}
|
||||
from(libOutDir) {
|
||||
into("zygisk")
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ LOCAL_PATH := $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
|
||||
LOCAL_MODULE := zygisk
|
||||
LOCAL_SRC_FILES := mount_parser.cpp unmount.cpp main.cpp
|
||||
LOCAL_SRC_FILES := utils.cpp map_parser.cpp mount_parser.cpp mountinfo_parser.cpp unmount.cpp main.cpp
|
||||
LOCAL_STATIC_LIBRARIES := libcxx
|
||||
LOCAL_LDLIBS := -llog
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
APP_ABI := armeabi-v7a arm64-v8a x86 x86_64
|
||||
APP_CPPFLAGS := -std=c++14 -fno-exceptions -fno-rtti -fvisibility=hidden -fvisibility-inlines-hidden
|
||||
APP_CPPFLAGS := -std=c++20 -fno-exceptions -fno-rtti -fvisibility=hidden -fvisibility-inlines-hidden
|
||||
APP_STL := none
|
||||
APP_PLATFORM := android-31
|
||||
|
||||
27
module/jni/include/map_parser.hpp
Normal file
27
module/jni/include/map_parser.hpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sys/types.h>
|
||||
|
||||
class map_entry_t
|
||||
{
|
||||
public:
|
||||
map_entry_t(uintptr_t address_start, uintptr_t address_end, uintptr_t offset,
|
||||
const std::string &perms, const std::string &pathname, dev_t device, ino_t inode);
|
||||
|
||||
uintptr_t getAddressStart() const;
|
||||
uintptr_t getAddressEnd() const;
|
||||
const std::string &getPerms() const;
|
||||
uintptr_t getOffset() const;
|
||||
dev_t getDevice() const;
|
||||
ino_t getInode() const;
|
||||
const std::string &getPathname() const;
|
||||
|
||||
private:
|
||||
uintptr_t address_start, address_end, offset;
|
||||
std::string perms, pathname;
|
||||
dev_t device;
|
||||
ino_t inode;
|
||||
};
|
||||
|
||||
std::vector<map_entry_t> parseMapsFromPath(const char *path);
|
||||
@@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
@@ -16,14 +17,10 @@ public:
|
||||
int getPassNumber() const;
|
||||
|
||||
private:
|
||||
void parseMountOptions(const std::string &input);
|
||||
|
||||
std::string fsname;
|
||||
std::string dir;
|
||||
std::string type;
|
||||
std::string fsname, dir, type;
|
||||
std::unordered_map<std::string, std::string> opts_map;
|
||||
int freq;
|
||||
int passno;
|
||||
int freq, passno;
|
||||
};
|
||||
|
||||
std::vector<mount_entry_t> parseMountsFromPath(const char *path);
|
||||
std::unordered_map<std::string, std::string> parseMountOptions(const std::string &input);
|
||||
|
||||
33
module/jni/include/mountinfo_parser.hpp
Normal file
33
module/jni/include/mountinfo_parser.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
class mountinfo_entry_t
|
||||
{
|
||||
public:
|
||||
mountinfo_entry_t(int mount_id, int parent_id, int major, int minor,
|
||||
const std::string &root, const std::string &mount_point,
|
||||
const std::string &mount_options, const std::string &optional_fields,
|
||||
const std::string &filesystem_type, const std::string &mount_source,
|
||||
const std::string &super_options);
|
||||
|
||||
int getMountId() const;
|
||||
int getParentId() const;
|
||||
int getMajor() const;
|
||||
int getMinor() const;
|
||||
const std::string &getRoot() const;
|
||||
const std::string &getMountPoint() const;
|
||||
const std::unordered_map<std::string, std::string> &getMountOptions() const;
|
||||
const std::string &getOptionalFields() const;
|
||||
const std::string &getFilesystemType() const;
|
||||
const std::string &getMountSource() const;
|
||||
const std::unordered_map<std::string, std::string> &getSuperOptions() const;
|
||||
|
||||
private:
|
||||
int mount_id, parent_id, major, minor;
|
||||
std::string root, mount_point, optional_fields, filesystem_type, mount_source;
|
||||
std::unordered_map<std::string, std::string> mount_options, super_options;
|
||||
};
|
||||
|
||||
std::vector<mountinfo_entry_t> parseMountinfosFromPath(const char *path);
|
||||
10
module/jni/include/utils.hpp
Normal file
10
module/jni/include/utils.hpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include "zygisk.hpp"
|
||||
|
||||
#define DCL_HOOK_FUNC(ret, func, ...) \
|
||||
ret (*old_##func)(__VA_ARGS__); \
|
||||
ret new_##func(__VA_ARGS__)
|
||||
|
||||
int is_userapp_uid(int uid);
|
||||
bool hook_plt_by_name(zygisk::Api *api, const std::string &libName, const std::string &symbolName, void *hookFunc, void **origFunc);
|
||||
@@ -1,11 +1,10 @@
|
||||
#include <unistd.h>
|
||||
#include <sched.h>
|
||||
|
||||
#include <sys/mount.h>
|
||||
|
||||
#include "zygisk.hpp"
|
||||
#include "logging.hpp"
|
||||
#include "android_filesystem_config.h"
|
||||
#include "utils.hpp"
|
||||
|
||||
using zygisk::Api;
|
||||
using zygisk::AppSpecializeArgs;
|
||||
@@ -13,14 +12,16 @@ using zygisk::ServerSpecializeArgs;
|
||||
|
||||
void do_unmount();
|
||||
|
||||
static int shouldSkipUid(int uid)
|
||||
DCL_HOOK_FUNC(static int, unshare, int flags)
|
||||
{
|
||||
int appid = uid % AID_USER_OFFSET;
|
||||
if (appid >= AID_APP_START && appid <= AID_APP_END)
|
||||
return false;
|
||||
if (appid >= AID_ISOLATED_START && appid <= AID_ISOLATED_END)
|
||||
return false;
|
||||
return true;
|
||||
// Do not allow CLONE_NEWNS.
|
||||
flags &= ~(CLONE_NEWNS);
|
||||
if (!flags)
|
||||
{
|
||||
// If CLONE_NEWNS was the only flag, skip the call.
|
||||
return 0;
|
||||
}
|
||||
return old_unshare(flags);
|
||||
}
|
||||
|
||||
class ZygiskModule : public zygisk::ModuleBase
|
||||
@@ -39,43 +40,45 @@ public:
|
||||
uint32_t flags = api->getFlags();
|
||||
bool isRoot = (flags & zygisk::StateFlag::PROCESS_GRANTED_ROOT) != 0;
|
||||
bool isOnDenylist = (flags & zygisk::StateFlag::PROCESS_ON_DENYLIST) != 0;
|
||||
if (isRoot || !isOnDenylist || shouldSkipUid(args->uid))
|
||||
if (isRoot || !isOnDenylist || !is_userapp_uid(args->uid))
|
||||
{
|
||||
LOGD("Skipping pid=%d uid=%d", getpid(), args->uid);
|
||||
LOGD("Skipping pid=%d ppid=%d uid=%d", getpid(), getppid(), args->uid);
|
||||
return;
|
||||
}
|
||||
|
||||
LOGD("Unmounting in preAppSpecialize for pid=%d uid=%d", getpid(), args->uid);
|
||||
LOGD("Processing pid=%d ppid=%d uid=%d", getpid(), getppid(), args->uid);
|
||||
|
||||
/*
|
||||
* Create only one namespace per zygote, child Zygotes will inherit it
|
||||
* But then again, why won't they also inherit the unmounts of the parent?
|
||||
* Either way, unshare in child Zygote will crash at the open FD sanity check.
|
||||
* Calling unshare twice invalidates FD hard links, which fails Zygote sanity checks.
|
||||
* So we hook unshare to prevent further namespace creations.
|
||||
* The logic behind whether there's going to be an unshare or not changes with each major Android version.
|
||||
* For maximum compatibility, we will always unshare but prevent further unshare by this Zygote fork in appSpecialize.
|
||||
*/
|
||||
if (!*args->is_child_zygote)
|
||||
if (!plt_hook_wrapper("libandroid_runtime.so", "unshare", new_unshare, old_unshare))
|
||||
{
|
||||
LOGD("Creating new mount namespace for parent pid=%d uid=%d", getpid(), args->uid);
|
||||
LOGE("plt_hook_wrapper(\"libandroid_runtime.so\", \"unshare\", new_unshare, old_unshare) returned false");
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* preAppSpecialize is before ensureInAppMountNamespace.
|
||||
* postAppSpecialize is after seccomp setup.
|
||||
* So we unshare here to create a pseudo app mount namespace
|
||||
*/
|
||||
if (unshare(CLONE_NEWNS) == -1)
|
||||
{
|
||||
LOGE("unshare(CLONE_NEWNS) returned -1: %d (%s)", errno, strerror(errno));
|
||||
// Don't unmount anything in global namespace
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* preAppSpecialize is before any possible unshare calls.
|
||||
* postAppSpecialize is after seccomp setup.
|
||||
* So we unshare here to create an app mount namespace.
|
||||
*/
|
||||
if (old_unshare(CLONE_NEWNS) == -1)
|
||||
{
|
||||
LOGE("unshare(CLONE_NEWNS) returned -1: %d (%s)", errno, strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Mount the pseudo app mount namespace's root as MS_SLAVE, so every mount/umount from
|
||||
* Zygote shared pre-specialization mountspace is propagated to this one.
|
||||
*/
|
||||
if (mount("rootfs", "/", NULL, (MS_SLAVE | MS_REC), NULL) == -1)
|
||||
{
|
||||
LOGE("mount(\"rootfs\", \"/\", NULL, (MS_SLAVE | MS_REC), NULL) returned -1");
|
||||
}
|
||||
/*
|
||||
* Mount the app mount namespace's root as MS_SLAVE, so every mount/umount from
|
||||
* Zygote shared pre-specialization namespace is propagated to this one.
|
||||
*/
|
||||
if (mount("rootfs", "/", NULL, (MS_SLAVE | MS_REC), NULL) == -1)
|
||||
{
|
||||
LOGE("mount(\"rootfs\", \"/\", NULL, (MS_SLAVE | MS_REC), NULL) returned -1");
|
||||
return;
|
||||
}
|
||||
|
||||
do_unmount();
|
||||
@@ -86,9 +89,15 @@ public:
|
||||
api->setOption(zygisk::Option::DLCLOSE_MODULE_LIBRARY);
|
||||
}
|
||||
|
||||
template <typename Return, typename... Args>
|
||||
bool plt_hook_wrapper(const std::string &libName, const std::string &symbolName, Return (&hookFunction)(Args...), Return (*&originalFunction)(Args...))
|
||||
{
|
||||
return hook_plt_by_name(api, libName, symbolName, (void *)&hookFunction, (void **)&originalFunction) && api->pltHookCommit();
|
||||
}
|
||||
|
||||
private:
|
||||
Api *api;
|
||||
JNIEnv *env;
|
||||
};
|
||||
|
||||
REGISTER_ZYGISK_MODULE(ZygiskModule)
|
||||
REGISTER_ZYGISK_MODULE(ZygiskModule)
|
||||
59
module/jni/map_parser.cpp
Normal file
59
module/jni/map_parser.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <sys/sysmacros.h> // For makedev
|
||||
|
||||
#include "map_parser.hpp"
|
||||
#include "logging.hpp"
|
||||
|
||||
map_entry_t::map_entry_t(uintptr_t address_start, uintptr_t address_end, uintptr_t offset, const std::string &perms, const std::string &pathname, dev_t device, ino_t inode)
|
||||
: address_start(address_start), address_end(address_end), perms(perms),
|
||||
offset(offset), device(device), inode(inode), pathname(pathname) {}
|
||||
|
||||
uintptr_t map_entry_t::getAddressStart() const { return address_start; }
|
||||
uintptr_t map_entry_t::getAddressEnd() const { return address_end; }
|
||||
const std::string &map_entry_t::getPerms() const { return perms; }
|
||||
uintptr_t map_entry_t::getOffset() const { return offset; }
|
||||
dev_t map_entry_t::getDevice() const { return device; }
|
||||
ino_t map_entry_t::getInode() const { return inode; }
|
||||
const std::string &map_entry_t::getPathname() const { return pathname; }
|
||||
|
||||
std::vector<map_entry_t> parseMapsFromPath(const char *path)
|
||||
{
|
||||
std::vector<map_entry_t> ret;
|
||||
|
||||
std::ifstream ifs(path, std::ifstream::in);
|
||||
if (!ifs)
|
||||
{
|
||||
LOGE("parseMapsFromPath could not open file \"%s\"", path);
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (std::string line; std::getline(ifs, line);)
|
||||
{
|
||||
std::istringstream iss(line);
|
||||
|
||||
uintptr_t address_start, address_end, offset;
|
||||
std::string perms;
|
||||
std::string pathname;
|
||||
ino_t inode;
|
||||
int dev_major, dev_minor;
|
||||
char dummy_char;
|
||||
|
||||
iss >> std::hex >> address_start >> dummy_char >> address_end >> perms >> offset >> dev_major >> dummy_char >> dev_minor >> std::dec >> inode;
|
||||
|
||||
if (iss.fail())
|
||||
{
|
||||
LOGE("parseMapsFromPath failed to parse line: %s", line.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
// This operation can fail, it doesn't matter as it's an optional field.
|
||||
std::getline(iss >> std::ws, pathname);
|
||||
|
||||
ret.emplace_back(map_entry_t(address_start, address_end, offset, perms, pathname, makedev(dev_major, dev_minor), inode));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -11,55 +11,15 @@
|
||||
mount_entry_t::mount_entry_t(::mntent *entry)
|
||||
: fsname(entry->mnt_fsname), dir(entry->mnt_dir), type(entry->mnt_type), freq(entry->mnt_freq), passno(entry->mnt_passno)
|
||||
{
|
||||
parseMountOptions(entry->mnt_opts);
|
||||
opts_map = parseMountOptions(entry->mnt_opts);
|
||||
}
|
||||
|
||||
const std::string &mount_entry_t::getFsName() const
|
||||
{
|
||||
return fsname;
|
||||
}
|
||||
|
||||
const std::string &mount_entry_t::getMountPoint() const
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
|
||||
const std::string &mount_entry_t::getType() const
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
const std::unordered_map<std::string, std::string> &mount_entry_t::getOptions() const
|
||||
{
|
||||
return opts_map;
|
||||
}
|
||||
|
||||
int mount_entry_t::getDumpFrequency() const
|
||||
{
|
||||
return freq;
|
||||
}
|
||||
|
||||
int mount_entry_t::getPassNumber() const
|
||||
{
|
||||
return passno;
|
||||
}
|
||||
|
||||
void mount_entry_t::parseMountOptions(const std::string &input)
|
||||
{
|
||||
std::istringstream iss(input);
|
||||
std::string token;
|
||||
while (std::getline(iss, token, ','))
|
||||
{
|
||||
std::istringstream tokenStream(token);
|
||||
std::string key, value;
|
||||
|
||||
if (std::getline(tokenStream, key, '='))
|
||||
{
|
||||
std::getline(tokenStream, value); // Put what's left in the stream to value, could be empty
|
||||
opts_map[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
const std::string &mount_entry_t::getFsName() const { return fsname; }
|
||||
const std::string &mount_entry_t::getMountPoint() const { return dir; }
|
||||
const std::string &mount_entry_t::getType() const { return type; }
|
||||
const std::unordered_map<std::string, std::string> &mount_entry_t::getOptions() const { return opts_map; }
|
||||
int mount_entry_t::getDumpFrequency() const { return freq; }
|
||||
int mount_entry_t::getPassNumber() const { return passno; }
|
||||
|
||||
std::vector<mount_entry_t> parseMountsFromPath(const char *path)
|
||||
{
|
||||
@@ -81,3 +41,22 @@ std::vector<mount_entry_t> parseMountsFromPath(const char *path)
|
||||
endmntent(file);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, std::string> parseMountOptions(const std::string &input)
|
||||
{
|
||||
std::unordered_map<std::string, std::string> ret;
|
||||
std::istringstream iss(input);
|
||||
std::string token;
|
||||
while (std::getline(iss, token, ','))
|
||||
{
|
||||
std::istringstream tokenStream(token);
|
||||
std::string key, value;
|
||||
|
||||
if (std::getline(tokenStream, key, '='))
|
||||
{
|
||||
std::getline(tokenStream, value); // Put what's left in the stream to value, could be empty
|
||||
ret[key] = value;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
90
module/jni/mountinfo_parser.cpp
Normal file
90
module/jni/mountinfo_parser.cpp
Normal file
@@ -0,0 +1,90 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "mountinfo_parser.hpp"
|
||||
#include "mount_parser.hpp"
|
||||
#include "logging.hpp"
|
||||
|
||||
mountinfo_entry_t::mountinfo_entry_t(int mount_id, int parent_id, int major, int minor,
|
||||
const std::string &root, const std::string &mount_point,
|
||||
const std::string &mount_options, const std::string &optional_fields,
|
||||
const std::string &filesystem_type, const std::string &mount_source,
|
||||
const std::string &super_options)
|
||||
: mount_id(mount_id), parent_id(parent_id), major(major), minor(minor),
|
||||
root(root), mount_point(mount_point),
|
||||
optional_fields(optional_fields), filesystem_type(filesystem_type),
|
||||
mount_source(mount_source)
|
||||
{
|
||||
this->mount_options = parseMountOptions(mount_options);
|
||||
this->super_options = parseMountOptions(super_options);
|
||||
}
|
||||
|
||||
int mountinfo_entry_t::getMountId() const { return mount_id; }
|
||||
int mountinfo_entry_t::getParentId() const { return parent_id; }
|
||||
int mountinfo_entry_t::getMajor() const { return major; }
|
||||
int mountinfo_entry_t::getMinor() const { return minor; }
|
||||
const std::string &mountinfo_entry_t::getRoot() const { return root; }
|
||||
const std::string &mountinfo_entry_t::getMountPoint() const { return mount_point; }
|
||||
const std::unordered_map<std::string, std::string> &mountinfo_entry_t::getMountOptions() const { return mount_options; }
|
||||
const std::string &mountinfo_entry_t::getOptionalFields() const { return optional_fields; }
|
||||
const std::string &mountinfo_entry_t::getFilesystemType() const { return filesystem_type; }
|
||||
const std::string &mountinfo_entry_t::getMountSource() const { return mount_source; }
|
||||
const std::unordered_map<std::string, std::string> &mountinfo_entry_t::getSuperOptions() const { return super_options; }
|
||||
|
||||
std::vector<mountinfo_entry_t> parseMountinfosFromPath(const char *path)
|
||||
{
|
||||
std::vector<mountinfo_entry_t> ret;
|
||||
|
||||
std::ifstream ifs(path, std::ifstream::in);
|
||||
if (!ifs)
|
||||
{
|
||||
LOGE("parseMountinfosFromPath could not open file \"%s\"", path);
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (std::string line; std::getline(ifs, line);)
|
||||
{
|
||||
std::istringstream iss(line);
|
||||
|
||||
int mount_id, parent_id, major, minor;
|
||||
std::string root, mount_point, mount_options, optional_fields, filesystem_type, mount_source, super_options;
|
||||
char colon;
|
||||
|
||||
// Read the first 6 fields (major, colon and minor are the same field)
|
||||
iss >> mount_id >> parent_id >> major >> colon >> minor >> root >> mount_point >> mount_options;
|
||||
if (iss.fail())
|
||||
{
|
||||
LOGE("parseMountinfosFromPath failed to parse the first 6 fields of line: %s", line.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string field;
|
||||
while (iss >> field && field != "-")
|
||||
{
|
||||
optional_fields += " " + field;
|
||||
}
|
||||
|
||||
if (iss.fail())
|
||||
{
|
||||
LOGE("parseMountinfosFromPath failed to parse the optional fields of line: %s", line.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
iss >> filesystem_type >> mount_source >> super_options;
|
||||
if (iss.fail())
|
||||
{
|
||||
LOGE("parseMountinfosFromPath failed to parse the last 3 fields of line: %s", line.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
ret.emplace_back(mountinfo_entry_t(mount_id, parent_id, major, minor,
|
||||
root, mount_point, mount_options,
|
||||
optional_fields, filesystem_type, mount_source,
|
||||
super_options));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -7,21 +7,33 @@
|
||||
#include "zygisk.hpp"
|
||||
#include "logging.hpp"
|
||||
#include "mount_parser.hpp"
|
||||
#include "mountinfo_parser.hpp"
|
||||
|
||||
constexpr std::array<const char *, 4> fsname_list = {"KSU", "APatch", "magisk", "worker"};
|
||||
|
||||
static bool shouldUnmount(const mount_entry_t &info)
|
||||
static bool shouldUnmount(const mountinfo_entry_t &mount_info)
|
||||
{
|
||||
const auto &mountPoint = info.getMountPoint();
|
||||
const auto &type = info.getType();
|
||||
const auto &options = info.getOptions();
|
||||
const auto &root = mount_info.getRoot();
|
||||
|
||||
// Unmount all module bind mounts
|
||||
if (root.rfind("/adb/modules", 0) == 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool shouldUnmount(const mount_entry_t &mount)
|
||||
{
|
||||
const auto &mountPoint = mount.getMountPoint();
|
||||
const auto &type = mount.getType();
|
||||
const auto &options = mount.getOptions();
|
||||
|
||||
// Unmount everything mounted to /data/adb
|
||||
if (mountPoint.rfind("/data/adb", 0) == 0)
|
||||
return true;
|
||||
|
||||
// Unmount all module overlayfs and tmpfs
|
||||
bool doesFsnameMatch = std::find(fsname_list.begin(), fsname_list.end(), info.getFsName()) != fsname_list.end();
|
||||
bool doesFsnameMatch = std::find(fsname_list.begin(), fsname_list.end(), mount.getFsName()) != fsname_list.end();
|
||||
if ((type == "overlay" || type == "tmpfs") && doesFsnameMatch)
|
||||
return true;
|
||||
|
||||
@@ -41,17 +53,29 @@ static bool shouldUnmount(const mount_entry_t &info)
|
||||
if (workdir != options.end() && workdir->second.rfind("/data/adb", 0) == 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void do_unmount()
|
||||
{
|
||||
std::vector<std::string> mountPoints;
|
||||
for (auto &info : parseMountsFromPath("/proc/self/mounts"))
|
||||
|
||||
// Check mounts first
|
||||
for (auto &mount : parseMountsFromPath("/proc/self/mounts"))
|
||||
{
|
||||
if (shouldUnmount(info))
|
||||
if (shouldUnmount(mount))
|
||||
{
|
||||
mountPoints.push_back(info.getMountPoint());
|
||||
mountPoints.push_back(mount.getMountPoint());
|
||||
}
|
||||
}
|
||||
|
||||
// Check mountinfos so that we can find bind mounts as well
|
||||
for (auto &mount_info : parseMountinfosFromPath("/proc/self/mountinfo"))
|
||||
{
|
||||
if (shouldUnmount(mount_info))
|
||||
{
|
||||
mountPoints.push_back(mount_info.getMountPoint());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
29
module/jni/utils.cpp
Normal file
29
module/jni/utils.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <string>
|
||||
|
||||
#include "map_parser.hpp"
|
||||
#include "utils.hpp"
|
||||
#include "android_filesystem_config.h"
|
||||
#include "zygisk.hpp"
|
||||
|
||||
bool hook_plt_by_name(zygisk::Api *api, const std::string &libName, const std::string &symbolName, void *hookFunc, void **origFunc)
|
||||
{
|
||||
for (const auto &map : parseMapsFromPath("/proc/self/maps"))
|
||||
{
|
||||
if (map.getPathname().ends_with("/" + libName))
|
||||
{
|
||||
api->pltHookRegister(map.getDevice(), map.getInode(), symbolName.c_str(), hookFunc, origFunc);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int is_userapp_uid(int uid)
|
||||
{
|
||||
int appid = uid % AID_USER_OFFSET;
|
||||
if (appid >= AID_APP_START && appid <= AID_APP_END)
|
||||
return true;
|
||||
if (appid >= AID_ISOLATED_START && appid <= AID_ISOLATED_END)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
@@ -3,4 +3,5 @@ name=${moduleName}
|
||||
version=${versionName}
|
||||
versionCode=${versionCode}
|
||||
author=snake-4
|
||||
description=Zygisk module to hide mounts.
|
||||
description=A Zygisk module to hide root.
|
||||
updateJson=https://raw.githubusercontent.com/snake-4/Zygisk-Assistant/main/update_metadata/update.json
|
||||
|
||||
12
update_metadata/CHANGELOG.md
Normal file
12
update_metadata/CHANGELOG.md
Normal file
@@ -0,0 +1,12 @@
|
||||
## 2.0.4
|
||||
+ Fixed an issue causing root to be lost.
|
||||
+ Fixed potential incompatibilities with other apps.
|
||||
|
||||
## 2.0.3
|
||||
+ Bind mounts are also hidden now.
|
||||
|
||||
## 2.0.2
|
||||
+ Fixed Magisk compatibility.
|
||||
|
||||
## 2.0.1
|
||||
+ Added update.json for automatic updates.
|
||||
6
update_metadata/update.json
Normal file
6
update_metadata/update.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"version": "v2.0.3",
|
||||
"versionCode": 203,
|
||||
"zipUrl": "https://github.com/snake-4/Zygisk-Assistant/releases/download/v2.0.3/Zygisk-Assistant-v2.0.3-fe05fbd-release.zip",
|
||||
"changelog": "https://raw.githubusercontent.com/snake-4/Zygisk-Assistant/main/update_metadata/CHANGELOG.md"
|
||||
}
|
||||
Reference in New Issue
Block a user