From 55ed6109c12ee3cfcef91d7f8d38dc3d4ac8d279 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Fri, 11 Feb 2022 01:00:58 -0800 Subject: [PATCH] Use dynamic_bitset.emplace_back() --- native/jni/utils/misc.hpp | 3 +++ native/jni/zygisk/entry.cpp | 24 ++++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/native/jni/utils/misc.hpp b/native/jni/utils/misc.hpp index 079c5fa63..8a8828dcc 100644 --- a/native/jni/utils/misc.hpp +++ b/native/jni/utils/misc.hpp @@ -93,6 +93,9 @@ public: slot_type get_slot(size_t slot) const { return slot_list.size() > slot ? slot_list[slot].to_ulong() : 0ul; } + void emplace_back(slot_type l) { + slot_list.emplace_back(l); + } protected: slot_bits::reference get(size_t pos) { size_t slot = pos / slot_size; diff --git a/native/jni/zygisk/entry.cpp b/native/jni/zygisk/entry.cpp index 2f428aa63..670bd9129 100644 --- a/native/jni/zygisk/entry.cpp +++ b/native/jni/zygisk/entry.cpp @@ -367,21 +367,21 @@ static void get_process_info(int client, const sock_cred *cred) { // Collect module status from system_server int slots = read_int(client); - int id = 0; + dynamic_bitset bits; for (int i = 0; i < slots; ++i) { dynamic_bitset::slot_type l = 0; xxread(client, &l, sizeof(l)); - dynamic_bitset::slot_bits bits(l); - for (int j = 0; id < module_list->size(); ++j, ++id) { - if (!bits[j]) { - // Either not a zygisk module, or incompatible - char buf[4096]; - snprintf(buf, sizeof(buf), MODULEROOT "/%s/zygisk", - module_list->operator[](id).name.data()); - if (int dirfd = open(buf, O_RDONLY | O_CLOEXEC); dirfd >= 0) { - close(xopenat(dirfd, "unloaded", O_CREAT | O_RDONLY, 0644)); - close(dirfd); - } + bits.emplace_back(l); + } + for (int id = 0; id < module_list->size(); ++id) { + if (!as_const(bits)[id]) { + // Either not a zygisk module, or incompatible + char buf[4096]; + snprintf(buf, sizeof(buf), MODULEROOT "/%s/zygisk", + module_list->operator[](id).name.data()); + if (int dirfd = open(buf, O_RDONLY | O_CLOEXEC); dirfd >= 0) { + close(xopenat(dirfd, "unloaded", O_CREAT | O_RDONLY, 0644)); + close(dirfd); } } }