Dynamic Method Offset detection for ART fails in Android 16
Looks like the dynamic detection for the method offsets is not successfully working on Android 16.
Reproducible on a physical Pixel 10 rooted device running Android 16.
The device enters on a loop reboot when the server runs and not able to spawn/launch apps using Frida.
Affected code: https://github.com/frida/frida-java-bridge/blob/f72e61ed18fa6b72f0559df223b22a899685b22c/lib/android.js#L1153
Error message:
{"type":"error","description":"Error: Unable to find copied methods in java/lang/Thread; please file a bug","stack":"Error: Unable to find copied methods in java/lang/Thread; please file a bug\n at /internal-agent.js:1:47232\n at Ie.perform (/internal-agent.js:1:25891)\n at Gn (/internal-agent.js:1:45951)\n at Md (/internal-agent.js:1827:1640)\n at Uo (/internal-agent.js:1827:1258)\n at Function.build (/internal-agent.js:1827:85)\n at t._make (/internal-agent.js:1828:18234)\n at t.use (/internal-agent.js:1828:17033)\n at /internal-agent.js:1837:6963\n at Ie.perform (/internal-agent.js:1:25891)","fileName":"/internal-agent.js","lineNumber":1,"columnNumber":47232}
Could you specify which OS patch you're on? This was working recently. (viz @AeonLucid )
This is the OS version that was not working: 16.0.0_BD3A.251105.010.E1
This is the same issue as https://github.com/frida/frida/issues/3644 https://github.com/frida/frida/issues/3642 https://github.com/frida/frida/issues/3641 and https://github.com/frida/frida/issues/3639. This problem technically belongs here, rather than on frida/frida.
The latest security patch from November 1st comes with a new version of the ART runtime that breaks the offset detection the same way it happened several times before.
Downgrading the ART runtime might work temporarily if the device doesn't have the new security patch, only the new APEX of the ART:
adb shell su -c 'pm uninstall com.google.android.art'
When will there be a fix? How long should I wait? There are persistent issues with FRIDA version 17.
If you want a fix, open a PR and make a fix.
Please note this is not only on Android 16. It is now spreading to OS versions as low as Android 12 via the Google Play update.
After the Google Play update in November 2025, my Android 13 device encountered the same problem, and uninstalling the update did not resolve it.
Not sure if this helps anyone, but here is the apex file from an affected device (Pixel 6A, Android 16):
Is anyone going to actually work on this or do we need to crowd source our own solution? Android Frida has been unusable now for an inappropriate amount of time.
Is anyone going to actually work on this or do we need to crowd source our own solution? Android Frida has been unusable now for an inappropriate amount of time.
Make a PR
Fine... I'll start then.
As we can tell from the comments we should probably be expecting to find 79 methods in java/lang/Thread. On a working device we can verify this by printing the below right after they're made on this line
console.log(JSON.stringify(methodsArray), offsetMethods);
{"length":79,"data":"0x709b8070"} 48
On an affected device we can do the same and find
{"length":125,"data":"0x70dbc938"} 48
The memory region between the 2 has some similarities upon first glance
https://github.com/frida/frida-java-bridge/blob/f72e61ed18fa6b72f0559df223b22a899685b22c/lib/android.js#L1146
let str = '';
for (let offset = offsetMethods; offset !== MAX_OFFSET; offset += 2) {
str += object.add(offset).readU16().toString(16);
if (object.add(offset).readU16() === methodsArraySize) {
offsetCopiedMethods = offset;
break;
}
}
console.log(str);
Unaffected devices above, affected below. Affected has been expanded to showcase patterns.
c068708500100021c0004901c40c04072078002fff00f0004f
c93070db0010600102c10004a01e80f050820880027fff00f0004109
Of note is the 00 10 in both instances which correlates to Thread MAX_PRIORITY which verifies we should be in the right area still. The ending pattern in the working example is FF 00 F0 00 also exists in the affected device but is no longer followed by 79. Expanding the search ranges on affected devices doesn't yield any obvious instances of 79.
Forcing it to continue with 65 (the value that exists there instead of 79) simply crashes which isn't surprising.
I can see some obvious patterns here in how this works. It's 2 bytes defining a value which was called the number of methods, 8 bytes defining something than groups of 4 bytes with a separator. The group's don't seem to match the "number of methods" short in both instances though. I'll have to play with it more tomorrow.
Relevant android commit https://cs.android.com/android/_/android/platform/art/+/1b4f99626e096a7366a028e7423602e505972f82, the copied_methods_offset_ field has been removed.
I can't work on this issue because I'm blocked by selinux issues. Frida has to update https://github.com/frida/selinux.
I can't work on this issue because I'm blocked by selinux issues. Frida has to update https://github.com/frida/selinux.
@AeonLucid use my fork https://github.com/esauvisky/selinux Ping on Discord if you need a hand đ
I imagine the update path would need to look something like this.
- Update the ART method loops to use a predetermined number of methods: https://github.com/frida/frida-java-bridge/blob/f72e61ed18fa6b72f0559df223b22a899685b22c/lib/class-model.js#L269
- Remove references to
copied_methods_offsetandclass_offset_copied_methods_offset - Remove the method offset path: https://github.com/frida/frida-java-bridge/blob/f72e61ed18fa6b72f0559df223b22a899685b22c/lib/android.js#L1143
Since this number of methods short doesn't exist anymore we would have to implement a helper to get the number of ART methods ourselves and pass that along to the module ahead of time. Easier said than done from a noob like me. I see in the linked android commit what looks like it could be the helper
inline uint32_t Class::NumDeclaredMethods() {
if (IsProxyClass()) {
return NumMethods();
}
if (IsArrayClass() || IsPrimitive()) {
return 0u;
}
ClassAccessor accessor(GetDexFile(), GetDexClassDefIndex());
return accessor.NumDirectMethods() + accessor.NumVirtualMethods();
}
But I don't know how I would implement this in Frida to get that value of 79 for java/lang/Thread. I don't think the proxy path is of importance but I have no clue how I would go about getting the values returned by accessor.NumDirectMethods() + accessor.NumVirtualMethods();
@ExternalAddress4401 maybe this is helpful for you! i tested on my pixel 6a running on android 16 works normally for me
RESPONSE BY AI:
Youâre right that copied_methods_offset_ is gone (A15/16), so scanning for that short will always fail. But we donât need a hardcoded method count or NumDeclaredMethods(). The ArtMethod array already stores its length in the array header, and read_art_array() can return it.
Suggested fix:
- android.js (API>=36): skip copiedâmethods scan and set copiedMethodsOffset to 0 (or omit it).
- class-model.js: when class_offset_copied_methods_offset == 0, use the length returned by read_art_array() for n instead of reading a guint16 from the class object. Apply same change in both method loops.
Sketch:
// android.js
if (getAndroidApiLevel() >= 36) {
return { offset: { ifields: 0x28, methods: 0x30, sfields: 0, copiedMethodsOffset:
0 } };
}
// class-model.js
elements = read_art_array(class_object, art_api.class_offset_methods, sizeof(gsize),
&n);
if (art_api.class_offset_copied_methods_offset != 0)
n = *(guint16 *)(class_object + art_api.class_offset_copied_methods_offset);
Same change around the other collect_matching_class_methods() loop.
This avoids Dex access and fixes âUnable to find copied methodsâ.
thanks to codex https://github.com/sijan2/frida
@ExternalAddress4401 maybe this is helpful for you! i tested on my pixel 6a running on android 16 works normally for me
RESPONSE BY AI:
Youâre right that copied_methods_offset_ is gone (A15/16), so scanning for that short will always fail. But we donât need a hardcoded method count or NumDeclaredMethods(). The ArtMethod array already stores its length in the array header, and read_art_array() can return it.
Suggested fix:
* android.js (API>=36): skip copiedâmethods scan and set copiedMethodsOffset to 0 (or omit it). * class-model.js: when class_offset_copied_methods_offset == 0, use the length returned by read_art_array() for n instead of reading a guint16 from the class object. Apply same change in both method loops.Sketch:
// android.js if (getAndroidApiLevel() >= 36) { return { offset: { ifields: 0x28, methods: 0x30, sfields: 0, copiedMethodsOffset: 0 } }; } // class-model.js elements = read_art_array(class_object, art_api.class_offset_methods, sizeof(gsize), &n); if (art_api.class_offset_copied_methods_offset != 0) n = *(guint16 *)(class_object + art_api.class_offset_copied_methods_offset);Same change around the other collect_matching_class_methods() loop.
This avoids Dex access and fixes âUnable to find copied methodsâ.
thanks to codex https://github.com/sijan2/frida
I'm not convinced this is anywhere close to correct.
The entire problem is readArtArray returns 125 on affected devices and not the amount of methods anymore as it was removed.
android.js (API>=36): skip copiedâmethods scan and set copiedMethodsOffset to 0 (or omit it).
Sure, now the method loops are invalid.
class-model.js: when class_offset_copied_methods_offset == 0, use the length returned by read_art_array() for n instead of reading a guint16 from the class object. Apply same change in both method loops.
This is 125 and not 79. Crashes. I've tried manually in both loops just to be sure.
This sketch it gave you also isn't represented in the repo anywhere. The patch it does to android.js doesn't work on its own without the first patch and the first patch is just... who even knows. I don't know what it's edited to force it to load but it can't be correct. It's beyond me what it does.
The server "runs" sure but attempting to start even the simplest of scripts
import Java from "frida-java-bridge";
Java.perform(() => {
console.log("Hello!");
});
Crashes immediately. And yes, this is with a patched bridge. It also shouldn't be using a short circuit check for the API level as it's only the copied methods field that was removed but it's an AI, it isn't going to know that. Nice try AI but I'm pretty sure we do need the method counts to know how far to read. I'm really interested in seeing what the actual fix ends up being and if I was anywhere close.
Did you try running a script with it yourself?
@ExternalAddress4401 what device are you on physical or emulator i tried on my both phyical device pixel 7 pro and pixel 6a running android 16 it works perfectly
download this patched frida https://github.com/sijan2/frida/releases/tag/v17.5.2-android16 and then setup clean virtual env and do
pip install frida frida-tools and then run this script to patch the frida tools
curl -O https://raw.githubusercontent.com/sijan2/frida/android16-compat-spawn/patches/patch-frida-tools.py python3 patch-frida-tools.py
make sure youâre actually running the patched bridge. frida-tools bundles bridges/ java.js, so if youâre using pip you must rebuild or patch the installed bridge; patching the repo alone wonât change the CLI.
@ExternalAddress4401 what device are you on physical or emulator i tried on my both phyical device pixel 7 pro and pixel 6a running android 16 it works perfectly download this patched frida https://github.com/sijan2/frida/releases/tag/v17.5.2-android16 and then setup clean virtual env and do
pip install frida frida-toolsand then run this script to patch the frida tools
curl -O https://raw.githubusercontent.com/sijan2/frida/android16-compat-spawn/patches/patch-frida-tools.py python3 patch-frida-tools.pymake sure youâre actually running the patched bridge. frida-tools bundles bridges/ java.js, so if youâre using pip you must rebuild or patch the installed bridge; patching the repo alone wonât change the CLI.
I used your repo. It doesn't work on my OnePlus 13. The server runs and that's where the functionality stops. frida -U xxx -l index.ts crashes. You can't use an unpatched bridge or you'll get the same "unable to find copied methods" error so there's no question of whether it's been patched or not.
I downloaded your tagged server to try.
import Java from "frida-java-bridge";
console.log("a");
Java.perform(() => {
console.log("Hello!");
});
Terminal:~/Desktop/hrhrth$ frida -U com.spaceapegames.beatstar -l index.ts
____
/ _ | Frida 17.4.2 - A world-class dynamic instrumentation toolkit
| (_| |
> _ | Commands:
/_/ |_| help -> Displays the help system
. . . . object? -> Display information about 'object'
. . . . exit/quit -> Exit
. . . .
. . . . More info at https://frida.re/docs/home/
. . . .
. . . . Connected to CPH2655 (id=c639bc74)
Compiled index.ts (32 ms)
a
Failed to load script: the connection is closed
Thank you for using Frida!
And we can be certain it's patched as if it's not
Terminal:~/Desktop/hrhrth$ frida -U com.spaceapegames.beatstar -l index.ts
____
/ _ | Frida 17.4.2 - A world-class dynamic instrumentation toolkit
| (_| |
> _ | Commands:
/_/ |_| help -> Displays the help system
. . . . object? -> Display information about 'object'
. . . . exit/quit -> Exit
. . . .
. . . . More info at https://frida.re/docs/home/
. . . .
. . . . Connected to CPH2655 (id=c639bc74)
Compiled index.ts (32 ms)
a
Error: Unable to find copied methods in java/lang/Thread; please file a bug
at <anonymous> (node_modules/frida-java-bridge/lib/android.js:1153)
at <anonymous> (node_modules/frida-java-bridge/lib/vm.js:35)
at getArtClassSpec (node_modules/frida-java-bridge/lib/android.js:1168)
at compileModule (node_modules/frida-java-bridge/lib/class-model.js:1306)
at ensureInitialized (node_modules/frida-java-bridge/lib/class-model.js:1270)
at build (node_modules/frida-java-bridge/lib/class-model.js:1180)
at _make (node_modules/frida-java-bridge/lib/class-factory.js:287)
at use (node_modules/frida-java-bridge/lib/class-factory.js:158)
at <anonymous> (node_modules/frida-java-bridge/index.js:404)
at <anonymous> (node_modules/frida-java-bridge/lib/vm.js:35)
at _performPendingVmOpsWhenReady (node_modules/frida-java-bridge/index.js:452)
at perform (node_modules/frida-java-bridge/index.js:377)
at <anonymous> (index.ts:6)
[CPH2655::com.spaceapegames.beatstar ]->
interesting i hit same error earlier before it was fixed on my phone i don't know how it got fixed i need to see chat log log
