Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove further detection points #104

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 32 additions & 15 deletions loader/src/common/daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,6 @@ namespace zygiskd {
return true;
}

int RequestLogcatFd() {
int fd = Connect(1);
if (fd == -1) {
PLOGE("RequestLogcatFd");

return -1;
}

socket_utils::write_u8(fd, (uint8_t) SocketAction::RequestLogcatFd);

return fd;
}

uint32_t GetProcessFlags(uid_t uid) {
int fd = Connect(1);
if (fd == -1) {
Expand All @@ -94,8 +81,8 @@ namespace zygiskd {
return res;
}

std::vector<Module> ReadModules() {
std::vector<Module> modules;
std::vector<ModuleInfo> ReadModules() {
std::vector<ModuleInfo> modules;
int fd = Connect(1);
if (fd == -1) {
PLOGE("ReadModules");
Expand Down Expand Up @@ -260,4 +247,34 @@ namespace zygiskd {
close(fd);
} else info->running = false;
}

std::string UpdateMountNamespace(enum mount_namespace_state nms_state) {
int fd = Connect(1);
if (fd == -1) {
PLOGE("UpdateMountNamespace");

return "";
}

socket_utils::write_u8(fd, (uint8_t) SocketAction::UpdateMountNamespace);
socket_utils::write_u32(fd, getpid());
socket_utils::write_u8(fd, (uint8_t)nms_state);

uint32_t target_pid = socket_utils::read_u32(fd);
int target_fd = 0;

if (target_pid == 0) goto error;

target_fd = (int)socket_utils::read_u32(fd);
if (target_fd == 0) goto error;

close(fd);

return "/proc/" + std::to_string(target_pid) + "/fd/" + std::to_string(target_fd);

error:
close(fd);

return "";
}
}
9 changes: 7 additions & 2 deletions loader/src/common/dl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ void* DlopenExt(const char* path, int flags) {
}

void* DlopenMem(int fd, int flags) {
auto info = android_dlextinfo{
auto info = android_dlextinfo {
.flags = ANDROID_DLEXT_USE_LIBRARY_FD,
.library_fd = fd
.reserved_addr = NULL,
.reserved_size = 0,
.relro_fd = 0,
.library_fd = fd,
.library_fd_offset = 0,
.library_namespace = NULL
};

auto* handle = android_dlopen_ext("/jit-cache-zygisk", flags, &info);
Expand Down
36 changes: 0 additions & 36 deletions loader/src/common/logging.cpp

This file was deleted.

18 changes: 12 additions & 6 deletions loader/src/include/daemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,31 @@ struct zygote_info {
bool running;
};

enum mount_namespace_state {
Clean,
Rooted,
Module
};

namespace zygiskd {

struct Module {
struct ModuleInfo {
std::string name;
UniqueFd memfd;

inline explicit Module(std::string name, int memfd) : name(name), memfd(memfd) {}
inline explicit ModuleInfo(std::string name, int memfd) : name(name), memfd(memfd) {}
};

enum class SocketAction {
PingHeartBeat,
RequestLogcatFd,
GetProcessFlags,
GetInfo,
ReadModules,
RequestCompanionSocket,
GetModuleDir,
ZygoteRestart,
SystemServerStarted,
UpdateMountNamespace
};

void Init(const char *path);
Expand All @@ -88,9 +94,7 @@ namespace zygiskd {

bool PingHeartbeat();

int RequestLogcatFd();

std::vector<Module> ReadModules();
std::vector<ModuleInfo> ReadModules();

uint32_t GetProcessFlags(uid_t uid);

Expand All @@ -103,4 +107,6 @@ namespace zygiskd {
void SystemServerStarted();

void GetInfo(struct zygote_info *info);

std::string UpdateMountNamespace(enum mount_namespace_state mns_state);
}
39 changes: 17 additions & 22 deletions loader/src/include/logging.h
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
#pragma once
#ifndef LOGGING_H
#define LOGGING_H

#include <android/log.h>
#include <errno.h>
#include <string.h>

#ifndef LOG_TAG
#if defined(__LP64__)
# define LOG_TAG "zygisk-core64"
#else
# define LOG_TAG "zygisk-core32"
#endif
#ifdef __LP64__
#define LOG_TAG "zygisk-core64"
#else
#define LOG_TAG "zygisk-core32"
#endif
#endif

#ifndef NDEBUG
#define LOGD(...) logging::log(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
#define LOGV(...) logging::log(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)
#else
#define LOGD(...)
#define LOGV(...)
#define LOGD(...)
#define LOGV(...)
#endif
#define LOGI(...) logging::log(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
#define LOGW(...) logging::log(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)
#define LOGE(...) logging::log(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
#define LOGF(...) logging::log(ANDROID_LOG_FATAL, LOG_TAG, __VA_ARGS__)
#define PLOGE(fmt, args...) LOGE(fmt " failed with %d: %s", ##args, errno, strerror(errno))

namespace logging {
void setfd(int fd);

int getfd();
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
#define LOGF(...) __android_log_print(ANDROID_LOG_FATAL, LOG_TAG, __VA_ARGS__)
#define PLOGE(fmt, args...) LOGE(fmt " failed with %d: %s", ##args, errno, strerror(errno))

[[gnu::format(printf, 3, 4)]]
void log(int prio, const char* tag, const char* fmt, ...);
}
#endif /* LOGGING_H */
4 changes: 2 additions & 2 deletions loader/src/include/solist.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ namespace SoList {
for (auto iter = solist; iter; iter = iter->get_next()) {
if (iter->get_name() && iter->get_path() && strstr(iter->get_path(), target_path)) {
SoList::ProtectedDataGuard guard;
LOGI("dropping solist record for %s loaded at %s with size %zu", iter->get_name(), iter->get_path(), iter->get_size());
LOGV("dropping solist record for %s loaded at %s with size %zu", iter->get_name(), iter->get_path(), iter->get_size());
if (iter->get_size() > 0) {
iter->set_size(0);
SoInfo::soinfo_free(iter);
Expand All @@ -136,7 +136,7 @@ namespace SoList {
return;
}
if (g_module_load_counter == NULL || g_module_unload_counter == NULL) {
LOGI("g_module counters not defined, skip reseting them");
LOGD("g_module counters not defined, skip reseting them");
return;
}
auto loaded_modules = *g_module_load_counter;
Expand Down
8 changes: 2 additions & 6 deletions loader/src/injector/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ size_t block_size = 0;

extern "C" [[gnu::visibility("default")]]
void entry(void* addr, size_t size, const char* path) {
LOGI("Zygisk library injected, version %s", ZKSU_VERSION);
LOGD("Zygisk library injected, version %s", ZKSU_VERSION);
start_addr = addr;
block_size = size;
zygiskd::Init(path);
Expand All @@ -19,11 +19,7 @@ void entry(void* addr, size_t size, const char* path) {
return;
}

#ifdef NDEBUG
logging::setfd(zygiskd::RequestLogcatFd());
#endif

LOGI("start plt hooking");
LOGD("start plt hooking");
hook_functions();
clean_trace(path, 1, 0, false);
}
Loading
Loading