cpp: RefBase: Dont use incWeakRequireWeak()

- Fixes the following on older android 10/11 platforms:
08-11 14:53:05.143  1388  1388 I TrickyStoreOSS: TrickyStore injector starting...
08-11 14:53:05.144  1388  1388 I TrickyStoreOSS: Starting injection of /data/adb/modules/tricky_store/libTrickyStoreOSS.so (entry: entry) into process 1024
08-11 14:53:05.151   587   587 I Zygote  : Preloading shared libraries...
08-11 14:53:05.155  1026  1053 I ServiceManager: Waiting for service 'package_native' on '/dev/binder'...
08-11 14:53:05.155  1388  1388 W TrickyStoreOSS: Primary dlopen failed for library: /data/adb/modules/tricky_store/libTrickyStoreOSS.so, dlerror: dlopen failed: cannot locate symbol "_ZN7android7RefBase12weakref_type18incWeakRequireWeakEPKv" referenced by "/data/adb/modules/tricky_store/libTrickyStoreOSS.so"..., trying fallback
08-11 14:53:05.155  1388  1388 I TrickyStoreOSS: Using fallback dlopen method for compatibility
08-11 14:53:05.158  1388  1388 E TrickyStoreOSS: Fallback dlopen failed for library: /data/adb/modules/tricky_store/libTrickyStoreOSS.so, dlerror: dlopen failed: cannot locate symbol "_ZN7android7RefBase12weakref_type18incWeakRequireWeakEPKv" referenced by "/data/adb/modules/tricky_store/libTrickyStoreOSS.so"...
08-11 14:53:05.158  1388  1388 E TrickyStoreOSS: Failed to load library in remote process
08-11 14:53:05.158  1388  1388 E TrickyStoreOSS: Injection failed

- Also improve error handling in injection process

Signed-off-by: Dakkshesh <beakthoven@gmail.com>
This commit is contained in:
Dakkshesh
2025-08-11 20:33:37 +05:30
parent 60bf475d48
commit eaa017be86
2 changed files with 42 additions and 4 deletions
+3 -1
View File
@@ -542,7 +542,9 @@ wp<T> wp<T>::fromExisting(T* other) {
if (!other) return nullptr;
auto refs = other->getWeakRefs();
refs->incWeakRequireWeak(other);
//TrickyStoreOSS edit
//refs->incWeakRequireWeak(other);
refs->incWeak(other);
wp<T> ret;
ret.m_ptr = other;
+39 -3
View File
@@ -225,12 +225,46 @@ static std::optional<int> transfer_fd_to_remote(int pid, const char *lib_path, s
return transferred_fd;
}
static std::string get_remote_dlerror(int pid, struct user_regs_struct &regs, const std::vector<lsplt::MapInfo> &local_map,
const std::vector<lsplt::MapInfo> &remote_map, uintptr_t libc_return_addr) {
auto dlerror_addr = find_func_addr(local_map, remote_map, constants::kLibdlModule, "dlerror");
if (!dlerror_addr) {
return "Failed to find dlerror function";
}
std::vector<uintptr_t> args;
auto dlerror_str_addr = remote_call(pid, regs, reinterpret_cast<uintptr_t>(dlerror_addr), libc_return_addr, args);
if (dlerror_str_addr == 0) {
return "dlerror returned null";
}
auto strlen_addr = find_func_addr(local_map, remote_map, constants::kLibcModule, "strlen");
if (!strlen_addr) {
return "Failed to find strlen function";
}
args.clear();
args.push_back(dlerror_str_addr);
auto dlerror_len = remote_call(pid, regs, reinterpret_cast<uintptr_t>(strlen_addr), libc_return_addr, args);
if (dlerror_len <= 0 || dlerror_len > 1024) {
return "Invalid dlerror string length";
}
std::string err;
err.resize(dlerror_len + 1, 0);
if (read_proc(pid, dlerror_str_addr, err.data(), dlerror_len) != dlerror_len) {
return "Failed to read dlerror string";
}
err.resize(dlerror_len);
return err;
}
static std::optional<uintptr_t> remote_dlopen(int pid, struct user_regs_struct &regs, const std::vector<lsplt::MapInfo> &local_map,
const std::vector<lsplt::MapInfo> &remote_map, int lib_fd, const char *lib_path,
uintptr_t libc_return_addr) {
auto dlopen_addr = find_func_addr(local_map, remote_map, constants::kLibdlModule, "android_dlopen_ext");
if (!dlopen_addr) {
LOGE("Failed to find android_dlopen_ext in %s", constants::kLibdlModule);
LOGW("Failed to find android_dlopen_ext in %s,", constants::kLibdlModule);
return std::nullopt;
}
@@ -245,7 +279,8 @@ static std::optional<uintptr_t> remote_dlopen(int pid, struct user_regs_struct &
uintptr_t remote_handle = remote_call(pid, regs, reinterpret_cast<uintptr_t>(dlopen_addr), libc_return_addr, args);
if (remote_handle == 0) {
LOGE("Remote dlopen failed for library: %s", lib_path);
std::string error_msg = get_remote_dlerror(pid, regs, local_map, remote_map, libc_return_addr);
LOGW("Primary dlopen failed for library: %s, dlerror: %s", lib_path, error_msg.c_str());
return std::nullopt;
}
@@ -268,7 +303,8 @@ static std::optional<uintptr_t> remote_find_entry(int pid, struct user_regs_stru
uintptr_t entry_addr = remote_call(pid, regs, reinterpret_cast<uintptr_t>(dlsym_addr), libc_return_addr, args);
if (entry_addr == 0) {
LOGE("Failed to find entry symbol '%s' in remote library", constants::kEntrySymbol);
std::string error_msg = get_remote_dlerror(pid, regs, local_map, remote_map, libc_return_addr);
LOGE("Failed to find entry symbol '%s' in remote library, dlerror: %s", constants::kEntrySymbol, error_msg.c_str());
return std::nullopt;
}