From c6dcff0ae75448750783546e6c960b338abb7245 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 24 Jan 2022 22:30:13 -0800 Subject: [PATCH] Minor dynamic_bitset changes --- native/jni/utils/misc.hpp | 9 ++++++++- native/jni/zygisk/hook.cpp | 5 +---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/native/jni/utils/misc.hpp b/native/jni/utils/misc.hpp index e6ce599f6..9e1916ec4 100644 --- a/native/jni/utils/misc.hpp +++ b/native/jni/utils/misc.hpp @@ -94,8 +94,15 @@ public: } return slot_list[slot][index]; } + bool operator[] (size_t pos) const { + size_t slot = pos / slot_size; + size_t index = pos % slot_size; + return slot_list.size() > slot && slot_list[slot][index]; + } size_t slots() const { return slot_list.size(); } - slot_type get_slot(size_t slot) const { return slot_list[slot].to_ulong(); } + slot_type get_slot(size_t slot) const { + return slot_list.size() > slot ? slot_list[slot].to_ulong() : 0ul; + } private: std::vector slot_list; }; diff --git a/native/jni/zygisk/hook.cpp b/native/jni/zygisk/hook.cpp index 5c3ed9aea..d4d092c50 100644 --- a/native/jni/zygisk/hook.cpp +++ b/native/jni/zygisk/hook.cpp @@ -498,11 +498,8 @@ void HookContext::nativeForkSystemServer_pre() { // Send the bitset of module status back to magiskd from system_server dynamic_bitset bits; - // Pre-allocate enough bits - bits[module_fds.size() - 1] = false; - for (const auto &m : modules) { + for (const auto &m : modules) bits[m.getId()] = true; - } write_int(fd, bits.slots()); for (int i = 0; i < bits.slots(); ++i) { auto l = bits.get_slot(i);