feat: 成功加载了so 并且调用了riru hide等逻辑
准备增加自定义linker
This commit is contained in:
@@ -175,8 +175,10 @@ namespace Config {
|
||||
|
||||
auto it = g_config.perAppConfig.find(packageName);
|
||||
if (it != g_config.perAppConfig.end()) {
|
||||
LOGD("Found app config for %s with %zu SO files", packageName.c_str(), it->second.soFiles.size());
|
||||
return it->second.soFiles;
|
||||
}
|
||||
LOGD("No app config found for %s", packageName.c_str());
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,6 @@
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
void hack_prepare(const char *game_data_dir, void *data, size_t length);
|
||||
void hack_prepare(const char *game_data_dir, const char *package_name, void *data, size_t length);
|
||||
|
||||
#endif //ZYGISK_IL2CPPDUMPER_HACK_H
|
||||
|
||||
@@ -7,63 +7,51 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
|
||||
// External function from newriruhide.cpp
|
||||
extern "C" void riru_hide(const char *name);
|
||||
|
||||
void load_so_file(const char *game_data_dir, const Config::SoFile &soFile) {
|
||||
char dest_path[512];
|
||||
snprintf(dest_path, sizeof(dest_path), "%s/files/%s", game_data_dir, soFile.name.c_str());
|
||||
// Extract the mapped filename from storedPath (e.g., "1750851324251_libmylib.so")
|
||||
const char *mapped_name = strrchr(soFile.storedPath.c_str(), '/');
|
||||
if (!mapped_name) {
|
||||
mapped_name = soFile.storedPath.c_str();
|
||||
} else {
|
||||
mapped_name++; // Skip the '/'
|
||||
}
|
||||
|
||||
// Copy SO file from storage to app directory
|
||||
int src_fd = open(soFile.storedPath.c_str(), O_RDONLY);
|
||||
if (src_fd < 0) {
|
||||
LOGE("Failed to open source SO: %s", soFile.storedPath.c_str());
|
||||
// The file should already be in app's files directory
|
||||
char so_path[512];
|
||||
snprintf(so_path, sizeof(so_path), "%s/files/%s", game_data_dir, mapped_name);
|
||||
|
||||
// Check if file exists
|
||||
if (access(so_path, F_OK) != 0) {
|
||||
LOGE("SO file not found: %s", so_path);
|
||||
return;
|
||||
}
|
||||
|
||||
int dest_fd = open(dest_path, O_WRONLY | O_CREAT | O_TRUNC, 0755);
|
||||
if (dest_fd < 0) {
|
||||
LOGE("Failed to create dest SO: %s", dest_path);
|
||||
close(src_fd);
|
||||
return;
|
||||
}
|
||||
|
||||
char buffer[4096];
|
||||
ssize_t bytes;
|
||||
while ((bytes = read(src_fd, buffer, sizeof(buffer))) > 0) {
|
||||
if (write(dest_fd, buffer, bytes) != bytes) {
|
||||
LOGE("Failed to write SO file");
|
||||
close(src_fd);
|
||||
close(dest_fd);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
close(src_fd);
|
||||
close(dest_fd);
|
||||
chmod(dest_path, 0755);
|
||||
|
||||
// Load the SO file
|
||||
void *handle = dlopen(dest_path, RTLD_NOW | RTLD_LOCAL);
|
||||
void *handle = dlopen(so_path, RTLD_NOW | RTLD_LOCAL);
|
||||
if (handle) {
|
||||
LOGI("Successfully loaded SO: %s", soFile.name.c_str());
|
||||
LOGI("Successfully loaded SO: %s (mapped: %s)", soFile.name.c_str(), mapped_name);
|
||||
|
||||
// Hide if configured
|
||||
if (Config::shouldHideInjection()) {
|
||||
// Call hide function if available
|
||||
void (*hide_func)(const char*) = (void(*)(const char*))dlsym(handle, "riru_hide");
|
||||
if (hide_func) {
|
||||
hide_func(soFile.name.c_str());
|
||||
}
|
||||
// Hide using the mapped name since that's what we loaded
|
||||
riru_hide(mapped_name);
|
||||
LOGI("Applied riru_hide to: %s", mapped_name);
|
||||
}
|
||||
} else {
|
||||
LOGE("Failed to load SO: %s - %s", dest_path, dlerror());
|
||||
LOGE("Failed to load SO: %s - %s", so_path, dlerror());
|
||||
}
|
||||
}
|
||||
|
||||
void hack_thread_func(const char *game_data_dir, const char *package_name) {
|
||||
LOGI("Hack thread started for package: %s", package_name);
|
||||
|
||||
// Wait a bit for app to initialize
|
||||
sleep(1);
|
||||
// Wait a bit for app to initialize and files to be copied
|
||||
sleep(2);
|
||||
|
||||
// Get SO files for this app
|
||||
auto soFiles = Config::getAppSoFiles(package_name);
|
||||
@@ -71,26 +59,13 @@ void hack_thread_func(const char *game_data_dir, const char *package_name) {
|
||||
|
||||
// Load each SO file
|
||||
for (const auto &soFile : soFiles) {
|
||||
LOGI("Loading SO: %s", soFile.name.c_str());
|
||||
LOGI("Loading SO: %s (stored as: %s)", soFile.name.c_str(), soFile.storedPath.c_str());
|
||||
load_so_file(game_data_dir, soFile);
|
||||
}
|
||||
}
|
||||
|
||||
void hack_prepare(const char *game_data_dir, void *data, size_t length) {
|
||||
// Get package name from game_data_dir
|
||||
// Format: /data/user/0/com.example.app or /data/data/com.example.app
|
||||
const char *package_name = nullptr;
|
||||
if (strstr(game_data_dir, "/data/user/")) {
|
||||
package_name = strrchr(game_data_dir, '/');
|
||||
if (package_name) package_name++;
|
||||
} else if (strstr(game_data_dir, "/data/data/")) {
|
||||
package_name = game_data_dir + strlen("/data/data/");
|
||||
}
|
||||
|
||||
if (!package_name) {
|
||||
LOGE("Failed to extract package name from: %s", game_data_dir);
|
||||
return;
|
||||
}
|
||||
void hack_prepare(const char *game_data_dir, const char *package_name, void *data, size_t length) {
|
||||
LOGI("hack_prepare called for package: %s, dir: %s", package_name, game_data_dir);
|
||||
|
||||
std::thread hack_thread(hack_thread_func, game_data_dir, package_name);
|
||||
hack_thread.detach();
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <cinttypes>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
#include "hack.h"
|
||||
#include "zygisk.hpp"
|
||||
#include "game.h"
|
||||
@@ -21,6 +24,7 @@ public:
|
||||
void onLoad(Api *api, JNIEnv *env) override {
|
||||
this->api = api;
|
||||
this->env = env;
|
||||
enable_hack = false;
|
||||
}
|
||||
|
||||
void preAppSpecialize(AppSpecializeArgs *args) override {
|
||||
@@ -38,7 +42,8 @@ public:
|
||||
|
||||
void postAppSpecialize(const AppSpecializeArgs *) override {
|
||||
if (enable_hack) {
|
||||
std::thread hack_thread(hack_prepare, _data_dir, data, length);
|
||||
// Then start hack thread
|
||||
std::thread hack_thread(hack_prepare, _data_dir, _package_name, data, length);
|
||||
hack_thread.detach();
|
||||
}
|
||||
}
|
||||
@@ -48,9 +53,10 @@ private:
|
||||
JNIEnv *env;
|
||||
bool enable_hack;
|
||||
char *_data_dir;
|
||||
char *_package_name;
|
||||
void *data;
|
||||
size_t length;
|
||||
|
||||
|
||||
void preSpecialize(const char *package_name, const char *app_data_dir) {
|
||||
// Read configuration
|
||||
Config::readConfig();
|
||||
@@ -61,6 +67,11 @@ private:
|
||||
enable_hack = true;
|
||||
_data_dir = new char[strlen(app_data_dir) + 1];
|
||||
strcpy(_data_dir, app_data_dir);
|
||||
_package_name = new char[strlen(package_name) + 1];
|
||||
strcpy(_package_name, package_name);
|
||||
|
||||
// ConfigApp is responsible for copying SO files
|
||||
// We just need to load them
|
||||
|
||||
#if defined(__i386__)
|
||||
auto path = "zygisk/armeabi-v7a.so";
|
||||
|
||||
Reference in New Issue
Block a user