Skip to content

Harden DEX obfuscation against malformed module input#767

Open
Shallow-dusty wants to merge 3 commits into
JingMatrix:masterfrom
Shallow-dusty:fix/dex-obfuscation-crash
Open

Harden DEX obfuscation against malformed module input#767
Shallow-dusty wants to merge 3 commits into
JingMatrix:masterfrom
Shallow-dusty:fix/dex-obfuscation-crash

Conversation

@Shallow-dusty

@Shallow-dusty Shallow-dusty commented Jun 22, 2026

Copy link
Copy Markdown

## Summary

Harden the daemon DEX obfuscation path against malformed module-controlled DEX input before it reaches slicer.

Root Cause

ObfuscationManager.obfuscateDex only checked whether the mapped DEX bytes contained a target signature before passing the whole buffer to dex::Reader::CreateFullIr(). Slicer's structural guards are implemented with SLICER_CHECK / SLICER_WEAK_CHECK, but those checks compile out under NDEBUG, so malformed table offsets and indexes can still be dereferenced in release-compatible builds.

Changes

  • Add a Vector-side DEX preflight before calling slicer.
  • Validate the standard DEX header, core indexed-section ranges, map/data bounds, alignment, and the type/proto/field/method/class references that CreateFullIr() touches first.
  • Keep the JNI/Kotlin interface unchanged.
  • Skip obfuscation and return the original SharedMemory wrapper for malformed inputs, no-signature inputs, and writer-output failures so the daemon does not crash.

Validation

  • git diff --check
  • ./gradlew.bat --no-daemon :daemon:assembleDebug
  • ./gradlew.bat --no-daemon :daemon:assembleRelease

The release daemon build covers the NDEBUG-style path where slicer's own checks are compiled out.

Fixes #766

Device-side harness validation (PJD110, Android 16, KernelSU root, arm64 release -DNDEBUG):

  • Used issue Malformed module DEX can crash release daemon during JNI DEX obfuscation #766 PoC bad_vector_obfuscation.dex with SHA-256 ca6598344db1eb878a3bf13cd99d0a0890acc9106e76c3b2050905911ee6a738.
  • Baseline slicer release harness on device reproduced the crash: HARNESS_RC:139, logcat Fatal signal 11 (SIGSEGV).
  • Fixed Vector preflight harness on the same PoC returned HARNESS_RC:0 with preflight rejected malformed input; slicer skipped, and no crash log.
  • Smoke-tested a valid DEX containing Lorg/matrix/vector/core/: preflight accepted it, CreateFullIr() parsed IR classes: 1, HARNESS_RC:0.

@Shallow-dusty Shallow-dusty force-pushed the fix/dex-obfuscation-crash branch from 7c52596 to 2ce173d Compare June 22, 2026 14:20
@Shallow-dusty Shallow-dusty marked this pull request as ready for review June 22, 2026 15:34
Copilot AI review requested due to automatic review settings June 22, 2026 15:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the daemon’s JNI DEX obfuscation pipeline by adding a Vector-side preflight validator for module-controlled DEX buffers before handing them to slicer, preventing release (-DNDEBUG) crashes on malformed inputs (Fixes #766).

Changes:

  • Added isDexSafeForSlicer() plus supporting helpers to validate DEX header/section bounds and key indexed references.
  • Updated ObfuscationManager.obfuscateDex() to (a) handle invalid sizes, (b) skip slicer for malformed/no-signature inputs, and (c) return the original SharedMemory wrapper on failures.
  • Refactored SharedMemory wrapping into a helper (wrapSharedMemoryFd).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread daemon/src/main/jni/obfuscation.cpp
Comment thread daemon/src/main/jni/obfuscation.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Malformed module DEX can crash release daemon during JNI DEX obfuscation

2 participants