From f9eea8aef777f993fc2faaebdffad0085f8b832f Mon Sep 17 00:00:00 2001 From: YZBruh Date: Sun, 10 Aug 2025 22:16:12 +0300 Subject: [PATCH] rebootFunction: Allow reboot function in ADB without root --- USAGE.md | 2 +- include/PartitionManager/PartitionManager.hpp | 1 + src/FunctionManager.cpp | 8 ++++++++ src/PartitionManager.cpp | 8 +++++--- srclib/libhelper/include/libhelper/lib.hpp | 1 + srclib/libhelper/src/Checkers.cpp | 1 + 6 files changed, 17 insertions(+), 4 deletions(-) diff --git a/USAGE.md b/USAGE.md index bcd9190..bf00c87 100644 --- a/USAGE.md +++ b/USAGE.md @@ -187,7 +187,7 @@ pmt type partition(s) [OPTIONS] --- ### 9. `reboot` -Reboot the device. Default reboot target is normal. General syntax: +Reboot the device. Default reboot target is normal. If you are using it via ADB terminal, you **DO NOT** need root to use this feature. General syntax: ```bash pmt reboot [rebootTarget] [OPTIONS] ``` diff --git a/include/PartitionManager/PartitionManager.hpp b/include/PartitionManager/PartitionManager.hpp index 657955d..761bc1f 100644 --- a/include/PartitionManager/PartitionManager.hpp +++ b/include/PartitionManager/PartitionManager.hpp @@ -55,6 +55,7 @@ private: public: void registerFunction(std::unique_ptr _func, CLI::App &_app); + [[nodiscard]] bool isUsed(std::string name) const; [[nodiscard]] bool handleAll() const; }; diff --git a/src/FunctionManager.cpp b/src/FunctionManager.cpp index 9433959..638f660 100644 --- a/src/FunctionManager.cpp +++ b/src/FunctionManager.cpp @@ -69,6 +69,14 @@ void basic_function_manager::registerFunction( << std::endl; } +bool basic_function_manager::isUsed(const std::string name) const { + if (_functions.empty()) return false; + for (const auto &func : _functions) { + if (func->name() == name) return func->isUsed(); + } + return false; +} + bool basic_function_manager::handleAll() const { LOGN(PMTF, INFO) << "running caught function commands in command-line." << std::endl; diff --git a/src/PartitionManager.cpp b/src/PartitionManager.cpp index ae1d39b..15a2027 100644 --- a/src/PartitionManager.cpp +++ b/src/PartitionManager.cpp @@ -112,9 +112,11 @@ int Main(int argc, char **argv) { "directory with -S " "(--search-path)"); - if (!Helper::hasSuperUser()) - throw Error( - "Partition Manager Tool is requires super-user privileges!\n"); + if (!Helper::hasSuperUser()) { + if (!(FuncManager.isUsed("reboot") && Helper::hasAdbPermissions())) + throw Error( + "Partition Manager Tool is requires super-user privileges!\n"); + } return FuncManager.handleAll() == true ? EXIT_SUCCESS : EXIT_FAILURE; } catch (Helper::Error &error) { diff --git a/srclib/libhelper/include/libhelper/lib.hpp b/srclib/libhelper/include/libhelper/lib.hpp index 89def3f..ccb0008 100644 --- a/srclib/libhelper/include/libhelper/lib.hpp +++ b/srclib/libhelper/include/libhelper/lib.hpp @@ -105,6 +105,7 @@ void reset(); // Checkers bool hasSuperUser(); +bool hasAdbPermissions(); bool isExists(std::string_view entry); bool fileIsExists(std::string_view file); bool directoryIsExists(std::string_view directory); diff --git a/srclib/libhelper/src/Checkers.cpp b/srclib/libhelper/src/Checkers.cpp index 1afe4a4..1c2f8a9 100644 --- a/srclib/libhelper/src/Checkers.cpp +++ b/srclib/libhelper/src/Checkers.cpp @@ -23,6 +23,7 @@ namespace Helper { bool hasSuperUser() { return (getuid() == AID_ROOT); } +bool hasAdbPermissions() { return (getuid() == AID_ADB); } bool isExists(const std::string_view entry) { struct stat st{};