mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-24 18:57:37 +00:00
Fix dynamic_bitset implementation
This commit is contained in:
parent
407dfc7547
commit
cbe97cdfde
@ -81,21 +81,23 @@ public:
|
||||
};
|
||||
|
||||
class dynamic_bitset {
|
||||
private:
|
||||
using long_bits = std::bitset<sizeof(unsigned long)>;
|
||||
std::vector<long_bits> 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_size>;
|
||||
|
||||
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_bits> slot_list;
|
||||
};
|
||||
|
||||
int parse_int(std::string_view s);
|
||||
|
@ -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<sizeof(unsigned long)> 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
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user