Skip to content

Commit 58ace5c

Browse files
committed
update: LSPlt submodule; improve: ReopenOrDetach symbol finding
This commit updates LSPlt submodule, and by taking advantage of the new hook by prefix capabilities, improves finding of the "ReopenOrDetach" symbol.
1 parent ecc28ed commit 58ace5c

2 files changed

Lines changed: 22 additions & 30 deletions

File tree

loader/src/external/lsplt

Submodule lsplt updated 37 files

loader/src/injector/hook.cpp

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ struct FileDescriptorInfo {
201201
- https://android.googlesource.com/platform/frameworks/base/+/refs/tags/android-14.0.0_r1/core/jni/fd_utils.cpp#544
202202
- https://android.googlesource.com/platform/frameworks/base/+/refs/tags/android-14.0.0_r1/core/jni/com_android_internal_os_Zygote.cpp#2329
203203
*/
204-
DCL_HOOK_FUNC(void, _ZNK18FileDescriptorInfo14ReopenOrDetachERKNSt3__18functionIFvNS0_12basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEEEE, void *_this, void *fail_fn) {
204+
DCL_HOOK_FUNC(void, _ZNK18FileDescriptorInfo14ReopenOrDetach, void *_this, void *fail_fn) {
205205
const int fd = *(const int *)((uintptr_t)_this + offsetof(FileDescriptorInfo, fd));
206206
const std::string *file_path = (const std::string *)((uintptr_t)_this + offsetof(FileDescriptorInfo, file_path));
207207
const bool is_sock = *(const bool *)((uintptr_t)_this + offsetof(FileDescriptorInfo, is_sock));
@@ -221,7 +221,7 @@ DCL_HOOK_FUNC(void, _ZNK18FileDescriptorInfo14ReopenOrDetachERKNSt3__18functionI
221221
}
222222

223223
bypass_fd_check:
224-
old__ZNK18FileDescriptorInfo14ReopenOrDetachERKNSt3__18functionIFvNS0_12basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEEEE(_this, fail_fn);
224+
old__ZNK18FileDescriptorInfo14ReopenOrDetach(_this, fail_fn);
225225
}
226226

227227
// We cannot directly call `dlclose` to unload ourselves, otherwise when `dlclose` returns,
@@ -1046,19 +1046,25 @@ static bool hook_commit(struct lsplt_map_info *map_infos) {
10461046
}
10471047
}
10481048

1049-
static void hook_register(dev_t dev, ino_t inode, const char *symbol, void *new_func, void **old_func) {
1050-
if (!lsplt_register_hook(dev, inode, symbol, new_func, old_func)) {
1049+
static void hook_register(dev_t dev, ino_t inode, const char *symbol, bool is_prefix, void *new_func, void **old_func) {
1050+
bool res = false;
1051+
if (is_prefix) res = lsplt_register_hook_by_prefix(dev, inode, symbol, new_func, old_func);
1052+
else res = lsplt_register_hook(dev, inode, symbol, new_func, old_func);
1053+
1054+
if (!res) {
10511055
LOGE("Failed to register plt_hook \"%s\"", symbol);
1056+
10521057
return;
10531058
}
1059+
10541060
plt_hook_list->emplace_back(dev, inode, symbol, old_func);
10551061
}
10561062

1057-
#define PLT_HOOK_REGISTER_SYM(DEV, INODE, SYM, NAME) \
1058-
hook_register(DEV, INODE, SYM, (void*) new_##NAME, (void **) &old_##NAME)
1063+
#define PLT_HOOK_REGISTER_SYM(DEV, INODE, SYM, NAME, IS_PREFIX) \
1064+
hook_register(DEV, INODE, SYM, IS_PREFIX, (void*) new_##NAME, (void **) &old_##NAME)
10591065

1060-
#define PLT_HOOK_REGISTER(DEV, INODE, NAME) \
1061-
PLT_HOOK_REGISTER_SYM(DEV, INODE, #NAME, NAME)
1066+
#define PLT_HOOK_REGISTER(DEV, INODE, NAME, IS_PREFIX) \
1067+
PLT_HOOK_REGISTER_SYM(DEV, INODE, #NAME, NAME, IS_PREFIX)
10621068

10631069
void hook_functions() {
10641070
plt_hook_list = new vector<tuple<dev_t, ino_t, const char *, void **>>();
@@ -1087,29 +1093,15 @@ void hook_functions() {
10871093
break;
10881094
}
10891095

1090-
PLT_HOOK_REGISTER(android_runtime_dev, android_runtime_inode, fork);
1091-
PLT_HOOK_REGISTER(android_runtime_dev, android_runtime_inode, strdup);
1092-
PLT_HOOK_REGISTER(android_runtime_dev, android_runtime_inode, property_get);
1093-
PLT_HOOK_REGISTER(android_runtime_dev, android_runtime_inode, _ZNK18FileDescriptorInfo14ReopenOrDetachERKNSt3__18functionIFvNS0_12basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEEEE);
1094-
1095-
/* INFO: Fallback to older symbol for ReopenOrDetach */
1096+
PLT_HOOK_REGISTER(android_runtime_dev, android_runtime_inode, fork, false);
1097+
PLT_HOOK_REGISTER(android_runtime_dev, android_runtime_inode, strdup, false);
1098+
PLT_HOOK_REGISTER(android_runtime_dev, android_runtime_inode, property_get, false);
1099+
PLT_HOOK_REGISTER(android_runtime_dev, android_runtime_inode, _ZNK18FileDescriptorInfo14ReopenOrDetach, true);
1100+
10961101
if (!hook_commit(map_infos)) {
1097-
LOGW("Failed to hook. Trying older symbol for ReopenOrDetach");
1102+
LOGE("Failed to commit plt_hook");
10981103

10991104
plt_hook_list->clear();
1100-
1101-
PLT_HOOK_REGISTER(android_runtime_dev, android_runtime_inode, fork);
1102-
PLT_HOOK_REGISTER(android_runtime_dev, android_runtime_inode, strdup);
1103-
PLT_HOOK_REGISTER(android_runtime_dev, android_runtime_inode, property_get);
1104-
PLT_HOOK_REGISTER_SYM(android_runtime_dev, android_runtime_inode,
1105-
"_ZNK18FileDescriptorInfo14ReopenOrDetachEPNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE",
1106-
_ZNK18FileDescriptorInfo14ReopenOrDetachERKNSt3__18functionIFvNS0_12basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEEEE);
1107-
1108-
if (!hook_commit(map_infos)) {
1109-
LOGE("All methods of hooking failed");
1110-
1111-
plt_hook_list->clear();
1112-
}
11131105
}
11141106

11151107
lsplt_free_maps(map_infos);
@@ -1155,7 +1147,7 @@ static void hook_unloader() {
11551147
} else {
11561148
LOGD("hook_unloader called with libart.so [%zu:%lu]", art_dev, art_inode);
11571149

1158-
PLT_HOOK_REGISTER(art_dev, art_inode, pthread_attr_setstacksize);
1150+
PLT_HOOK_REGISTER(art_dev, art_inode, pthread_attr_setstacksize, false);
11591151
hook_commit(map_infos);
11601152
}
11611153

0 commit comments

Comments
 (0)