Android: fall back to VisiblyInitializedCallback hooks on Android 16#388
Draft
mrmees wants to merge 1 commit intofrida:mainfrom
Draft
Android: fall back to VisiblyInitializedCallback hooks on Android 16#388mrmees wants to merge 1 commit intofrida:mainfrom
mrmees wants to merge 1 commit intofrida:mainfrom
Conversation
oleavr
requested changes
Mar 31, 2026
|
|
||
| // Android 16 ART refactored this callback flow and older byte signatures no longer | ||
| // match reliably. Fall back to the callback methods that are still present. | ||
| if (getAndroidApiLevel() >= 36) { |
Member
There was a problem hiding this comment.
I would be good to base this on getArtApexVersion() instead, so new ART on older Android OSes also benefit from this.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Full Disclosure - This is 100% AI. I have no understanding of the underlying code changes, but my Frida setup wasn't working before, and now it is, so I figured I would put it up for review.
Summary
Fix Java
.implementationhooking on Android 16 by adding a fallback path for static-trampoline resynchronization when the existingVisiblyInitializedCallbackbyte signatures no longer match.On Android 16 / ART APEX
361154300, the existinginstrumentArtFixupStaticTrampolines()patterns stop matching, and one of the previously targeted symbols,AdjustThreadVisibilityCounter, is no longer present. This leaves replacement-method bookkeeping stale during ART's visibility / trampoline fixup flow, which appears to be enough to destabilize Java method replacement.This patch keeps the existing pattern-based behavior for older ART builds, but on Android 16 falls back to attaching directly to the
VisiblyInitializedCallbackmethods that are still present:MarkVisiblyInitializedMakeVisibleRunEach fallback hook triggers the same replacement-method synchronization already used by the existing path.
Why
On a Pixel 8 running Android 16 with ART APEX
361154300, local testing showed:interpreter::DoCallhooks are still foundGetOatQuickMethodHeaderscanning still matchesMarkVisiblyInitializedstill exists, but the old byte pattern no longer matchesAdjustThreadVisibilityCounteris goneMakeVisibleandRunare present inClassLinker::VisiblyInitializedCallbackWith this fallback in place, Java
.implementationstopped crashing immediately in the tested app process and was able to hook and invoke Java methods again.Implementation
instrumentArtFixupStaticTrampolines()now:synchronizeReplacements()helper for the existing resync logic.apiLevel >= 36, falls back to attaching to:_ZN3art11ClassLinker26VisiblyInitializedCallback11MakeVisibleEPNS_6ThreadE_ZN3art11ClassLinker26VisiblyInitializedCallback3RunEPNS_6ThreadE_ZN3art11ClassLinker26VisiblyInitializedCallback22MarkVisiblyInitializedEPNS_6ThreadEValidation
Validated locally on:
361154300Observed before this patch:
.implementationcrashed or destabilized the session on Android 16Observed after this patch:
Notes
This is intentionally a narrow compatibility fix. It does not change the existing pattern-based path for older ART builds, and it does not alter
GetOatQuickMethodHeaderhandling or the interpreter hook path.