frida-hook-wechat-termux.md
4.34 KB
Frida Hook WeChat on Android/Termux
Problem
Hooking WeChat's send message method (com.tencent.mm.ui.chatting.component.sk.p0) on Android/Termux requires:
- frida-server running as root
- frida Python client compiled from source (PyPI wheels are glibc-only)
- Java VM bridge working (for Java method hooking)
Compilation Steps (Verified)
1. Install frida Python Client from Source
See react/references/frida-termux-compilation-recipe.md for the full compilation recipe. Summary:
# Download matching devkit (version MUST match frida-server)
VERSION=$(su -c "/data/local/tmp/frida-server --version")
curl -L -o frida-core-devkit.tar.xz \
"https://github.com/frida/frida/releases/download/${VERSION}/frida-core-devkit-${VERSION}-android-arm64.tar.xz"
# Install build deps
pkg install -y clang make pkg-config glib libffi
pip install meson
# Compile ninja from source (PyPI wheel incompatible with Bionic)
# See frida-termux-compilation-recipe.md for ninja Bionic patch
# Build extension and install
FRIDA_EXTENSION=/path/to/_frida.abi3.so pip install . --no-build-isolation
2. Upgrade frida-server to Match
VERSION=17.15.3 # Must match Python package version
curl -L -o frida-server-${VERSION}-android-arm64.xz \
"https://github.com/frida/frida/releases/download/${VERSION}/frida-server-${VERSION}-android-arm64.xz"
unxz frida-server-${VERSION}-android-arm64.xz
su -c "cp frida-server-${VERSION}-android-arm64 /data/local/tmp/frida-server"
su -c "chmod 755 /data/local/tmp/frida-server"
su -c "killall frida-server"
su -c "/data/local/tmp/frida-server -D &"
3. Connect and Enumerate Processes
import frida
device = frida.get_device_manager().add_remote_device('127.0.0.1:27042')
processes = device.enumerate_processes()
# Find WeChat processes
for p in processes:
if 'mm' in p.name.lower() or 'tencent' in p.name.lower():
print(f'{p.pid}: {p.name}')
Expected output:
3950: mmd
23178: WeChat
23392: com.tencent.mm:push
24869: com.tencent.mm:xweb_sandboxed_process_0
...
The Java VM Problem
After successful compilation and connection, Java VM is unavailable in all WeChat processes:
session = device.attach(23178) # "WeChat" process
script = session.create_script('''
console.log('Java available: ' + (typeof Java !== 'undefined'));
// Output: Java available: false
''')
Attempted fixes:
- Attach to
WeChat(pid=23178) → Java VM unavailable - Attach to
mmd(pid=3950) → Java VM unavailable - Spawn
com.tencent.mm→ Java VM unavailable - Upgrade frida-server 17.9.10 → 17.15.3 → Java VM still unavailable
Root Cause Analysis
- frida-server may not support Java bridge on Android 16 - Newer Android versions may have ART restrictions
- WeChat may use non-standard process model - Main process may be
mmd(notcom.tencent.mm) - frida-server may need
--enable-jitflag - Java bridge requires JIT compilation - SELinux or Magisk may block Java bridge - Security policy may prevent Java VM access
Alternative: Native Hook (Without Java)
If Java bridge is unavailable, consider native hooking:
// Native hook example (no Java.perform needed)
Interceptor.attach(Module.findExportByName(null, "open"), {
onEnter: function(args) {
console.log("open() called with: " + Memory.readUtf8String(args[0]));
}
});
But this cannot hook WeChat's Java-level sk.p0() method.
Workarounds
UI Automation (Verified Working) - Use ADBKeyboard + OCR + tap to send messages
- See
wechat-send-message-mechanism.mdfor the verified sequence - See
pixel-fold-screen-detectorfor screen state detection
- See
Xposed/LSPosed - Install framework and write Xposed module
- Requires LSPosed Magisk module
- Can hook Java methods directly
- See
../software-development/react/references/frida-android-setup.mdfor Xposed template
Try frida-server with
--enable-jit- May enable Java bridgesu -c "/data/local/tmp/frida-server -D --enable-jit &"
Related
react/references/frida-termux-compilation-recipe.md- Complete compilation stepsreact/references/frida-android-setup.md- Frida setup and hook targetsreact/references/apktool-android-apk-decompilation.md- APK analysis for finding hook targetswechat-send-message-mechanism.md- Verified UI automation sequence