Method inlined on Android 13/Tiramisu (API 33) #5
-
Tried LSPlant to hook android.app.Activity#getSystemService as a sample, the hook result returns true, but the callback has never been called. Why? trying to deoptimize not work. It works on Android 6 ~ 12 though. |
Beta Was this translation helpful? Give feedback.
Replies: 26 comments 12 replies
-
Have you tried to invoke |
Beta Was this translation helpful? Give feedback.
-
If I am not mistaken it requires the object/instance of |
Beta Was this translation helpful? Give feedback.
-
What I mean is just for testing... |
Beta Was this translation helpful? Give feedback.
-
Oh, sorry - yeah, it works if I tried to invoke the backup using reflection. |
Beta Was this translation helpful? Give feedback.
-
Not the backup. What I mean is: |
Beta Was this translation helpful? Give feedback.
-
Nope, not working - only works for Activity that I have defined, as I said. |
Beta Was this translation helpful? Give feedback.
-
So reflection (on your own activity) can trigger hook, right? |
Beta Was this translation helpful? Give feedback.
-
I am still trying to figure out why it's not working only for Tiramisu... |
Beta Was this translation helpful? Give feedback.
-
Ok, then it's the inline problem. Tiramisu has increased its inline threshold so it's not surprising. As the document has said, you should deoptimize the caller to make it work. Note that it's not deoptimizing the For example, there's a piece of code like this:
You should |
Beta Was this translation helpful? Give feedback.
-
Cool, thanks for the hint. Can you also suggest how to find the caller of the method at runtime? |
Beta Was this translation helpful? Give feedback.
-
It's possible but slow. I recommend you to hard code the callers. But if you are interesting, you can take a look at our experimental API for it at: https://github.com/LSPosed/DexBuilder/blob/master/include/dex_helper.h It can search all methods that invoke a specific method. And a JVM binding is here: https://github.com/yujincheng08/BiliRoaming/blob/master/app/src/main/jni/biliroaming.cc These APIs are still for experimental usage. We will publish it when it matures. |
Beta Was this translation helpful? Give feedback.
-
This is working: https://github.com/LSPosed/LSPosed/blob/master/core/src/main/cpp/external/yahfa/src/HookMain.cpp |
Beta Was this translation helpful? Give feedback.
-
are you hooking a normal app? LSPosed has disabled inline systemwisely so it may work. |
Beta Was this translation helpful? Give feedback.
-
Yeah, I didn't build any Xposed/LSPosed module, just include this library and try on a normal app. |
Beta Was this translation helpful? Give feedback.
-
Why this closed? We still have a discussion! )) |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
woops, sorry, I mean the original. edited :) |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
And. The inline problem affects all hook frameworks, including pine, epic, sandhook, yahfa, etc. |
Beta Was this translation helpful? Give feedback.
-
@yujincheng08 I found this function getInstanceOfClasses on VMDebug class on Android P and higher, might be able to use it to locate the instances/callers? |
Beta Was this translation helpful? Give feedback.
-
Reflection is just for tests. If a hook can be invoked by reflection but not by other callers, it's likely inlined. And the solution is never to find the instances and invoke them by reflection. The solution is to avoid the inline, like deoptimizing all possible callers or recompiling the app with flags that disable the inline. |
Beta Was this translation helpful? Give feedback.
-
It's not a bug. Maybe we should move it to the discussion. |
Beta Was this translation helpful? Give feedback.
-
Which Android versions that have this inlining problem? Android R, S, and Tiramisu? or just Android S and Tiramisu? |
Beta Was this translation helpful? Give feedback.
-
Read https://github.com/asLody/SandHook/blob/master/doc/doc.md#inline-%E5%A4%84%E7%90%86 about the inline problem and how to deal with it. |
Beta Was this translation helpful? Give feedback.
-
@yujincheng08 Seems like everything works correctly. I tried different method, this time, it's |
Beta Was this translation helpful? Give feedback.
Ok, then it's the inline problem. Tiramisu has increased its inline threshold so it's not surprising.
See LSPosed/LSPosed@ef1439a,
systemMain
is also inlined...As the document has said, you should deoptimize the caller to make it work. Note that it's not deoptimizing the
getSystemService
but the method which invokesgetSystemService
.For example, there's a piece of code like this:
You should
deoptmize(X::A)
rather thandeoptmize(Activity::getSystemService)