Magisk/native/jni/zygisk/inject.hpp
topjohnwu 12647dcf30 Improve memory map tricks
- In `unmap_all`, replace readable pages atomically with mmap + mremap
- Create new function `remap_all` to replace pages with equivalent
  anonymous copies to prevent simple maps name scanning
2021-09-22 19:14:05 -07:00

38 lines
883 B
C++

#pragma once
#include <stdint.h>
#include <jni.h>
#define INJECT_ENV_1 "MAGISK_INJ_1"
#define INJECT_ENV_2 "MAGISK_INJ_2"
enum : int {
ZYGISK_SETUP,
ZYGISK_GET_APPINFO,
ZYGISK_UNMOUNT,
ZYGISK_GET_LOG_PIPE,
};
// Unmap all pages matching the name
void unmap_all(const char *name);
// Remap all matching pages with anonymous pages
void remap_all(const char *name);
// Get library name + offset (from start of ELF), given function address
uintptr_t get_function_off(int pid, uintptr_t addr, char *lib);
// Get function address, given library name + offset
uintptr_t get_function_addr(int pid, const char *lib, uintptr_t off);
struct AppInfo {
bool is_magisk_app;
bool on_denylist;
};
void self_unload();
void hook_functions();
bool unhook_functions();
void remote_get_app_info(int uid, const char *process, AppInfo *info);
int remote_request_unmount();