Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions lib/android.js
Original file line number Diff line number Diff line change
Expand Up @@ -2160,6 +2160,13 @@ function instrumentArtFixupStaticTrampolines () {
];
const api = getApi();
const art = api.module;
const { artNterpEntryPoint, artQuickToInterpreterBridge } = api;
const quickCodeOffset = getArtMethodSpec(api.vm).offset.quickCode;

const synchronizeReplacements = function () {
artController.replacedMethods.synchronize(quickCodeOffset, artNterpEntryPoint, artQuickToInterpreterBridge);
};

for (const [name, pattern] of patterns) {
const base = art.findSymbolByName(name);
if (base === null) {
Expand All @@ -2168,17 +2175,38 @@ function instrumentArtFixupStaticTrampolines () {

const matches = Memory.scanSync(base, 8192, pattern);
if (matches.length === 0) {
return;
continue;
}

const { artNterpEntryPoint, artQuickToInterpreterBridge } = api;
const quickCodeOffset = getArtMethodSpec(api.vm).offset.quickCode;
Interceptor.attach(matches[0].address, function () {
artController.replacedMethods.synchronize(quickCodeOffset, artNterpEntryPoint, artQuickToInterpreterBridge);
});
Interceptor.attach(matches[0].address, synchronizeReplacements);

return;
}

// 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) {
Copy link
Copy Markdown
Member

@oleavr oleavr Mar 31, 2026

Choose a reason for hiding this comment

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

I would be good to base this on getArtApexVersion() instead, so new ART on older Android OSes also benefit from this.

const fallbackSymbols = [
'_ZN3art11ClassLinker26VisiblyInitializedCallback11MakeVisibleEPNS_6ThreadE',
'_ZN3art11ClassLinker26VisiblyInitializedCallback3RunEPNS_6ThreadE',
'_ZN3art11ClassLinker26VisiblyInitializedCallback22MarkVisiblyInitializedEPNS_6ThreadE'
];

let hooked = false;
fallbackSymbols.forEach(name => {
const address = art.findSymbolByName(name);
if (address === null) {
return;
}

Interceptor.attach(address, synchronizeReplacements);
hooked = true;
});

if (hooked) {
return;
}
}
}

function ensureArtKnowsHowToHandleReplacementMethods (vm) {
Expand Down