2021-01-06 22:21:17 -08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2021-01-08 05:25:44 -08:00
|
|
|
#include <jni.h>
|
2021-10-13 04:52:02 -07:00
|
|
|
#include <vector>
|
2022-02-12 23:43:36 +08:00
|
|
|
#include <daemon.hpp>
|
2021-01-06 22:21:17 -08:00
|
|
|
|
2022-02-06 16:27:31 +08:00
|
|
|
#define INJECT_ENV_1 "MAGISK_INJ_1"
|
|
|
|
#define INJECT_ENV_2 "MAGISK_INJ_2"
|
|
|
|
#define MAGISKFD_ENV "MAGISKFD"
|
|
|
|
#define MAGISKTMP_ENV "MAGISKTMP"
|
2021-01-06 22:21:17 -08:00
|
|
|
|
2022-03-01 02:13:18 -08:00
|
|
|
namespace ZygiskRequest {
|
|
|
|
enum : int {
|
2022-02-12 23:43:36 +08:00
|
|
|
SETUP,
|
|
|
|
GET_INFO,
|
|
|
|
GET_LOG_PIPE,
|
|
|
|
CONNECT_COMPANION,
|
|
|
|
GET_MODDIR,
|
|
|
|
PASSTHROUGH,
|
|
|
|
END
|
2021-08-18 03:44:32 -07:00
|
|
|
};
|
2022-03-01 02:13:18 -08:00
|
|
|
}
|
2021-08-18 03:44:32 -07:00
|
|
|
|
2021-10-14 02:13:23 -07:00
|
|
|
#if defined(__LP64__)
|
|
|
|
#define ZLOGD(...) LOGD("zygisk64: " __VA_ARGS__)
|
|
|
|
#define ZLOGE(...) LOGE("zygisk64: " __VA_ARGS__)
|
|
|
|
#define ZLOGI(...) LOGI("zygisk64: " __VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define ZLOGD(...) LOGD("zygisk32: " __VA_ARGS__)
|
|
|
|
#define ZLOGE(...) LOGE("zygisk32: " __VA_ARGS__)
|
|
|
|
#define ZLOGI(...) LOGI("zygisk32: " __VA_ARGS__)
|
|
|
|
#endif
|
|
|
|
|
2022-02-06 16:27:31 +08:00
|
|
|
// Find the memory address + size of the pages matching name + inode
|
|
|
|
std::pair<void*, size_t> find_map_range(const char *name, unsigned long inode);
|
|
|
|
|
2021-01-06 22:21:17 -08:00
|
|
|
// Unmap all pages matching the name
|
|
|
|
void unmap_all(const char *name);
|
|
|
|
|
2021-09-22 19:14:05 -07:00
|
|
|
// Remap all matching pages with anonymous pages
|
|
|
|
void remap_all(const char *name);
|
|
|
|
|
2021-08-11 00:00:21 -07:00
|
|
|
// Get library name + offset (from start of ELF), given function address
|
|
|
|
uintptr_t get_function_off(int pid, uintptr_t addr, char *lib);
|
2021-01-06 22:21:17 -08:00
|
|
|
|
2021-08-11 00:00:21 -07:00
|
|
|
// Get function address, given library name + offset
|
|
|
|
uintptr_t get_function_addr(int pid, const char *lib, uintptr_t off);
|
2021-01-08 00:53:24 -08:00
|
|
|
|
2021-11-07 13:05:44 -08:00
|
|
|
extern void *self_handle;
|
|
|
|
|
2021-01-08 00:53:24 -08:00
|
|
|
void hook_functions();
|
2022-01-21 04:43:27 -08:00
|
|
|
int remote_get_info(int uid, const char *process, uint32_t *flags, std::vector<int> &fds);
|
2021-08-19 04:55:17 -07:00
|
|
|
int remote_request_unmount();
|
2022-02-12 23:43:36 +08:00
|
|
|
|
2022-03-01 02:13:18 -08:00
|
|
|
inline int zygisk_request(int req) {
|
|
|
|
int fd = connect_daemon(MainRequest::ZYGISK);
|
|
|
|
write_int(fd, req);
|
2022-02-12 23:43:36 +08:00
|
|
|
return fd;
|
|
|
|
}
|