diff --git a/native/jni/utils/misc.hpp b/native/jni/utils/misc.hpp index 1de8c4395..e6ce599f6 100644 --- a/native/jni/utils/misc.hpp +++ b/native/jni/utils/misc.hpp @@ -81,21 +81,23 @@ public: }; class dynamic_bitset { -private: - using long_bits = std::bitset; - std::vector bits; public: - constexpr static int slot_size = sizeof(unsigned long); - long_bits::reference operator[] (size_t pos) { + using slot_type = unsigned long; + constexpr static int slot_size = sizeof(slot_type) * 8; + using slot_bits = std::bitset; + + slot_bits::reference operator[] (size_t pos) { size_t slot = pos / slot_size; size_t index = pos % slot_size; - if (bits.size() <= slot) { - bits.resize(slot + 1); + if (slot_list.size() <= slot) { + slot_list.resize(slot + 1); } - return bits[slot][index]; + return slot_list[slot][index]; } - size_t slots() const { return bits.size(); } - unsigned long to_ulong(size_t slot) const { return bits[slot].to_ulong(); } + size_t slots() const { return slot_list.size(); } + slot_type get_slot(size_t slot) const { return slot_list[slot].to_ulong(); } +private: + std::vector slot_list; }; int parse_int(std::string_view s); diff --git a/native/jni/zygisk/entry.cpp b/native/jni/zygisk/entry.cpp index 4250f81bc..97597162e 100644 --- a/native/jni/zygisk/entry.cpp +++ b/native/jni/zygisk/entry.cpp @@ -362,9 +362,9 @@ static void get_process_info(int client, const sock_cred *cred) { int slots = read_int(client); int id = 0; for (int i = 0; i < slots; ++i) { - unsigned long l = 0; + dynamic_bitset::slot_type l = 0; xxread(client, &l, sizeof(l)); - bitset bits(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 diff --git a/native/jni/zygisk/hook.cpp b/native/jni/zygisk/hook.cpp index 3649f8c8b..5c3ed9aea 100644 --- a/native/jni/zygisk/hook.cpp +++ b/native/jni/zygisk/hook.cpp @@ -505,7 +505,7 @@ void HookContext::nativeForkSystemServer_pre() { } write_int(fd, bits.slots()); for (int i = 0; i < bits.slots(); ++i) { - unsigned long l = bits.to_ulong(i); + auto l = bits.get_slot(i); xwrite(fd, &l, sizeof(l)); } }