You've already forked ReZygisk
mirror of
https://github.com/PerformanC/ReZygisk.git
synced 2025-09-06 06:37:01 +00:00
use /debug_ramdisk
This commit is contained in:
@@ -12,8 +12,7 @@
|
||||
#endif
|
||||
|
||||
constexpr auto kCPSocketName = "/" LP_SELECT("cp32", "cp64") ".sock";
|
||||
constexpr const auto MAGIC_PATH_ENV = "MAGIC_PATH";
|
||||
constexpr const auto MAGIC_ENV = "MAGIC";
|
||||
#define TMP_PATH "/debug_ramdisk/zygisksu"
|
||||
|
||||
class UniqueFd {
|
||||
using Fd = int;
|
||||
@@ -63,7 +62,7 @@ namespace zygiskd {
|
||||
ZygoteRestart,
|
||||
};
|
||||
|
||||
void Init(const char *path);
|
||||
void Init(const char *path = TMP_PATH);
|
||||
|
||||
bool PingHeartbeat();
|
||||
|
||||
|
||||
@@ -8,11 +8,11 @@ using namespace std;
|
||||
void *self_handle = nullptr;
|
||||
|
||||
extern "C" [[gnu::visibility("default")]]
|
||||
void entry(void* handle, const char* path) {
|
||||
void entry(void* handle) {
|
||||
LOGI("Zygisk library injected, version %s", ZKSU_VERSION);
|
||||
self_handle = handle;
|
||||
|
||||
zygiskd::Init(path);
|
||||
zygiskd::Init();
|
||||
if (!zygiskd::PingHeartbeat()) {
|
||||
LOGE("Zygisk daemon is not running");
|
||||
return;
|
||||
|
||||
@@ -19,7 +19,7 @@ int main(int argc, char **argv) {
|
||||
return 0;
|
||||
} else if (argc >= 3 && argv[1] == "trace"sv) {
|
||||
if (argc >= 4 && argv[3] == "--restart"sv) {
|
||||
zygiskd::Init(getenv(MAGIC_PATH_ENV));
|
||||
zygiskd::Init();
|
||||
zygiskd::ZygoteRestart();
|
||||
}
|
||||
auto pid = strtol(argv[2], 0, 0);
|
||||
|
||||
@@ -37,13 +37,7 @@ enum TracingState {
|
||||
|
||||
std::string monitor_stop_reason;
|
||||
|
||||
constexpr char SOCKET_NAME[] = "init_monitor";
|
||||
|
||||
std::string GetControlSocketName() {
|
||||
auto env = getenv(MAGIC_ENV);
|
||||
if (env == nullptr) return SOCKET_NAME;
|
||||
return std::string(SOCKET_NAME) + env;
|
||||
}
|
||||
constexpr char SOCKET_NAME[] = TMP_PATH "/init_monitor";
|
||||
|
||||
struct EventLoop;
|
||||
|
||||
@@ -141,9 +135,8 @@ struct SocketHandler : public EventHandler {
|
||||
.sun_family = AF_UNIX,
|
||||
.sun_path={0},
|
||||
};
|
||||
auto socket_name = GetControlSocketName();
|
||||
strcpy(addr.sun_path + 1, socket_name.c_str());
|
||||
socklen_t socklen = sizeof(sa_family_t) + strlen(addr.sun_path + 1) + 1;
|
||||
strcpy(addr.sun_path, SOCKET_NAME);
|
||||
socklen_t socklen = sizeof(sa_family_t) + strlen(addr.sun_path);
|
||||
if (bind(sock_fd_, (struct sockaddr *) &addr, socklen) == -1) {
|
||||
PLOGE("bind socket");
|
||||
return false;
|
||||
@@ -542,12 +535,7 @@ static void updateStatus() {
|
||||
}
|
||||
|
||||
static bool prepare_environment() {
|
||||
auto path = getenv(MAGIC_PATH_ENV);
|
||||
if (path == nullptr) {
|
||||
LOGE("path is null, is MAGIC_PATH_ENV specified?");
|
||||
return false;
|
||||
}
|
||||
prop_path = std::string(path) + "/module.prop";
|
||||
prop_path = TMP_PATH "/module.prop";
|
||||
close(open(prop_path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644));
|
||||
auto orig_prop = xopen_file("./module.prop", "r");
|
||||
if (orig_prop == nullptr) {
|
||||
@@ -618,9 +606,8 @@ void send_control_command(Command cmd) {
|
||||
.sun_family = AF_UNIX,
|
||||
.sun_path={0},
|
||||
};
|
||||
auto socket_name = GetControlSocketName();
|
||||
strcpy(addr.sun_path + 1, socket_name.c_str());
|
||||
socklen_t socklen = sizeof(sa_family_t) + strlen(addr.sun_path + 1) + 1;
|
||||
strcpy(addr.sun_path, SOCKET_NAME);
|
||||
socklen_t socklen = sizeof(sa_family_t) + strlen(addr.sun_path);
|
||||
auto nsend = sendto(sockfd, (void *) &cmd, sizeof(cmd), 0, (sockaddr *) &addr, socklen);
|
||||
if (nsend == -1) {
|
||||
err(EXIT_FAILURE, "send");
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <string>
|
||||
#include "utils.hpp"
|
||||
|
||||
bool inject_on_main(int pid, const char *lib_path, const char* magic_path) {
|
||||
bool inject_on_main(int pid, const char *lib_path) {
|
||||
LOGI("injecting %s to zygote %d", lib_path, pid);
|
||||
// parsing KernelArgumentBlock
|
||||
// https://cs.android.com/android/platform/superproject/main/+/main:bionic/libc/private/KernelArgumentBlock.h;l=30;drc=6d1ee77ee32220e4202c3066f7e1f69572967ad8
|
||||
@@ -145,8 +145,6 @@ bool inject_on_main(int pid, const char *lib_path, const char* magic_path) {
|
||||
// call injector entry(handle, magic)
|
||||
args.clear();
|
||||
args.push_back(remote_handle);
|
||||
str = push_string(pid, regs, magic_path);
|
||||
args.push_back((long) str);
|
||||
remote_call(pid, regs, injector_entry, (uintptr_t) libc_return_addr, args);
|
||||
|
||||
// reset pc to entry
|
||||
@@ -180,9 +178,9 @@ bool trace_zygote(int pid) {
|
||||
}
|
||||
WAIT_OR_DIE
|
||||
if (STOPPED_WITH(SIGSTOP, PTRACE_EVENT_STOP)) {
|
||||
std::string magic_path = getenv(MAGIC_PATH_ENV);
|
||||
std::string lib_path = magic_path + "/lib" LP_SELECT("", "64") "/libzygisk.so";
|
||||
if (!inject_on_main(pid, lib_path.c_str(), magic_path.c_str())) {
|
||||
std::string lib_path = TMP_PATH;
|
||||
lib_path += "/lib" LP_SELECT("", "64") "/libzygisk.so";
|
||||
if (!inject_on_main(pid, lib_path.c_str())) {
|
||||
LOGE("failed to inject");
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user