Files
Zygisk-MyInjector/module/src/main/cpp/hack_new.cpp

72 lines
2.3 KiB
C++
Raw Normal View History

2025-06-25 18:08:46 +08:00
#include "hack.h"
#include "config.h"
#include "log.h"
#include <cstring>
#include <thread>
#include <dlfcn.h>
#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);
2025-06-25 18:08:46 +08:00
void load_so_file(const char *game_data_dir, const Config::SoFile &soFile) {
// 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 '/'
2025-06-25 18:08:46 +08:00
}
// 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);
2025-06-25 18:08:46 +08:00
// Check if file exists
if (access(so_path, F_OK) != 0) {
LOGE("SO file not found: %s", so_path);
return;
2025-06-25 18:08:46 +08:00
}
// Load the SO file
void *handle = dlopen(so_path, RTLD_NOW | RTLD_LOCAL);
2025-06-25 18:08:46 +08:00
if (handle) {
LOGI("Successfully loaded SO: %s (mapped: %s)", soFile.name.c_str(), mapped_name);
2025-06-25 18:08:46 +08:00
// Hide if configured
if (Config::shouldHideInjection()) {
// Hide using the mapped name since that's what we loaded
riru_hide(mapped_name);
LOGI("Applied riru_hide to: %s", mapped_name);
2025-06-25 18:08:46 +08:00
}
} else {
LOGE("Failed to load SO: %s - %s", so_path, dlerror());
2025-06-25 18:08:46 +08:00
}
}
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 and files to be copied
sleep(2);
2025-06-25 18:08:46 +08:00
// Get SO files for this app
auto soFiles = Config::getAppSoFiles(package_name);
LOGI("Found %zu SO files to load", soFiles.size());
// Load each SO file
for (const auto &soFile : soFiles) {
LOGI("Loading SO: %s (stored as: %s)", soFile.name.c_str(), soFile.storedPath.c_str());
2025-06-25 18:08:46 +08:00
load_so_file(game_data_dir, soFile);
}
}
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);
2025-06-25 18:08:46 +08:00
std::thread hack_thread(hack_thread_func, game_data_dir, package_name);
hack_thread.detach();
}