From 6e333581fbabcb68f9118485388e4a5c32647401 Mon Sep 17 00:00:00 2001 From: snake-4 <18491360+snake-4@users.noreply.github.com> Date: Sun, 14 Apr 2024 16:23:38 +0200 Subject: [PATCH] Added remount function and changed bind mount... prefix. --- module/jni/main.cpp | 2 ++ module/jni/unmount.cpp | 26 +++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/module/jni/main.cpp b/module/jni/main.cpp index ddde443..7544c9b 100644 --- a/module/jni/main.cpp +++ b/module/jni/main.cpp @@ -11,6 +11,7 @@ using zygisk::AppSpecializeArgs; using zygisk::ServerSpecializeArgs; void do_unmount(); +void do_remount(); DCL_HOOK_FUNC(static int, unshare, int flags) { @@ -84,6 +85,7 @@ public: } do_unmount(); + do_remount(); } void preServerSpecialize(ServerSpecializeArgs *args) override diff --git a/module/jni/unmount.cpp b/module/jni/unmount.cpp index 6f3b016..d50ef09 100644 --- a/module/jni/unmount.cpp +++ b/module/jni/unmount.cpp @@ -16,7 +16,7 @@ static bool shouldUnmount(const mountinfo_entry_t &mount_info) const auto &root = mount_info.getRoot(); // Unmount all module bind mounts - if (root.rfind("/adb/modules", 0) == 0) + if (root.rfind("/adb/", 0) == 0) return true; return false; @@ -95,3 +95,27 @@ void do_unmount() } } } + +void do_remount() +{ + std::vector mounts = parseMountsFromPath("/proc/self/mounts"); + auto data_mount_it = std::find_if(mounts.begin(), mounts.end(), [](const mount_entry_t &mount) + { return mount.getMountPoint() == "/data"; }); + if (data_mount_it != mounts.end()) + { + const auto &options = data_mount_it->getOptions(); + + // If errors=remount-ro, remount it with errors=continue + if (options.find("errors") != options.end() && options.at("errors") == "remount-ro") + { + if (mount(NULL, "/data", NULL, MS_REMOUNT, "errors=continue") == 0) + { + LOGD("mount(NULL, \"/data\", NULL, MS_REMOUNT, \"errors=continue\") returned 0"); + } + else + { + LOGE("mount(NULL, \"/data\", NULL, MS_REMOUNT, \"errors=continue\") returned -1: %d (%s)", errno, strerror(errno)); + } + } + } +}