mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-02-17 13:28:29 +00:00
Fix crashes whenever a zygisk module has ver > 4
This commit is contained in:
parent
11b2ddbad8
commit
cd5384f13e
@ -2,6 +2,7 @@
|
||||
#include <sys/mount.h>
|
||||
#include <dlfcn.h>
|
||||
#include <bitset>
|
||||
#include <list>
|
||||
|
||||
#include <xhook.h>
|
||||
|
||||
@ -54,7 +55,7 @@ struct HookContext {
|
||||
} args;
|
||||
|
||||
const char *process;
|
||||
vector<ZygiskModule> modules;
|
||||
list<ZygiskModule> modules;
|
||||
|
||||
int pid;
|
||||
bitset<FLAG_MAX> flags;
|
||||
@ -485,10 +486,6 @@ void HookContext::fork_post() {
|
||||
}
|
||||
|
||||
void HookContext::run_modules_pre(const vector<int> &fds) {
|
||||
// Because the data structure stored in the vector is self referencing, in order to prevent
|
||||
// dangling pointers, the vector has to be pre-allocated to ensure reallocation does not occur
|
||||
modules.reserve(fds.size());
|
||||
|
||||
for (int i = 0; i < fds.size(); ++i) {
|
||||
struct stat s{};
|
||||
if (fstat(fds[i], &s) != 0 || !S_ISREG(s.st_mode)) {
|
||||
@ -509,8 +506,16 @@ void HookContext::run_modules_pre(const vector<int> &fds) {
|
||||
close(fds[i]);
|
||||
}
|
||||
|
||||
for (auto it = modules.begin(); it != modules.end();) {
|
||||
it->onLoad(env);
|
||||
if (it->valid()) {
|
||||
++it;
|
||||
} else {
|
||||
it = modules.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &m : modules) {
|
||||
m.onLoad(env);
|
||||
if (flags[APP_SPECIALIZE]) {
|
||||
m.preAppSpecialize(args.app);
|
||||
} else if (flags[SERVER_FORK_AND_SPECIALIZE]) {
|
||||
|
@ -180,6 +180,9 @@ struct ZygiskModule {
|
||||
void postServerSpecialize(const ServerSpecializeArgs_v1 *args) const {
|
||||
mod.v1->postServerSpecialize(mod.v1->impl, args);
|
||||
}
|
||||
bool valid() const {
|
||||
return entry.fn && mod.api_version;
|
||||
}
|
||||
|
||||
int connectCompanion() const;
|
||||
int getModuleDir() const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user