mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-04-29 22:14:27 +02:00
core: search for first available dir in PATH
This commit is contained in:
parent
9a74e19117
commit
4d80361805
@ -233,10 +233,21 @@ private:
|
||||
};
|
||||
|
||||
static void inject_magisk_bins(root_node *system) {
|
||||
auto bin = system->get_child<inter_node>("bin");
|
||||
dir_node* bin = system->get_child<inter_node>("bin");
|
||||
if (!bin) {
|
||||
bin = new inter_node("bin");
|
||||
system->insert(bin);
|
||||
struct stat st{};
|
||||
bin = system;
|
||||
for (auto &item: split(getenv("PATH"), ":")) {
|
||||
item.erase(0, item.starts_with("/system/") ? 8 : 1);
|
||||
auto system_path = "/system/" + item;
|
||||
if (stat(system_path.data(), &st) == 0 && st.st_mode & S_IXOTH) {
|
||||
for (const auto &dir: split(item, "/")) {
|
||||
auto node = bin->get_child<inter_node>(dir);
|
||||
bin = node ? node : bin->emplace<inter_node>(dir, dir.data());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Insert binaries
|
||||
|
Loading…
x
Reference in New Issue
Block a user