Skip to content

Initialize CloseGuard for legacy synthetic DexFiles - #177

Merged
eirv merged 1 commit into
LSPosed:masterfrom
kasnder:codex/legacy-closeguard
Aug 3, 2026
Merged

Initialize CloseGuard for legacy synthetic DexFiles#177
eirv merged 1 commit into
LSPosed:masterfrom
kasnder:codex/legacy-closeguard

Conversation

@kasnder

@kasnder kasnder commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Problem

The pre-Android O generated-dex fallback allocates dalvik.system.DexFile with AllocObject so
it can attach an in-memory ART dex. On API 21-25 this bypasses the constructor's initialization of
the private CloseGuard guard field. Finalization later calls close() and throws a
NullPointerException from CloseGuard.close().

Fix

Resolve CloseGuard.get() and the legacy DexFile.guard field during DexFile::Init, then seed a
fresh guard on every synthetic object returned by ToJavaDexFile. If any framework contract is
missing, initialization fails closed and LSPlant remains unavailable on that runtime.

Evidence

  • HookBridge ARM64 release native build passes.
  • A source contract regression test covers class/method/field lookup and object seeding.
  • With the fix enabled on an API 21 ARM64 emulator, LSPlant initialized and installed its hooks;
    the six fixture logs contained no DexFile.finalize/CloseGuard.close NPEs. The broader fixture
    harness still reported no-bound rows, so this is not presented as a complete compatibility pass.

@eirv
eirv merged commit 3383196 into LSPosed:master Aug 3, 2026
1 of 3 checks passed
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.

2 participants