# 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: 1. frida-server running as root 2. frida Python client compiled from source (PyPI wheels are glibc-only) 3. 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: ```bash # 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 ```bash 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 ```python 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: ```python 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 1. **frida-server may not support Java bridge on Android 16** - Newer Android versions may have ART restrictions 2. **WeChat may use non-standard process model** - Main process may be `mmd` (not `com.tencent.mm`) 3. **frida-server may need `--enable-jit` flag** - Java bridge requires JIT compilation 4. **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: ```javascript // 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 1. **UI Automation (Verified Working)** - Use ADBKeyboard + OCR + tap to send messages - See `wechat-send-message-mechanism.md` for the verified sequence - See `pixel-fold-screen-detector` for screen state detection 2. **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.md` for Xposed template 3. **Try frida-server with `--enable-jit`** - May enable Java bridge ```bash su -c "/data/local/tmp/frida-server -D --enable-jit &" ``` ## Related - `react/references/frida-termux-compilation-recipe.md` - Complete compilation steps - `react/references/frida-android-setup.md` - Frida setup and hook targets - `react/references/apktool-android-apk-decompilation.md` - APK analysis for finding hook targets - `wechat-send-message-mechanism.md` - Verified UI automation sequence