feat:使用原来的so名称注入

This commit is contained in:
jiqiu2021
2025-06-26 20:14:54 +08:00
parent d793712a13
commit 680a93cba8
2 changed files with 26 additions and 43 deletions

View File

@@ -151,9 +151,17 @@ public class ConfigManager {
config.globalSoFiles = new ArrayList<>(); config.globalSoFiles = new ArrayList<>();
} }
// Generate unique filename // Keep original filename
String fileName = new File(originalPath).getName(); String fileName = new File(originalPath).getName();
String storedPath = SO_STORAGE_DIR + "/" + System.currentTimeMillis() + "_" + fileName; String storedPath = SO_STORAGE_DIR + "/" + fileName;
// Check if file already exists with same name
for (SoFile existing : config.globalSoFiles) {
if (existing.name.equals(fileName)) {
Log.w(TAG, "SO file with same name already exists: " + fileName);
return;
}
}
// Copy SO file to our storage // Copy SO file to our storage
Shell.Result result = Shell.cmd("cp \"" + originalPath + "\" \"" + storedPath + "\"").exec(); Shell.Result result = Shell.cmd("cp \"" + originalPath + "\" \"" + storedPath + "\"").exec();
@@ -288,9 +296,8 @@ public class ConfigManager {
// Copy each SO file configured for this app // Copy each SO file configured for this app
for (SoFile soFile : appConfig.soFiles) { for (SoFile soFile : appConfig.soFiles) {
// Extract mapped filename // Use original filename
String mappedName = new File(soFile.storedPath).getName(); String destPath = filesDir + "/" + soFile.name;
String destPath = filesDir + "/" + mappedName;
// Check if source file exists // Check if source file exists
Shell.Result checkResult = Shell.cmd("test -f \"" + soFile.storedPath + "\" && echo 'exists'").exec(); Shell.Result checkResult = Shell.cmd("test -f \"" + soFile.storedPath + "\" && echo 'exists'").exec();
@@ -354,8 +361,8 @@ public class ConfigManager {
// Only delete the SO files we deployed, not the entire directory // Only delete the SO files we deployed, not the entire directory
for (SoFile soFile : appConfig.soFiles) { for (SoFile soFile : appConfig.soFiles) {
String mappedName = new File(soFile.storedPath).getName(); // Use original filename
String filePath = filesDir + "/" + mappedName; String filePath = filesDir + "/" + soFile.name;
Log.i(TAG, "Cleaning up: " + filePath); Log.i(TAG, "Cleaning up: " + filePath);

View File

@@ -15,17 +15,9 @@
extern "C" void riru_hide(const char *name); extern "C" void riru_hide(const char *name);
void load_so_file_standard(const char *game_data_dir, const Config::SoFile &soFile) { void load_so_file_standard(const char *game_data_dir, const Config::SoFile &soFile) {
// Extract the mapped filename from storedPath (e.g., "1750851324251_libmylib.so") // Use original filename
const char *mapped_name = strrchr(soFile.storedPath.c_str(), '/');
if (!mapped_name) {
mapped_name = soFile.storedPath.c_str();
} else {
mapped_name++; // Skip the '/'
}
// The file should already be in app's files directory
char so_path[512]; char so_path[512];
snprintf(so_path, sizeof(so_path), "%s/files/%s", game_data_dir, mapped_name); snprintf(so_path, sizeof(so_path), "%s/files/%s", game_data_dir, soFile.name.c_str());
// Check if file exists // Check if file exists
if (access(so_path, F_OK) != 0) { if (access(so_path, F_OK) != 0) {
@@ -36,24 +28,16 @@ void load_so_file_standard(const char *game_data_dir, const Config::SoFile &soFi
// Load the SO file using standard dlopen (no hiding) // Load the SO file using standard dlopen (no hiding)
void *handle = dlopen(so_path, RTLD_NOW | RTLD_LOCAL); void *handle = dlopen(so_path, RTLD_NOW | RTLD_LOCAL);
if (handle) { if (handle) {
LOGI("Successfully loaded SO via standard dlopen: %s (mapped: %s)", soFile.name.c_str(), mapped_name); LOGI("Successfully loaded SO via standard dlopen: %s", soFile.name.c_str());
} else { } else {
LOGE("Failed to load SO via standard dlopen: %s - %s", so_path, dlerror()); LOGE("Failed to load SO via standard dlopen: %s - %s", so_path, dlerror());
} }
} }
void load_so_file_riru(const char *game_data_dir, const Config::SoFile &soFile) { void load_so_file_riru(const char *game_data_dir, const Config::SoFile &soFile) {
// Extract the mapped filename from storedPath (e.g., "1750851324251_libmylib.so") // Use original filename
const char *mapped_name = strrchr(soFile.storedPath.c_str(), '/');
if (!mapped_name) {
mapped_name = soFile.storedPath.c_str();
} else {
mapped_name++; // Skip the '/'
}
// The file should already be in app's files directory
char so_path[512]; char so_path[512];
snprintf(so_path, sizeof(so_path), "%s/files/%s", game_data_dir, mapped_name); snprintf(so_path, sizeof(so_path), "%s/files/%s", game_data_dir, soFile.name.c_str());
// Check if file exists // Check if file exists
if (access(so_path, F_OK) != 0) { if (access(so_path, F_OK) != 0) {
@@ -64,13 +48,13 @@ void load_so_file_riru(const char *game_data_dir, const Config::SoFile &soFile)
// Load the SO file using dlopen (Riru method) // Load the SO file using dlopen (Riru method)
void *handle = dlopen(so_path, RTLD_NOW | RTLD_LOCAL); void *handle = dlopen(so_path, RTLD_NOW | RTLD_LOCAL);
if (handle) { if (handle) {
LOGI("Successfully loaded SO via Riru: %s (mapped: %s)", soFile.name.c_str(), mapped_name); LOGI("Successfully loaded SO via Riru: %s", soFile.name.c_str());
// Hide if configured // Hide if configured
if (Config::shouldHideInjection()) { if (Config::shouldHideInjection()) {
// Hide using the mapped name since that's what we loaded // Hide using the original name
riru_hide(mapped_name); riru_hide(soFile.name.c_str());
LOGI("Applied riru_hide to: %s", mapped_name); LOGI("Applied riru_hide to: %s", soFile.name.c_str());
} }
} else { } else {
LOGE("Failed to load SO via Riru: %s - %s", so_path, dlerror()); LOGE("Failed to load SO via Riru: %s - %s", so_path, dlerror());
@@ -78,17 +62,9 @@ void load_so_file_riru(const char *game_data_dir, const Config::SoFile &soFile)
} }
void load_so_file_custom_linker(const char *game_data_dir, const Config::SoFile &soFile, JavaVM *vm) { void load_so_file_custom_linker(const char *game_data_dir, const Config::SoFile &soFile, JavaVM *vm) {
// Extract the mapped filename from storedPath // Use original filename
const char *mapped_name = strrchr(soFile.storedPath.c_str(), '/');
if (!mapped_name) {
mapped_name = soFile.storedPath.c_str();
} else {
mapped_name++; // Skip the '/'
}
// The file should already be in app's files directory
char so_path[512]; char so_path[512];
snprintf(so_path, sizeof(so_path), "%s/files/%s", game_data_dir, mapped_name); snprintf(so_path, sizeof(so_path), "%s/files/%s", game_data_dir, soFile.name.c_str());
// Check if file exists // Check if file exists
if (access(so_path, F_OK) != 0) { if (access(so_path, F_OK) != 0) {
@@ -98,7 +74,7 @@ void load_so_file_custom_linker(const char *game_data_dir, const Config::SoFile
// Load the SO file using custom linker // Load the SO file using custom linker
if (mylinker_load_library(so_path, vm)) { if (mylinker_load_library(so_path, vm)) {
LOGI("Successfully loaded SO via custom linker: %s (mapped: %s)", soFile.name.c_str(), mapped_name); LOGI("Successfully loaded SO via custom linker: %s", soFile.name.c_str());
// Custom linker doesn't appear in maps, so no need to hide // Custom linker doesn't appear in maps, so no need to hide
if (Config::shouldHideInjection()) { if (Config::shouldHideInjection()) {