mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-10 16:35:53 +01:00
Update injector.cpp
This commit is contained in:
parent
e91641be57
commit
f573351358
58
injector.cpp
58
injector.cpp
@ -11,21 +11,25 @@
|
||||
#include <sys/uio.h>
|
||||
#include <elf.h>
|
||||
|
||||
// 手动定义 NDK 缺失或隐藏的宏,确保 AArch64 编译通过
|
||||
#ifndef NT_PRSTATUS
|
||||
#define NT_PRSTATUS 1
|
||||
#endif
|
||||
|
||||
#ifndef RTLD_DEFAULT
|
||||
#define RTLD_DEFAULT ((void *) 0LL)
|
||||
#endif
|
||||
|
||||
const char* TARGET_PKG = "com.tencent.tmgp.sgame";
|
||||
const char* LIB_PATH = "/data/local/tmp/libJKMenu.so";
|
||||
|
||||
// 这里的获取方式更适合 Android 高版本
|
||||
uintptr_t get_remote_linker_func(pid_t pid, const char* func_name) {
|
||||
// 尝试直接获取本地地址(通常 linker 加载地址在所有进程中是一致的)
|
||||
void* handle = dlopen("linker64", RTLD_LAZY);
|
||||
if (!handle) handle = dlopen("linker", RTLD_LAZY);
|
||||
uintptr_t addr = (uintptr_t)dlsym(handle, func_name);
|
||||
if (handle) dlclose(handle);
|
||||
return addr;
|
||||
}
|
||||
|
||||
pid_t find_pid(const char* pkg) {
|
||||
DIR* dir = opendir("/proc");
|
||||
if (!dir) return -1;
|
||||
struct dirent* entry;
|
||||
while ((entry = readdir(dir))) {
|
||||
pid_t pid = atoi(entry->d_name);
|
||||
@ -45,10 +49,11 @@ pid_t find_pid(const char* pkg) {
|
||||
|
||||
int main() {
|
||||
pid_t pid = find_pid(TARGET_PKG);
|
||||
if (pid == -1) {
|
||||
printf("[-] SGame not found!\n");
|
||||
return 1;
|
||||
}
|
||||
if (pid == -1) { printf("[-] SGame not found!\n"); return 1; }
|
||||
|
||||
// 获取 dlopen 地址 (尝试 __loader_dlopen)
|
||||
uintptr_t dlopen_addr = get_remote_linker_func(pid, "__loader_dlopen");
|
||||
if (!dlopen_addr) dlopen_addr = (uintptr_t)dlopen; // 最后的保底
|
||||
|
||||
if (ptrace(PTRACE_ATTACH, pid, NULL, NULL) < 0) {
|
||||
perror("[-] Attach failed");
|
||||
@ -57,29 +62,10 @@ int main() {
|
||||
waitpid(pid, NULL, WUNTRACED);
|
||||
|
||||
struct user_pt_regs regs;
|
||||
struct iovec iov;
|
||||
iov.iov_base = ®s;
|
||||
iov.iov_len = sizeof(regs);
|
||||
|
||||
// 显式转换参数类型以通过 NDK 编译器检查
|
||||
if (ptrace(PTRACE_GETREGSET, pid, (void*)(uintptr_t)NT_PRSTATUS, &iov) < 0) {
|
||||
perror("[-] PTRACE_GETREGSET failed");
|
||||
ptrace(PTRACE_DETACH, pid, NULL, NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 获取远程 dlopen (在 Android Linker 中)
|
||||
uintptr_t remote_dlopen = (uintptr_t)dlsym(RTLD_DEFAULT, "__loader_dlopen");
|
||||
if (!remote_dlopen) {
|
||||
remote_dlopen = (uintptr_t)dlsym(RTLD_DEFAULT, "dlopen");
|
||||
}
|
||||
|
||||
if (!remote_dlopen) {
|
||||
printf("[-] Failed to locate dlopen symbols.\n");
|
||||
ptrace(PTRACE_DETACH, pid, NULL, NULL);
|
||||
return 1;
|
||||
}
|
||||
struct iovec iov = { .iov_base = ®s, .iov_len = sizeof(regs) };
|
||||
ptrace(PTRACE_GETREGSET, pid, (void*)(uintptr_t)NT_PRSTATUS, &iov);
|
||||
|
||||
// 写入路径
|
||||
uintptr_t sp = (regs.sp - 512) & ~0xF;
|
||||
size_t len = strlen(LIB_PATH) + 1;
|
||||
for (size_t i = 0; i < len; i += 8) {
|
||||
@ -88,13 +74,15 @@ int main() {
|
||||
ptrace(PTRACE_POKETEXT, pid, (void*)(sp + i), (void*)data);
|
||||
}
|
||||
|
||||
regs.regs[0] = sp; // x0: path
|
||||
regs.regs[1] = 2; // x1: RTLD_NOW
|
||||
regs.pc = remote_dlopen;
|
||||
// 远程调用 dlopen(path, RTLD_NOW)
|
||||
regs.regs[0] = sp;
|
||||
regs.regs[1] = 2;
|
||||
regs.pc = dlopen_addr;
|
||||
|
||||
ptrace(PTRACE_SETREGSET, pid, (void*)(uintptr_t)NT_PRSTATUS, &iov);
|
||||
ptrace(PTRACE_DETACH, pid, NULL, NULL);
|
||||
|
||||
printf("[+] Injecting into SGame (PID: %d)...\n", pid);
|
||||
printf("[+] Remote dlopen address: %lx\n", (long)dlopen_addr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user