mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-04-22 14:51:32 +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 <sys/mount.h>
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
#include <xhook.h>
|
#include <xhook.h>
|
||||||
|
|
||||||
@ -54,7 +55,7 @@ struct HookContext {
|
|||||||
} args;
|
} args;
|
||||||
|
|
||||||
const char *process;
|
const char *process;
|
||||||
vector<ZygiskModule> modules;
|
list<ZygiskModule> modules;
|
||||||
|
|
||||||
int pid;
|
int pid;
|
||||||
bitset<FLAG_MAX> flags;
|
bitset<FLAG_MAX> flags;
|
||||||
@ -485,10 +486,6 @@ void HookContext::fork_post() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HookContext::run_modules_pre(const vector<int> &fds) {
|
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) {
|
for (int i = 0; i < fds.size(); ++i) {
|
||||||
struct stat s{};
|
struct stat s{};
|
||||||
if (fstat(fds[i], &s) != 0 || !S_ISREG(s.st_mode)) {
|
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]);
|
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) {
|
for (auto &m : modules) {
|
||||||
m.onLoad(env);
|
|
||||||
if (flags[APP_SPECIALIZE]) {
|
if (flags[APP_SPECIALIZE]) {
|
||||||
m.preAppSpecialize(args.app);
|
m.preAppSpecialize(args.app);
|
||||||
} else if (flags[SERVER_FORK_AND_SPECIALIZE]) {
|
} else if (flags[SERVER_FORK_AND_SPECIALIZE]) {
|
||||||
|
@ -180,6 +180,9 @@ struct ZygiskModule {
|
|||||||
void postServerSpecialize(const ServerSpecializeArgs_v1 *args) const {
|
void postServerSpecialize(const ServerSpecializeArgs_v1 *args) const {
|
||||||
mod.v1->postServerSpecialize(mod.v1->impl, args);
|
mod.v1->postServerSpecialize(mod.v1->impl, args);
|
||||||
}
|
}
|
||||||
|
bool valid() const {
|
||||||
|
return entry.fn && mod.api_version;
|
||||||
|
}
|
||||||
|
|
||||||
int connectCompanion() const;
|
int connectCompanion() const;
|
||||||
int getModuleDir() const;
|
int getModuleDir() const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user