简体   繁体   中英

How to invoke an Android Dalvik internal method using Java reflection?

Although there are similar questions (such as this and this ), their answers do not solve my problem.

I'm using Android Studio 1.5.1 targeting Android API 18 (before Android KitKat 4.4, so I'm dealing with Dalvik, not ART runtime).

My questions are:

(1) Is it possible to invoke Dalvik internal methods using reflection? If so, can you show a code example? For example, Dalvik has its own stack which is located in the source code here (Interpreter) , can I call the function dvmDumpRunningThreadStack() via reflection?

(2) If (1) is not possible because the stack is written in native code, is it possible to invoke any Dalvik internal method using reflection? If so, can you show a code example? For example, Dalvik has many methods located in the source code here (Dalvik) , can I call any method there via reflection?

This doesn't work. The reflection mechanism only knows how to find things visible to Java-language code.

You can invoke methods that are visible to managed code but not part of the public API. The VM's internal native functions simply aren't visible, and there is no VM function for finding them. All VM functions that are intended to be called are published explicitly as "native" methods in a class.

First the reflection in Java could only got a java-level function pointer. The essence is to get the vtable from corresponding class object. All the dalvik internal method is located at '/system/lib/'. And your code is located at '/data/app/'.

So, I don't think you could use any dalvik internal methods at runtime unless you know the address of libdvm.so and the offset of internal method in dynamic library(eg libdvm.so).

If your phone is running on the rom you build, using objdump -D libdvm.so to get the offset and print log to find the address of libdvm.so. I think it could be work.

: )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM