Update main.cpp

This commit is contained in:
gggaa2152 2026-04-06 04:43:48 +08:00 committed by GitHub
parent b60b5ac44c
commit f291ca3206
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4,21 +4,22 @@
#include <android/log.h>
#include <string.h>
#include <sys/mman.h>
#include "dobby.h" // 确保项目中有 dobby.h
#include <stdio.h> // 新增:修复 FILE, fopen 报错
#include <stdlib.h> // 新增:修复 strtoull 报错
#include "dobby.h"
#define TAG "JKMenu_SGame"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
// 模拟你的 Hook 目标(请根据实际偏移修改)
// 假设你要 Hook libUnity.so 或 libGameCore.so
// 获取模块基址
uintptr_t get_module_base(const char* name) {
FILE* fp = fopen("/proc/self/maps", "r");
char line[1024];
uintptr_t base = 0;
while (fp && fgets(line, sizeof(line), fp)) {
if (strstr(line, name)) {
base = strtoull(line, NULL, 16);
base = (uintptr_t)strtoull(line, NULL, 16);
break;
}
}
@ -32,33 +33,30 @@ void* init_thread(void*) {
uintptr_t game_base = 0;
int retry = 0;
// 1. 等待游戏主核心库加载(王者荣耀通常是 libGameCore.so 或 libunity.so)
// 王者荣耀核心库通常是 libGameCore.so 或 Unity 环境下的 libunity.so
// 我们先循环检测,直到库加载完成
while (game_base == 0 && retry < 60) {
game_base = get_module_base("libGameCore.so"); // 尝试获取核心库
game_base = get_module_base("libGameCore.so");
if (game_base == 0) {
if (retry % 5 == 0) LOGI("Waiting for libGameCore.so... (retry %d)", retry);
game_base = get_module_base("libunity.so"); // 兼容性检测
}
if (game_base == 0) {
if (retry % 5 == 0) LOGI("Waiting for game libraries... (retry %d)", retry);
sleep(1);
retry++;
}
}
if (game_base == 0) {
LOGE("Error: libGameCore.so not found after 60s, exiting thread.");
LOGE("Error: Game core library not found after 60s.");
return nullptr;
}
LOGI("Found libGameCore.so at: %p", (void*)game_base);
LOGI("Found game base at: %p", (void*)game_base);
// 2. 执行 Hook 逻辑
// 建议先只 Hook 一个最简单的函数测试稳定性
/*
uintptr_t target_offset = 0x123456; // 你的偏移
void* target_addr = (void*)(game_base + target_offset);
LOGI("Attempting to Hook at %p", target_addr);
// DobbyHook(target_addr, (void*)my_fake_func, (void**)&orig_func);
*/
// TODO: 在此处添加你的 DobbyHook 逻辑
// 例如: DobbyHook((void*)(game_base + 0x123456), (void*)new_func, (void**)&orig_func);
LOGI("All initialization steps completed.");
return nullptr;
@ -67,7 +65,7 @@ void* init_thread(void*) {
__attribute__((constructor))
void _init() {
pthread_t tid;
// 创建分离线程,防止阻塞导致游戏启动黑屏
// 使用分离模式创建线程,确保不会阻塞游戏进程
pthread_create(&tid, nullptr, init_thread, nullptr);
pthread_detach(tid);
}