LSPosed A16 JNINativeInterface Fix
Bug
Vector v2.0 (and likely JingMatrix v1.11.0) crashes zygote64 on Android 16:
JNI DETECTED ERROR IN APPLICATION: negative buffer capacity in NewDirectByteBuffer
from int com.android.internal.os.Zygote.nativeForkSystemServer
Magisk detects repeated zygote crashes → auto-rolls-back Zygisk → modules never inject.
Root Cause
zygisk/src/main/cpp/ipc_bridge.cpp line 557:
memcpy(&native_interface_hook_, env->functions, sizeof(JNINativeInterface));
sizeof(JNINativeInterface) is compile-time (NDK 26 = ~2376 bytes). A16 ART added new JNI
functions, making the runtime structure larger. The truncated copy leaves garbage pointers
for new functions like NewDirectByteBuffer. ART's SetTableOverride reads reserved0
(which stores the correct runtime size and IS copied at offset 0), so it trusts the
truncated table → crash on first call to a new JNI function.
Fix
Two files changed. Use reserved0 for runtime size + dynamic allocation.
zygisk/src/main/cpp/include/ipc_bridge.h:167:
- JNINativeInterface native_interface_hook_{};
+ JNINativeInterface* native_interface_hook_ = nullptr;
+ size_t table_size_ = 0;
zygisk/src/main/cpp/ipc_bridge.cpp:555-566:
- memcpy(&native_interface_hook_, env->functions, sizeof(JNINativeInterface));
+ table_size_ = (size_t)env->functions->reserved0;
+ if (table_size_ == 0 || table_size_ < sizeof(JNINativeInterface))
+ table_size_ = sizeof(JNINativeInterface);
+ native_interface_hook_ = (JNINativeInterface*)malloc(table_size_);
+ memcpy(native_interface_hook_, env->functions, table_size_);
- call_boolean_method_v_backup_ = env->functions->CallBooleanMethodV;
+ call_boolean_method_v_backup_ = native_interface_hook_->CallBooleanMethodV;
- native_interface_hook_.CallBooleanMethodV = &CallBooleanMethodV_Hook;
+ native_interface_hook_->CallBooleanMethodV = &CallBooleanMethodV_Hook;
- set_table_override_func(&native_interface_hook_);
+ set_table_override_func(native_interface_hook_);
Build & Deploy
Package at ~/tmp/xhs_lsposed_a16_fix/ contains:
apply_a16_fix.sh— one-click patch scriptipc_bridge.h/ipc_bridge.cpp— pre-patched filesREADME.md— full build/deploy/verify guide
git clone --depth 1 --recursive https://github.com/JingMatrix/LSPosed.git
cd LSPosed
bash apply_a16_fix.sh .
export ANDROID_HOME=/path/to/android-sdk
./gradlew :zygisk:assembleRelease
Replace /data/adb/modules/zygisk_vector/zygisk/arm64-v8a.so with the built .so, reboot.
Verification (post-reboot)
su -c 'pidof lspd' # daemon running?
su -c 'cat /proc/$(pidof zygote64)/maps|grep zygisk' # injected into zygote?
su -c 'cat /proc/$(pidof com.xingin.xhs)/maps|grep xhshook' # module in target app?
Note on Compilation
Native clang 21.1.8 on Termux aarch64 crashes compiling lsplant's C++23 template code (Segmentation fault in class.cxx). Must compile on x86_64 desktop with Android NDK.