mirror of
https://github.com/kdrag0n/safetynet-fix.git
synced 2024-11-19 11:11:22 +00:00
59 lines
1.5 KiB
C++
59 lines
1.5 KiB
C++
#include <cstdlib>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <android/log.h>
|
|
|
|
#include "zygisk.hpp"
|
|
|
|
using zygisk::Api;
|
|
using zygisk::AppSpecializeArgs;
|
|
using zygisk::ServerSpecializeArgs;
|
|
|
|
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, "Magisk", __VA_ARGS__)
|
|
|
|
class MyModule : public zygisk::ModuleBase {
|
|
public:
|
|
void onLoad(Api *api, JNIEnv *env) override {
|
|
this->api = api;
|
|
this->env = env;
|
|
}
|
|
|
|
void preAppSpecialize(AppSpecializeArgs *args) override {
|
|
// Use JNI to fetch our process name
|
|
const char *process = env->GetStringUTFChars(args->nice_name, nullptr);
|
|
preSpecialize(process);
|
|
env->ReleaseStringUTFChars(args->nice_name, process);
|
|
}
|
|
|
|
void preServerSpecialize(ServerSpecializeArgs *args) override {
|
|
preSpecialize("system_server");
|
|
}
|
|
|
|
private:
|
|
Api *api;
|
|
JNIEnv *env;
|
|
|
|
void preSpecialize(const char *process) {
|
|
// Demonstrate connecting to to companion process
|
|
// We ask the companion for a random number
|
|
int r = 0;
|
|
int fd = api->connectCompanion();
|
|
read(fd, &r, sizeof(r));
|
|
close(fd);
|
|
LOGD("example: process=[%s], r=[%u]\n", process, r);
|
|
}
|
|
|
|
};
|
|
|
|
static void companion_handler(int i) {
|
|
int fd = open("/dev/urandom", O_RDONLY);
|
|
int r;
|
|
read(fd, &r, sizeof(r));
|
|
close(fd);
|
|
LOGD("example: companion r=[%u]\n", r);
|
|
write(i, &r, sizeof(r));
|
|
}
|
|
|
|
REGISTER_ZYGISK_MODULE(MyModule)
|
|
REGISTER_ZYGISK_COMPANION(companion_handler)
|