You've already forked ReZygisk
mirror of
https://github.com/PerformanC/ReZygisk.git
synced 2025-09-06 06:37:01 +00:00
Add flashable module
This commit is contained in:
@@ -19,7 +19,7 @@ namespace zygiskd {
|
||||
|
||||
while (retry--) {
|
||||
int r = connect(fd, reinterpret_cast<struct sockaddr*>(&addr), socklen);
|
||||
if (r != -1) return r;
|
||||
if (r == 0) return fd;
|
||||
LOGW("retrying to connect to zygiskd, sleep 1s");
|
||||
sleep(1);
|
||||
}
|
||||
@@ -27,11 +27,13 @@ namespace zygiskd {
|
||||
}
|
||||
|
||||
bool PingHeartbeat() {
|
||||
LOGD("Daemon socket: %s", kZygiskSocket);
|
||||
auto fd = Connect(5);
|
||||
if (fd == -1) {
|
||||
PLOGE("Connect to zygiskd");
|
||||
return false;
|
||||
}
|
||||
socket_utils::write_u8(fd, (uint8_t) SocketAction::PingHeartBeat);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -45,16 +47,6 @@ namespace zygiskd {
|
||||
return socket_utils::read_string(fd);
|
||||
}
|
||||
|
||||
UniqueFd ReadInjector() {
|
||||
auto fd = Connect(1);
|
||||
if (fd == -1) {
|
||||
PLOGE("ReadInjector");
|
||||
return -1;
|
||||
}
|
||||
socket_utils::write_u8(fd, (uint8_t) SocketAction::ReadInjector);
|
||||
return socket_utils::recv_fd(fd);
|
||||
}
|
||||
|
||||
std::vector<Module> ReadModules() {
|
||||
std::vector<Module> modules;
|
||||
auto fd = Connect(1);
|
||||
|
||||
@@ -75,9 +75,9 @@ namespace socket_utils {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T read_exact(int fd) {
|
||||
inline T read_exact_or(int fd, T fail) {
|
||||
T res;
|
||||
return sizeof(T) == xread(fd, &res, sizeof(T)) ? res : -1;
|
||||
return sizeof(T) == xread(fd, &res, sizeof(T)) ? res : fail;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -86,11 +86,11 @@ namespace socket_utils {
|
||||
}
|
||||
|
||||
size_t read_usize(int fd) {
|
||||
return read_exact<size_t>(fd);
|
||||
return read_exact_or<size_t>(fd, 0);
|
||||
}
|
||||
|
||||
std::string read_string(int fd) {
|
||||
auto len = read_exact<size_t>(fd);
|
||||
auto len = read_usize(fd);
|
||||
char buf[len + 1];
|
||||
buf[len] = '\0';
|
||||
xread(fd, buf, len);
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
# define LP_SELECT(lp32, lp64) lp32
|
||||
#endif
|
||||
|
||||
constexpr std::string_view kZygiskSocket = LP_SELECT("zygisk32", "zygisk64") "placeholder123456";
|
||||
constexpr std::string_view kZygiskSocket = LP_SELECT("zygiskd32", "zygiskd64") "socket_placeholder";
|
||||
|
||||
class UniqueFd {
|
||||
using Fd = int;
|
||||
@@ -52,9 +52,8 @@ namespace zygiskd {
|
||||
};
|
||||
|
||||
enum class SocketAction {
|
||||
HeartBeat,
|
||||
PingHeartBeat,
|
||||
ReadNativeBridge,
|
||||
ReadInjector,
|
||||
ReadModules,
|
||||
RequestCompanionSocket,
|
||||
};
|
||||
@@ -63,7 +62,5 @@ namespace zygiskd {
|
||||
|
||||
std::string ReadNativeBridge();
|
||||
|
||||
UniqueFd ReadInjector();
|
||||
|
||||
std::vector<Module> ReadModules();
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@ extern "C" [[gnu::visibility("default")]]
|
||||
uint8_t NativeBridgeItf[sizeof(NativeBridgeCallbacks<__ANDROID_API_R__>) * 2]{0};
|
||||
|
||||
namespace {
|
||||
constexpr std::array kZygoteProcesses = {"zygote", "zygote32""zygote64", "usap32", "usap64"};
|
||||
constexpr auto kZygoteProcesses = {"zygote", "zygote32", "zygote64", "usap32", "usap64"};
|
||||
constexpr auto kInjector = "/system/" LP_SELECT("lib", "lib64") "/libinjector.so";
|
||||
|
||||
void* sOriginalBridge = nullptr;
|
||||
}
|
||||
@@ -31,9 +32,8 @@ void Constructor() {
|
||||
}
|
||||
|
||||
std::string_view cmdline = getprogname();
|
||||
if (std::any_of(
|
||||
kZygoteProcesses.begin(),
|
||||
kZygoteProcesses.end(),
|
||||
if (std::none_of(
|
||||
kZygoteProcesses.begin(), kZygoteProcesses.end(),
|
||||
[&](const char* p) { return cmdline == p; }
|
||||
)) {
|
||||
LOGW("Not started as zygote (cmdline=%s)", cmdline.data());
|
||||
@@ -49,10 +49,7 @@ void Constructor() {
|
||||
native_bridge = zygiskd::ReadNativeBridge();
|
||||
|
||||
LOGI("Load injector");
|
||||
auto injector = zygiskd::ReadInjector();
|
||||
if (injector != -1) break;
|
||||
|
||||
auto handle = DlopenMem(injector, RTLD_NOW);
|
||||
auto handle = DlopenExt(kInjector, RTLD_NOW);
|
||||
if (handle == nullptr) {
|
||||
LOGE("Failed to dlopen injector: %s", dlerror());
|
||||
break;
|
||||
@@ -60,12 +57,13 @@ void Constructor() {
|
||||
auto entry = dlsym(handle, "entry");
|
||||
if (entry == nullptr) {
|
||||
LOGE("Failed to dlsym injector entry: %s", dlerror());
|
||||
dlclose(handle);
|
||||
break;
|
||||
}
|
||||
reinterpret_cast<void (*)()>(entry)();
|
||||
reinterpret_cast<void (*)(void*)>(entry)(handle);
|
||||
} while (false);
|
||||
|
||||
if (native_bridge.empty()) return;
|
||||
if (native_bridge.empty() || native_bridge == "0") return;
|
||||
LOGI("Load original native bridge: %s", native_bridge.data());
|
||||
sOriginalBridge = dlopen(native_bridge.data(), RTLD_NOW);
|
||||
if (sOriginalBridge == nullptr) {
|
||||
|
||||
Reference in New Issue
Block a user